-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test class for abstract validator #3028
- Loading branch information
1 parent
195bf0c
commit 4a7dea5
Showing
5 changed files
with
145 additions
and
3 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
...test/java/com/mercedesbenz/sechub/wrapper/prepare/modules/AbstractInputValidatorTest.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,110 @@ | ||
package com.mercedesbenz.sechub.wrapper.prepare.modules; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class AbstractInputValidatorTest { | ||
|
||
TestInputValidator validatorToTest; | ||
|
||
@Test | ||
void constructor_throws_exception_when_type_is_null() { | ||
/* prepare */ | ||
Pattern locationPattern = Pattern.compile(".*"); | ||
Pattern usernamePattern = Pattern.compile(".*"); | ||
Pattern passwordPattern = Pattern.compile(".*"); | ||
|
||
/* execute */ | ||
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { | ||
validatorToTest = new TestInputValidator(null, locationPattern, usernamePattern, passwordPattern); | ||
}); | ||
|
||
/* test */ | ||
assertEquals("Type must not be null or empty.", exception.getMessage()); | ||
} | ||
|
||
@Test | ||
void constructor_throws_exception_when_type_is_empty() { | ||
/* prepare */ | ||
Pattern locationPattern = Pattern.compile(".*"); | ||
Pattern usernamePattern = Pattern.compile(".*"); | ||
Pattern passwordPattern = Pattern.compile(".*"); | ||
|
||
/* execute */ | ||
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { | ||
validatorToTest = new TestInputValidator("", locationPattern, usernamePattern, passwordPattern); | ||
}); | ||
|
||
/* test */ | ||
assertEquals("Type must not be null or empty.", exception.getMessage()); | ||
} | ||
|
||
@Test | ||
void constructor_throws_exception_when_locationPattern_is_null() { | ||
/* prepare */ | ||
Pattern usernamePattern = Pattern.compile(".*"); | ||
Pattern passwordPattern = Pattern.compile(".*"); | ||
|
||
/* execute */ | ||
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { | ||
validatorToTest = new TestInputValidator("type", null, usernamePattern, passwordPattern); | ||
}); | ||
|
||
/* test */ | ||
assertEquals("Pattern must not be null.", exception.getMessage()); | ||
} | ||
|
||
@Test | ||
void constructor_throws_exception_when_usernamePattern_is_null() { | ||
/* prepare */ | ||
Pattern locationPattern = Pattern.compile(".*"); | ||
Pattern passwordPattern = Pattern.compile(".*"); | ||
|
||
/* execute */ | ||
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { | ||
validatorToTest = new TestInputValidator("type", locationPattern, null, passwordPattern); | ||
}); | ||
|
||
/* test */ | ||
assertEquals("Pattern must not be null.", exception.getMessage()); | ||
} | ||
|
||
@Test | ||
void constructor_throws_exception_when_passwordPattern_is_null() { | ||
/* prepare */ | ||
Pattern locationPattern = Pattern.compile(".*"); | ||
Pattern usernamePattern = Pattern.compile(".*"); | ||
|
||
/* execute */ | ||
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { | ||
validatorToTest = new TestInputValidator("type", locationPattern, usernamePattern, null); | ||
}); | ||
|
||
/* test */ | ||
assertEquals("Pattern must not be null.", exception.getMessage()); | ||
} | ||
|
||
@Test | ||
void constructor_creates_instance_when_all_parameters_are_valid() { | ||
/* prepare */ | ||
Pattern locationPattern = Pattern.compile(".*"); | ||
Pattern usernamePattern = Pattern.compile(".*"); | ||
Pattern passwordPattern = Pattern.compile(".*"); | ||
|
||
/* execute */ | ||
validatorToTest = new TestInputValidator("type", locationPattern, usernamePattern, passwordPattern); | ||
|
||
/* test */ | ||
assertNotNull(validatorToTest); | ||
} | ||
|
||
private class TestInputValidator extends AbstractInputValidator { | ||
public TestInputValidator(String type, Pattern locationPattern, Pattern usernamePattern, Pattern passwordPattern) { | ||
super(type, locationPattern, usernamePattern, passwordPattern); | ||
} | ||
} | ||
|
||
} |
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
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
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
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