-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update&test[utils]: Add positive and negative JUnit tests to Paramete…
…rValidator class, ensuring full test coverage
- Loading branch information
Fredrik Marjoni
committed
Mar 24, 2026
1 parent
316d43c
commit 218a32f
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
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
63 changes: 63 additions & 0 deletions
63
src/test/java/edu/group5/app/utils/ParameterValidatorTest.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,63 @@ | ||
| package edu.group5.app.utils; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| public class ParameterValidatorTest { | ||
|
|
||
| @Test | ||
| void testValidatorDoesNotThrowWithValidParameters() { | ||
| assertDoesNotThrow(() -> ParameterValidator.stringChecker("valid", "validString")); | ||
| assertDoesNotThrow(() -> ParameterValidator.intChecker(1, "positiveInt")); | ||
| assertDoesNotThrow(() -> ParameterValidator.objectChecker(new Object(), "validObject")); | ||
| assertDoesNotThrow(() -> ParameterValidator.bigDecimalChecker(java.math.BigDecimal.valueOf(1), "positiveBigDecimal")); | ||
| } | ||
|
|
||
| @Test | ||
| void testValidatorThrowsWithStringChecker() { | ||
| IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { | ||
| ParameterValidator.stringChecker(null, "nullString"); | ||
| }); | ||
| IllegalArgumentException exception2 = assertThrows(IllegalArgumentException.class, () -> { | ||
| ParameterValidator.stringChecker("", "emptyString"); | ||
| }); | ||
| IllegalArgumentException exception3 = assertThrows(IllegalArgumentException.class, () -> { | ||
| ParameterValidator.stringChecker(" ", "blankString"); | ||
| }); | ||
| assertEquals("nullString can't be null", exception.getMessage()); | ||
| assertEquals("emptyString can't be blank", exception2.getMessage()); | ||
| assertEquals("blankString can't be blank", exception3.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| void testValidatorThrowsWithIntChecker() { | ||
| IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { | ||
| ParameterValidator.intChecker(-1, "negativeInt"); | ||
| }); | ||
| assertEquals("negativeInt must be a positive integer", exception.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| void testValidatorThrowsWithObjectChecker() { | ||
| IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { | ||
| ParameterValidator.objectChecker(null, "nullObject"); | ||
| }); | ||
| assertEquals("nullObject can't be null", exception.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| void testValidatorThrowsWithBigDecimalChecker() { | ||
| IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { | ||
| ParameterValidator.bigDecimalChecker(null, "nullBigDecimal"); | ||
| }); | ||
| IllegalArgumentException exception2 = assertThrows(IllegalArgumentException.class, () -> { | ||
| ParameterValidator.bigDecimalChecker(java.math.BigDecimal.valueOf(-1), "negativeBigDecimal"); | ||
| }); | ||
| IllegalArgumentException exception3 = assertThrows(IllegalArgumentException.class, () -> { | ||
| ParameterValidator.bigDecimalChecker(java.math.BigDecimal.ZERO, "zeroBigDecimal"); | ||
| }); | ||
| assertEquals("nullBigDecimal can't be null", exception.getMessage()); | ||
| assertEquals("negativeBigDecimal must be larger than 0", exception2.getMessage()); | ||
| assertEquals("zeroBigDecimal must be larger than 0", exception3.getMessage()); | ||
| } | ||
| } |