-
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.
Added unit test for NewUserController
- Loading branch information
Showing
2 changed files
with
87 additions
and
7 deletions.
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
67 changes: 67 additions & 0 deletions
67
src/test/java/client/controllers/NewUserControllerTest.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,67 @@ | ||
package client.controllers; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class NewUserControllerTest { | ||
NewUserController control; | ||
|
||
@BeforeEach | ||
void init(){ | ||
control = new NewUserController(); | ||
} | ||
|
||
@Test | ||
void testValidUsernameTooShort() { | ||
assertFalse(control.isValidUsername("aaa")); // 3 | ||
} | ||
|
||
@Test | ||
void testValidUsernameTooLong() { | ||
assertFalse(control.isValidUsername("aaaaaaaaaaaaaaaaaaaaa")); // 21 | ||
} | ||
|
||
@Test | ||
void testValidUsernameShortestPossible() { | ||
assertTrue(control.isValidUsername("aaaa")); // 4 | ||
} | ||
|
||
@Test | ||
void testValidUsernameLongestPossible() { | ||
assertTrue(control.isValidUsername("aaaaaaaaaaaaaaaaaaaa")); // 20 | ||
} | ||
|
||
@Test | ||
void testValidUsernameNumbers() { | ||
assertTrue(control.isValidUsername("1234567890")); | ||
} | ||
|
||
@Test | ||
void testValidUsernameCharacters() { | ||
assertTrue(control.isValidUsername("abcdefghijklmnopqrst")); | ||
assertTrue(control.isValidUsername("iuwgyz")); // Too long otherwise | ||
} | ||
|
||
@Test | ||
void testValidUsernameEmptySpaces() { | ||
assertFalse(control.isValidUsername(" ")); // Trim all empty spaces from beginning and end | ||
} | ||
|
||
@Test | ||
void testValidUsernameEmptySpacesWithTooFewCharacters() { | ||
assertFalse(control.isValidUsername(" abc ")); | ||
} | ||
|
||
@Test | ||
void testValidUsernameEmptySpacesWithEnoughCharacters() { | ||
assertTrue(control.isValidUsername(" abcdefghijklmnopqrst ")); | ||
} | ||
|
||
@Test | ||
void testValidUsernameIllegalCharacters() { | ||
assertFalse(control.isValidUsername("!@%*_")); | ||
} | ||
} |