Mailbox { public static Builder builder() { return new Builder(); } @VisibleForTesting  Mailbox(MailboxId id, String name, Optional<MailboxId> parentId, Optional<Role> role, SortOrder sortOrder, boolean mustBeOnlyMailbox,
                               boolean mayReadItems, boolean mayAddItems, boolean mayRemoveItems, boolean mayCreateChild, boolean mayRename, boolean mayDelete,
                               Number totalMessages, Number unreadMessages, Number totalThreads, Number unreadThreads, Rights sharedWith, MailboxNamespace namespace,
                               Optional<Quotas> quotas); static Builder builder(); MailboxId getId(); String getName(); Optional<MailboxId> getParentId(); Optional<Role> getRole(); SortOrder getSortOrder(); boolean isMustBeOnlyMailbox(); boolean isMayReadItems(); boolean isMayAddItems(); boolean isMayRemoveItems(); boolean isMayCreateChild(); boolean isMayRename(); boolean isMayDelete(); Number getTotalMessages(); Number getUnreadMessages(); Number getTotalThreads(); Number getUnreadThreads(); Rights getSharedWith(); MailboxNamespace getNamespace(); Optional<Quotas> getQuotas(); @JsonIgnore boolean hasRole(Role role); @JsonIgnore boolean hasSystemRole(); @Override final boolean equals(Object obj); @Override final int hashCode(); @Override String toString();  }
@Test(expected = NullPointerException.class) public void idShouldThrowWhenIdIsNull() { Mailbox.builder() .id(null); }
@Test(expected = NullPointerException.class) public void nameShouldThrowWhenNameIsNull() { Mailbox.builder() .name(null); }
@Test(expected = IllegalStateException.class) public void buildShouldThrowWhenIdIsNull() { Mailbox.builder().build(); }
@Test(expected = IllegalStateException.class) public void buildShouldThrowWhenNameIsNull() { Mailbox.builder() .id(InMemoryId.of(1)) .build(); }
@Test(expected = IllegalStateException.class) public void buildShouldThrowWhenNameIsEmpty() { Mailbox.builder() .id(InMemoryId.of(1)) .name("") .build(); }
@Test public void buildShouldWork() { Number totalMessages = Number.fromLong(456); Number unreadMessages = Number.fromLong(789); Number totalThreads = Number.fromLong(741); Number unreadThreads = Number.fromLong(852); Mailbox expectedMailbox = new Mailbox(InMemoryId.of(1), "name", Optional.of(InMemoryId.of(0)), Optional.of(Role.DRAFTS), SortOrder.of(123), true, true, true, true, true, true, true, totalMessages, unreadMessages, totalThreads, unreadThreads, Rights.EMPTY, MailboxNamespace.personal(), Optional.empty()); Mailbox mailbox = Mailbox.builder() .id(InMemoryId.of(1)) .name("name") .parentId(InMemoryId.of(0)) .role(Optional.of(Role.DRAFTS)) .sortOrder(SortOrder.of(123)) .mustBeOnlyMailbox(true) .mayReadItems(true) .mayAddItems(true) .mayRemoveItems(true) .mayCreateChild(true) .mayRename(true) .mayDelete(true) .totalMessages(456) .unreadMessages(789) .totalThreads(741) .unreadThreads(852) .build(); assertThat(mailbox).isEqualToComparingFieldByField(expectedMailbox); }