Skip to content

Commit

Permalink
Add test showing problematic behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
todvora committed Jul 2, 2024
1 parent c4fd199 commit 32583ec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/test/java/com/github/joschi/jadconfig/JadConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,7 @@

import com.github.joschi.jadconfig.repositories.InMemoryRepository;
import com.github.joschi.jadconfig.repositories.PropertiesRepository;
import com.github.joschi.jadconfig.testbeans.ConverterFailureBean;
import com.github.joschi.jadconfig.testbeans.DefaultValueConfigurationBean;
import com.github.joschi.jadconfig.testbeans.EmptyBean;
import com.github.joschi.jadconfig.testbeans.FoobarConfigurationBean;
import com.github.joschi.jadconfig.testbeans.InheritedBeanSubClass;
import com.github.joschi.jadconfig.testbeans.InheritedBeanSubSubClass;
import com.github.joschi.jadconfig.testbeans.Multi1ConfigurationBean;
import com.github.joschi.jadconfig.testbeans.Multi2ConfigurationBean;
import com.github.joschi.jadconfig.testbeans.NonExistingParameterBean;
import com.github.joschi.jadconfig.testbeans.RequiredParameterBean;
import com.github.joschi.jadconfig.testbeans.SaveMeBean;
import com.github.joschi.jadconfig.testbeans.SimpleConfigurationBean;
import com.github.joschi.jadconfig.testbeans.TrimBean;
import com.github.joschi.jadconfig.testbeans.ValidatedConfigurationBean;
import com.github.joschi.jadconfig.testbeans.ValidatorMethodConfigurationBean;
import com.github.joschi.jadconfig.testbeans.VoidConfigurationBean;
import com.github.joschi.jadconfig.testbeans.*;
import com.github.joschi.jadconfig.testconverters.FoobarConverterFactory;
import com.github.joschi.jadconfig.validators.StringNotBlankValidator;
import org.junit.Assert;
Expand Down Expand Up @@ -503,6 +488,18 @@ public void testProcessValidatedBean() throws RepositoryException, ValidationExc
Assert.assertEquals(1234567890123L, configurationBean.getMyLong());
}

@Test
public void testProcessValidatedBeanInvalidDefaultValue() throws RepositoryException, ValidationException {
InvalidDefaultValueValidatorBean configurationBean = new InvalidDefaultValueValidatorBean();
jadConfig = new JadConfig(repository, configurationBean);

jadConfig.process();

// TODO: this should throw an exception, is a mismatch of default value and configured validator
Assert.assertEquals(-1L, configurationBean.getMyPositiveLong());
}


@Test
public void testProcessNullPropertiesDoNotOverwriteDefaultValues() throws RepositoryException, ValidationException {
final SingleFieldBean bean = new SingleFieldBean();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.joschi.jadconfig.testbeans;

import com.github.joschi.jadconfig.Parameter;
import com.github.joschi.jadconfig.validators.PositiveLongValidator;

public class InvalidDefaultValueValidatorBean {

@Parameter(value = "test.positive.long", validator = PositiveLongValidator.class)
private long myPositiveLong = -1;

public long getMyPositiveLong() {
return myPositiveLong;
}
}

0 comments on commit 32583ec

Please sign in to comment.