Role { public static Optional<Role> from(String name) { Optional<Role> predefinedRole = predefinedRole(name); if (predefinedRole.isPresent()) { return predefinedRole; } else { return tryBuildCustomRole(name); } } @VisibleForTesting  Role(String name, String defaultMailbox, BiFunction<String, String, Boolean> comparator); @VisibleForTesting  Role(String name); static Optional<Role> from(String name); boolean isSystemRole(); String serialize(); String getDefaultMailbox(); @Override int hashCode(); @Override boolean equals(Object object); @Override String toString(); static final String USER_DEFINED_ROLE_PREFIX; static final Role INBOX; static final Role DRAFTS; static final Role OUTBOX; static final Role SENT; static final Role TRASH; static final Role ARCHIVE; static final Role SPAM; static final Role TEMPLATES; static final Role RESTORED_MESSAGES; }
@Test void fromShouldReturnEmptyWhenUnknownValue() { assertThat(Role.from("jjjj")).isEqualTo(Optional.empty()); }
@Test void fromShouldReturnSomethingWhenXPrefixedRole() { assertThat(Role.from("x-client-specific-role")).isEqualTo(Optional.of(new Role("x-client-specific-role"))); }
@Test void fromShouldReturnInboxWhenContainsUppercaseValueInTurkish() { Locale previousLocale = Locale.getDefault(); Locale.setDefault(Locale.forLanguageTag("tr")); try { assertThat(Role.from("InBox")).isEqualTo(Optional.of(Role.INBOX)); } finally { Locale.setDefault(previousLocale); } }
@Test void theDrAfTsMailboxNameShouldNotBeASystemMailbox() { Optional<Role> role = Role.from("DrAfTs"); assertThat(role).isEmpty(); }
@Test void theOuTbOxMailboxNameShouldNotBeASystemMailbox() { Optional<Role> role = Role.from("OuTbOx"); assertThat(role).isEmpty(); }
@Test void theSeNtMailboxNameShouldNotBeASystemMailbox() { Optional<Role> role = Role.from("SeNt"); assertThat(role).isEmpty(); }
@Test void theTrAsHMailboxNameShouldNotBeASystemMailbox() { Optional<Role> role = Role.from("TrAsH"); assertThat(role).isEmpty(); }
@Test void theReStOrEdMeSsAgEsMailboxNameShouldNotBeASystemMailbox() { Optional<Role> role = Role.from("ReStOrEd-MeSsAgEs"); assertThat(role).isEmpty(); }