-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from avaje/feature/tests-primitive-positive
Fix Object Boolean assert, null is valid
- Loading branch information
Showing
4 changed files
with
81 additions
and
4 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
blackbox-test/src/test/java/example/avaje/bool/ABoolFalse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package example.avaje.bool; | ||
|
||
import io.avaje.validation.constraints.AssertFalse; | ||
import io.avaje.validation.constraints.Valid; | ||
|
||
@Valid | ||
public record ABoolFalse( | ||
|
||
@AssertFalse boolean primitive, | ||
@AssertFalse Boolean object | ||
) { | ||
|
||
@AssertFalse public boolean primitiveMethod() { | ||
return primitive; | ||
} | ||
|
||
@AssertFalse public Boolean objectMethod() { | ||
return object; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
blackbox-test/src/test/java/example/avaje/bool/ABoolTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package example.avaje.bool; | ||
|
||
import io.avaje.validation.ConstraintViolation; | ||
import io.avaje.validation.Validator; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
class ABoolTest { | ||
|
||
Validator validator = Validator.builder().build(); | ||
|
||
@Test | ||
void valid() { | ||
validator.validate(new ABoolTrue(true, null)); | ||
validator.validate(new ABoolTrue(true, true)); | ||
validator.validate(new ABoolFalse(false, null)); | ||
validator.validate(new ABoolFalse(false, false)); | ||
} | ||
|
||
@Test | ||
void invalidTrue() { | ||
var violations = new ArrayList<>(validator.check(new ABoolTrue(false, false))); | ||
violations.stream() | ||
.map(ConstraintViolation::message) | ||
.forEach(msg -> assertThat(msg).isEqualTo("must be true")); | ||
} | ||
|
||
@Test | ||
void invalidFalse() { | ||
var violations = new ArrayList<>(validator.check(new ABoolFalse(true, true))); | ||
violations.stream() | ||
.map(ConstraintViolation::message) | ||
.forEach(msg -> assertThat(msg).isEqualTo("must be false")); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
blackbox-test/src/test/java/example/avaje/bool/ABoolTrue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package example.avaje.bool; | ||
|
||
import io.avaje.validation.constraints.AssertTrue; | ||
import io.avaje.validation.constraints.Valid; | ||
|
||
@Valid | ||
public record ABoolTrue( | ||
@AssertTrue boolean primitive, | ||
@AssertTrue Boolean object | ||
) { | ||
|
||
@AssertTrue public boolean primitiveMethod() { | ||
return primitive; | ||
} | ||
|
||
@AssertTrue public Boolean objectMethod() { | ||
return object; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters