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 581d649
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/test/java/com/github/joschi/jadconfig/JadConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
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 581d649

Please sign in to comment.