### Question:
Validator { public void checkPlayerId(String input) { boolean empty = isEmpty(input); if (empty || !id.matcher(input).matches()) { throw new IllegalArgumentException(String.format("Player id is invalid: '%s'", input)); } } Validator(); void checkPlayerId(String input); boolean isReadableName(String input); boolean isNickName(String input); boolean isFullName(String input); void checkPlayerId(String input, boolean canBeNull); boolean isPlayerId(String input, boolean canBeNull); boolean isEmail(String input, boolean canBeNull); void checkEmail(String input, boolean canBeNull); boolean isCode(String input, boolean canBeNull); void checkCode(String input, boolean canBeNull); boolean isEmpty(String input); boolean isGameName(String input, boolean canBeNull); boolean isRoomName(String input, boolean canBeNull); boolean is(String input, boolean canBeNull, Pattern pattern); void checkRoomName(String input, boolean canBeNull); void checkGameName(String input, boolean canBeNull); void checkNotEmpty(String name, String input); GameType checkGameType(String input); void checkMD5(String input); void checkCommand(String input); void checkPlayerCode(String id, String code); void checkNotNull(String name, Object input); void checkPlayerInRoom(String id, String roomName); static final boolean CAN_BE_NULL; static final boolean CANT_BE_NULL; }### Answer:
@Test public void validateCheckPlayerId_only() { shouldError("Player id is invalid: 'null'", () -> validator.checkPlayerId(null)); shouldError("Player id is invalid: ''", () -> validator.checkPlayerId("")); shouldError("Player id is invalid: 'NuLL'", () -> validator.checkPlayerId("NuLL")); shouldError("Player id is invalid: 'null'", () -> validator.checkPlayerId("null")); shouldError("Player id is invalid: 'NULL'", () -> validator.checkPlayerId("NULL")); shouldError("Player id is invalid: '*F(@DF^@(&@DF(@^'", () -> validator.checkPlayerId("*F(@DF^@(&@DF(@^")); shouldError("Player id is invalid: 'too large aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'", () -> validator.checkPlayerId("too large aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); shouldOk(() -> validator.checkPlayerId("1")); shouldOk(() -> validator.checkPlayerId("someId")); }
@Test public void validateCheckPlayerId() { shouldOk(() -> validator.checkPlayerId("validPlayerId", CANT_BE_NULL)); shouldOk(() -> validator.checkPlayerId("valid-player-id", CANT_BE_NULL)); shouldOk(() -> validator.checkPlayerId("codePlayerId", CANT_BE_NULL)); shouldError("Player id is invalid: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@aaa.aaa'", () -> validator.checkPlayerId("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@aaa.aaa", CANT_BE_NULL)); shouldError("Player id is invalid: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'", () -> validator.checkPlayerId("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", CANT_BE_NULL)); shouldError("Player id is invalid: 'email#&*^#gmail%#&^*com'", () -> validator.checkPlayerId("email#&*^#gmail%#&^*com", CANT_BE_NULL)); shouldError("Player id is invalid: 'null'", () -> validator.checkPlayerId(null, CANT_BE_NULL)); shouldError("Player id is invalid: 'NuLL'", () -> validator.checkPlayerId("NuLL", CANT_BE_NULL)); shouldError("Player id is invalid: ''", () -> validator.checkPlayerId("", CANT_BE_NULL)); shouldError("Player id is invalid: 'null'", () -> validator.checkPlayerId(null, CANT_BE_NULL)); shouldOk(() -> validator.checkPlayerId(null, CAN_BE_NULL)); shouldOk(() -> validator.checkPlayerId("null", CAN_BE_NULL)); shouldOk(() -> validator.checkPlayerId("", CAN_BE_NULL)); shouldOk(() -> validator.checkPlayerId("nULL", CAN_BE_NULL)); }