diff --git a/src/test/java/com/github/joschi/jadconfig/JadConfigTest.java b/src/test/java/com/github/joschi/jadconfig/JadConfigTest.java index 355c17d..5df5683 100644 --- a/src/test/java/com/github/joschi/jadconfig/JadConfigTest.java +++ b/src/test/java/com/github/joschi/jadconfig/JadConfigTest.java @@ -8,6 +8,7 @@ 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.InvalidDefaultValueValidatorBean; import com.github.joschi.jadconfig.testbeans.Multi1ConfigurationBean; import com.github.joschi.jadconfig.testbeans.Multi2ConfigurationBean; import com.github.joschi.jadconfig.testbeans.NonExistingParameterBean; @@ -503,6 +504,16 @@ public void testProcessValidatedBean() throws RepositoryException, ValidationExc Assert.assertEquals(1234567890123L, configurationBean.getMyLong()); } + @Test + public void testProcessValidatedBeanInvalidDefaultValue() { + InvalidDefaultValueValidatorBean configurationBean = new InvalidDefaultValueValidatorBean(); + jadConfig = new JadConfig(repository, configurationBean); + + // the default value is -1, validator expects only positive longs => validation exception + Assert.assertThrows(ValidationException.class, () -> jadConfig.process()); + } + + @Test public void testProcessNullPropertiesDoNotOverwriteDefaultValues() throws RepositoryException, ValidationException { final SingleFieldBean bean = new SingleFieldBean(); diff --git a/src/test/java/com/github/joschi/jadconfig/testbeans/InvalidDefaultValueValidatorBean.java b/src/test/java/com/github/joschi/jadconfig/testbeans/InvalidDefaultValueValidatorBean.java new file mode 100644 index 0000000..90f0985 --- /dev/null +++ b/src/test/java/com/github/joschi/jadconfig/testbeans/InvalidDefaultValueValidatorBean.java @@ -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; + } +}