### Question:
PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private  PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); static PermanentFlagsResponse parse(ImapResponse response); Set<Flag> getFlags(); boolean canCreateKeywords();  }### Answer:
@Test public void parse_withTaggedResponse_shouldReturnNull() throws Exception { ImapResponse response = createImapResponse("1 OK [PERMANENTFLAGS (\\Deleted \\Seen)] Flags permitted."); PermanentFlagsResponse result = PermanentFlagsResponse.parse(response); assertNull(result); }
@Test public void parse_withoutOkResponse_shouldReturnNull() throws Exception { ImapResponse response = createImapResponse("* BYE See you"); PermanentFlagsResponse result = PermanentFlagsResponse.parse(response); assertNull(result); }
@Test public void parse_withoutResponseText_shouldReturnNull() throws Exception { ImapResponse response = createImapResponse("* OK Success"); PermanentFlagsResponse result = PermanentFlagsResponse.parse(response); assertNull(result); }
@Test public void parse_withTooShortResponseText_shouldReturnNull() throws Exception { ImapResponse response = createImapResponse("* OK [PERMANENTFLAGS]"); PermanentFlagsResponse result = PermanentFlagsResponse.parse(response); assertNull(result); }
@Test public void parse_withoutPermanentFlagsResponse_shouldReturnNull() throws Exception { ImapResponse response = createImapResponse("* OK [UIDNEXT 1]"); PermanentFlagsResponse result = PermanentFlagsResponse.parse(response); assertNull(result); }
@Test public void parse_withoutPermanentFlagsList_shouldReturnNull() throws Exception { ImapResponse response = createImapResponse("* OK [PERMANENTFLAGS none]"); PermanentFlagsResponse result = PermanentFlagsResponse.parse(response); assertNull(result); }
@Test public void parse_withInvalidElementInPermanentFlagsList_shouldReturnNull() throws Exception { ImapResponse response = createImapResponse("* OK [PERMANENTFLAGS (\\Seen ())]"); PermanentFlagsResponse result = PermanentFlagsResponse.parse(response); assertNull(result); }