mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-22 19:11:16 +08:00
Merge pull request #226 from nagisa77/codex/update-username-validation-rules
Adjust username validation and signup UI
This commit is contained in:
@@ -14,8 +14,8 @@ public class UsernameValidator {
|
||||
* @param username the username to validate
|
||||
*/
|
||||
public void validate(String username) {
|
||||
if (username == null || username.length() < 6) {
|
||||
throw new FieldException("username", "Username must be at least 6 characters long");
|
||||
if (username == null || username.isEmpty()) {
|
||||
throw new FieldException("username", "Username cannot be empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.openisle.service;
|
||||
|
||||
import com.openisle.exception.FieldException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class UsernameValidatorTest {
|
||||
|
||||
@Test
|
||||
void rejectsEmptyUsername() {
|
||||
UsernameValidator validator = new UsernameValidator();
|
||||
assertThrows(FieldException.class, () -> validator.validate(""));
|
||||
assertThrows(FieldException.class, () -> validator.validate(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void allowsShortUsername() {
|
||||
UsernameValidator validator = new UsernameValidator();
|
||||
assertDoesNotThrow(() -> validator.validate("a"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user