ListingEncodingUtils { public static void encodeListingResponse(ImapCommand command, ImapResponseComposer composer, AbstractListingResponse response) throws IOException { composer.untagged(); composer.message(command.getName()); composer.openParen(); for (String attribute : getNameAttributes(response)) { composer.message(attribute); } composer.closeParen(); writeDelimiter(composer, response.getHierarchyDelimiter()); composer.mailbox(response.getName()); composer.end(); }  static void encodeListingResponse(ImapCommand command, ImapResponseComposer composer, AbstractListingResponse response);  }
@Test public void encodeShouldWriteNilDelimiterWhenUnassigned() throws Exception { ListResponse input = new ListResponse(Children.HAS_CHILDREN, Selectability.NONE, nameParameter, ((char) Character.UNASSIGNED)); ListingEncodingUtils.encodeListingResponse(LIST_COMMAND, composer, input); assertThat(writer.getString()).isEqualTo("* LIST (\\HasChildren) NIL \"mailbox\"\r\n"); }
@Test public void encodeShouldWriteAnyDelimiter() throws Exception { ListResponse input = new ListResponse(Children.HAS_CHILDREN, Selectability.NONE, nameParameter, '#'); ListingEncodingUtils.encodeListingResponse(LIST_COMMAND, composer, input); assertThat(writer.getString()).isEqualTo("* LIST (\\HasChildren) \"#\" \"mailbox\"\r\n"); }
@Test public void encodeShouldNotIncludeAttributeWhenNone() throws Exception { ListResponse input = new ListResponse(Children.CHILDREN_ALLOWED_BUT_UNKNOWN, MailboxMetaData.Selectability.NONE, nameParameter, '.'); ListingEncodingUtils.encodeListingResponse(LIST_COMMAND, composer, input); assertThat(writer.getString()).isEqualTo("* LIST () \".\" \"mailbox\"\r\n"); }
@Test public void encodeShouldAddHasChildrenToAttributes() throws Exception { ListResponse input = new ListResponse(Children.HAS_CHILDREN, Selectability.NONE, nameParameter, '.'); ListingEncodingUtils.encodeListingResponse(LIST_COMMAND, composer, input); assertThat(writer.getString()).isEqualTo("* LIST (\\HasChildren) \".\" \"mailbox\"\r\n"); }
@Test public void encodeShouldAddHasNoChildrenToAttributes() throws Exception { ListResponse input = new ListResponse(Children.HAS_NO_CHILDREN, Selectability.NONE, nameParameter, '.'); ListingEncodingUtils.encodeListingResponse(LIST_COMMAND, composer, input); assertThat(writer.getString()).isEqualTo("* LIST (\\HasNoChildren) \".\" \"mailbox\"\r\n"); }
@Test public void encodeShouldAddSeveralAttributes() throws Exception { ListResponse input = new ListResponse(Children.NO_INFERIORS, Selectability.NOSELECT, nameParameter, '.'); ListingEncodingUtils.encodeListingResponse(LIST_COMMAND, composer, input); assertThat(writer.getString()).isEqualTo("* LIST (\\Noselect \\Noinferiors) \".\" \"mailbox\"\r\n"); }
@Test public void encodeShouldAddMarkedAttribute() throws Exception { ListResponse input = new ListResponse(Children.CHILDREN_ALLOWED_BUT_UNKNOWN, Selectability.MARKED, nameParameter, '.'); ListingEncodingUtils.encodeListingResponse(LIST_COMMAND, composer, input); assertThat(writer.getString()).isEqualTo("* LIST (\\Marked) \".\" \"mailbox\"\r\n"); }
@Test public void encodeShouldAddUnmarkedAttribute() throws Exception { ListResponse input = new ListResponse(Children.CHILDREN_ALLOWED_BUT_UNKNOWN, Selectability.UNMARKED, nameParameter, '.'); ListingEncodingUtils.encodeListingResponse(LIST_COMMAND, composer, input); assertThat(writer.getString()).isEqualTo("* LIST (\\Unmarked) \".\" \"mailbox\"\r\n"); }
@Test public void encodeShouldAddXListAttributeWhenTypeIsInbox() throws Exception { XListResponse input = new XListResponse(Children.HAS_CHILDREN, Selectability.NONE, nameParameter, '.', MailboxType.INBOX); ListingEncodingUtils.encodeListingResponse(XLIST_COMMAND, composer, input); assertThat(writer.getString()).isEqualTo("* XLIST (\\HasChildren \\Inbox) \".\" \"mailbox\"\r\n"); }