private ImapList parseList(ImapList parent, char start, char end) throws IOException { expect(start); ImapList list = new ImapList(); parent.add(list); String endString = String.valueOf(end); Object token; while (true) { token = parseToken(list); if (token == null) { return null; } else if (token.equals(endString)) { break; } else if (!(token instanceof ImapList)) { list.add(token); } } return list; }
@Test public void getDate_returnsCorrectDateForValidString() throws MessagingException { ImapList list = new ImapList(); list.add("INTERNALDATE"); list.add("10-Mar-2000 12:02:01 GMT"); Calendar c = Calendar.getInstance(); c.setTime(list.getDate(1)); assertEquals(2000, c.get(Calendar.YEAR)); assertEquals(Calendar.MARCH, c.get(Calendar.MONTH)); assertEquals(10, c.get(Calendar.DAY_OF_MONTH)); }
@Test public void getKeyedDate_returnsCorrectDateForValidString() throws MessagingException { ImapList list = new ImapList(); list.add("INTERNALDATE"); list.add("10-Mar-2000 12:02:01 GMT"); Calendar c = Calendar.getInstance(); c.setTime(list.getKeyedDate("INTERNALDATE")); assertEquals(2000, c.get(Calendar.YEAR)); assertEquals(Calendar.MARCH, c.get(Calendar.MONTH)); assertEquals(10, c.get(Calendar.DAY_OF_MONTH)); }
private ImapList buildSampleList() { ImapList list = new ImapList(); list.add("ONE"); list.add("TWO"); list.add("THREE"); return list; }
@Test(expected = MessagingException.class) public void getKeyedDate_throwsExceptionForInvalidDate() throws MessagingException { ImapList list = new ImapList(); list.add("INTERNALDATE"); list.add("InvalidDate"); list.getKeyedDate("INTERNALDATE"); }
@Test(expected = MessagingException.class) public void getDate_throwsExceptionForInvalidDate() throws MessagingException { ImapList list = new ImapList(); list.add("INTERNALDATE"); list.add("InvalidDate"); list.getDate(1); }
@Test public void getDate_returnsNullForNIL() throws MessagingException { ImapList list = new ImapList(); list.add("INTERNALDATE"); list.add("NIL"); assertNull(list.getDate(1)); }
@Test public void getKeyedDate_returnsNullForNIL() throws MessagingException { ImapList list = new ImapList(); list.add("INTERNALDATE"); list.add("NIL"); assertNull(list.getKeyedDate("INTERNALDATE")); } }
private ImapResponse buildImapFetchResponse(ImapResponseCallback callback) { ImapResponse response = ImapResponse.newContinuationRequest(callback); response.add("1"); response.add("FETCH"); ImapList fetchList = new ImapList(); fetchList.add("UID"); fetchList.add("1"); fetchList.add("BODY"); fetchList.add("1.1"); fetchList.add("text"); response.add(fetchList); return response; }