@Test public void checkUsername_tooShort() { assertEquals(UsernameUtil.InvalidReason.TOO_SHORT, UsernameUtil.checkUsername(null).get()); assertEquals(UsernameUtil.InvalidReason.TOO_SHORT, UsernameUtil.checkUsername("").get()); assertEquals(UsernameUtil.InvalidReason.TOO_SHORT, UsernameUtil.checkUsername("abc").get()); }
public static Optional<InvalidReason> checkUsername(@Nullable String value) { if (value == null) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() < MIN_LENGTH) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() > MAX_LENGTH) { return Optional.of(InvalidReason.TOO_LONG); } else if (DIGIT_START_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.STARTS_WITH_NUMBER); } else if (!FULL_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.INVALID_CHARACTERS); } else { return Optional.absent(); } }
UsernameUtil { public static Optional<InvalidReason> checkUsername(@Nullable String value) { if (value == null) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() < MIN_LENGTH) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() > MAX_LENGTH) { return Optional.of(InvalidReason.TOO_LONG); } else if (DIGIT_START_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.STARTS_WITH_NUMBER); } else if (!FULL_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.INVALID_CHARACTERS); } else { return Optional.absent(); } } }
UsernameUtil { public static Optional<InvalidReason> checkUsername(@Nullable String value) { if (value == null) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() < MIN_LENGTH) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() > MAX_LENGTH) { return Optional.of(InvalidReason.TOO_LONG); } else if (DIGIT_START_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.STARTS_WITH_NUMBER); } else if (!FULL_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.INVALID_CHARACTERS); } else { return Optional.absent(); } }  }
UsernameUtil { public static Optional<InvalidReason> checkUsername(@Nullable String value) { if (value == null) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() < MIN_LENGTH) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() > MAX_LENGTH) { return Optional.of(InvalidReason.TOO_LONG); } else if (DIGIT_START_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.STARTS_WITH_NUMBER); } else if (!FULL_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.INVALID_CHARACTERS); } else { return Optional.absent(); } }  static boolean isValidUsernameForSearch(@Nullable String value); static Optional<InvalidReason> checkUsername(@Nullable String value); @WorkerThread static @NonNull Optional<UUID> fetchUuidForUsername(@NonNull Context context, @NonNull String username); }
UsernameUtil { public static Optional<InvalidReason> checkUsername(@Nullable String value) { if (value == null) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() < MIN_LENGTH) { return Optional.of(InvalidReason.TOO_SHORT); } else if (value.length() > MAX_LENGTH) { return Optional.of(InvalidReason.TOO_LONG); } else if (DIGIT_START_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.STARTS_WITH_NUMBER); } else if (!FULL_PATTERN.matcher(value).matches()) { return Optional.of(InvalidReason.INVALID_CHARACTERS); } else { return Optional.absent(); } }  static boolean isValidUsernameForSearch(@Nullable String value); static Optional<InvalidReason> checkUsername(@Nullable String value); @WorkerThread static @NonNull Optional<UUID> fetchUuidForUsername(@NonNull Context context, @NonNull String username); static final int MIN_LENGTH; static final int MAX_LENGTH; }