List of usage examples for android.test MoreAsserts assertEquals
public static void assertEquals(Set<? extends Object> expected, Set<? extends Object> actual)
From source file:com.ichi2.libanki.test.SchedTestCase.java
@MediumTest public void test_deckDue() throws JSONException { Collection d = Shared.getEmptyDeck(getInstrumentation().getContext()); // add a note with default deck Note f = d.newNote();/*from ww w . j a va 2s . co m*/ f.setitem("Front", "one"); d.addNote(f); // and one that's a child f = d.newNote(); f.setitem("Front", "two"); long default1 = 0; f.model().put("did", d.getDecks().id("Default::1")); default1 = f.model().getLong("did"); d.addNote(f); // make it a review card Card c = f.cards().get(0); c.setQueue(2); c.setDue(0); c.flush(); // add one more with a new deck f = d.newNote(); f.setitem("Front", "two"); long foobar = 0; f.model().put("did", d.getDecks().id("foo::bar")); foobar = f.model().getLong("did"); d.addNote(f); // and one that's a sibling f = d.newNote(); f.setitem("Front", "three"); long foobaz = 0; f.model().put("did", d.getDecks().id("foo::baz")); foobaz = f.model().getLong("did"); d.addNote(f); d.reset(); assertEquals(d.getDecks().getDecks().size(), 5); List<Object[]> cnts = d.getSched().deckDueList(Sched.DECK_INFORMATION_SIMPLE_COUNTS); // DIFFERENT THAN LIBANKI: deckDueList in AnkiDroid returns [deckname, did, new, lrn, rev] assertEquals(cnts.get(0)[0], "Default"); assertEquals(((Long) cnts.get(0)[1]).longValue(), 1); MoreAsserts.assertEquals(Shared.toPrimitiveInt(Arrays.copyOfRange(cnts.get(0), 2, 5, Integer[].class)), new int[] { 1, 0, 0 }); assertEquals(cnts.get(1)[0], "Default::1"); assertEquals(((Long) cnts.get(1)[1]).longValue(), default1); MoreAsserts.assertEquals(Shared.toPrimitiveInt(Arrays.copyOfRange(cnts.get(1), 2, 5, Integer[].class)), new int[] { 0, 0, 1 }); assertEquals(cnts.get(2)[0], "foo"); assertEquals(((Long) cnts.get(2)[1]).longValue(), d.getDecks().id("foo")); MoreAsserts.assertEquals(Shared.toPrimitiveInt(Arrays.copyOfRange(cnts.get(2), 2, 5, Integer[].class)), new int[] { 0, 0, 0 }); assertEquals(cnts.get(3)[0], "foo::bar"); assertEquals(((Long) cnts.get(3)[1]).longValue(), foobar); MoreAsserts.assertEquals(Shared.toPrimitiveInt(Arrays.copyOfRange(cnts.get(3), 2, 5, Integer[].class)), new int[] { 1, 0, 0 }); assertEquals(cnts.get(4)[0], "foo::baz"); assertEquals(((Long) cnts.get(4)[1]).longValue(), foobaz); MoreAsserts.assertEquals(Shared.toPrimitiveInt(Arrays.copyOfRange(cnts.get(4), 2, 5, Integer[].class)), new int[] { 1, 0, 0 }); TreeSet<Object[]> tree = d.getSched().deckDueTree(Sched.DECK_INFORMATION_SIMPLE_COUNTS); assertEquals(((String[]) tree.first()[0])[0], "Default"); // sum of child and parent assertEquals(((Long) tree.first()[1]).longValue(), 1); assertEquals(((Integer) tree.first()[2]).intValue(), 1); assertEquals(((Integer) tree.first()[4]).intValue(), 1); // child count is just review // DIFFERENT THAN LIBANKI assertEquals(((String[]) tree.higher(tree.first())[0])[0], "Default"); assertEquals(((String[]) tree.higher(tree.first())[0])[1], "1"); assertEquals(((Long) tree.higher(tree.first())[1]).longValue(), default1); assertEquals(((Integer) tree.higher(tree.first())[2]).intValue(), 0); assertEquals(tree.higher(tree.first())[4], 1); // code should not fail if a card has an invalid deck c.setDid(12345); c.flush(); d.getSched().deckDueList(Sched.DECK_INFORMATION_SIMPLE_COUNTS); d.getSched().deckDueTree(Sched.DECK_INFORMATION_SIMPLE_COUNTS); }
From source file:com.android.email.mail.store.ImapStoreUnitTests.java
public void testSearchForUids() throws Exception { MockTransport mock = openAndInjectMockTransport(); setupOpenFolder(mock);//w w w . ja va2 s. c om mFolder.open(OpenMode.READ_WRITE, null); // Single results mock.expect(getNextTag(false) + " UID SEARCH X", new String[] { "* sEARCH 1", getNextTag(true) + " oK success" }); MoreAsserts.assertEquals(new String[] { "1" }, mFolder.searchForUids("X")); // Multiple results, including SEARCH with no UIDs. mock.expect(getNextTag(false) + " UID SEARCH UID 123", new String[] { "* sEARCH 123 4 567", "* search", "* sEARCH 0", "* SEARCH", "* sEARCH 100 200 300", getNextTag(true) + " oK success" }); MoreAsserts.assertEquals(new String[] { "123", "4", "567", "0", "100", "200", "300" }, mFolder.searchForUids("UID 123")); // NO result mock.expect(getNextTag(false) + " UID SEARCH SOME CRITERIA", new String[] { getNextTag(true) + " nO not found" }); MoreAsserts.assertEquals(new String[] {}, mFolder.searchForUids("SOME CRITERIA")); // OK result, but result is empty. (Probably against RFC) mock.expect(getNextTag(false) + " UID SEARCH SOME CRITERIA", new String[] { getNextTag(true) + " oK success" }); MoreAsserts.assertEquals(new String[] {}, mFolder.searchForUids("SOME CRITERIA")); // OK result with empty search response. mock.expect(getNextTag(false) + " UID SEARCH SOME CRITERIA", new String[] { "* search", getNextTag(true) + " oK success" }); MoreAsserts.assertEquals(new String[] {}, mFolder.searchForUids("SOME CRITERIA")); }
From source file:com.android.email.mail.store.ImapStoreUnitTests.java
private static void checkMessageUids(String[] expectedUids, Message[] actualMessages) { ArrayList<String> list = new ArrayList<String>(); for (Message m : actualMessages) { list.add(m.getUid());//from w w w . j a v a2 s. c o m } MoreAsserts.assertEquals(expectedUids, list.toArray(new String[0])); }
From source file:com.android.email.mail.store.ImapStoreUnitTests.java
/** * Apparently some servers send a size in the wrong format. e.g. 123E *//*w w w .j a va 2 s . co m*/ public void testFetchBodyStructureMalformed() throws Exception { final MockTransport mock = openAndInjectMockTransport(); setupOpenFolder(mock); mFolder.open(OpenMode.READ_WRITE, null); final Message message = mFolder.createMessage("1"); final FetchProfile fp = new FetchProfile(); fp.add(FetchProfile.Item.STRUCTURE); mock.expect(getNextTag(false) + " UID FETCH 1 \\(UID BODYSTRUCTURE\\)", new String[] { "* 9 FETCH (UID 1 BODYSTRUCTURE (\"TEXT\" \"PLAIN\" ()" + " NIL NIL NIL 123E 3))", // 123E isn't a number! getNextTag(true) + " OK SUCCESS" }); mFolder.fetch(new Message[] { message }, fp, null); // Check mime structure... MoreAsserts.assertEquals(new String[] { "text/plain" }, message.getHeader("Content-Type")); assertNull(message.getHeader("Content-Transfer-Encoding")); assertNull(message.getHeader("Content-ID")); // Doesn't have size=xxx assertNull(message.getHeader("Content-Disposition")); }
From source file:com.android.email.mail.store.ImapStoreUnitTests.java
/** * Folder name with special chars in it. * * Gmail puts the folder name in the OK response, which crashed the old parser if there's a * special char in the folder name./*from w ww . j a v a 2s.c o m*/ */ public void testFolderNameWithSpecialChars() throws Exception { final String FOLDER_1 = "@u88**%_St"; final String FOLDER_1_QUOTED = Pattern.quote(FOLDER_1); final String FOLDER_2 = "folder test_06"; MockTransport mock = openAndInjectMockTransport(); expectLogin(mock); // List folders. mock.expect(getNextTag(false) + " LIST \"\" \"\\*\"", new String[] { "* LIST () \"/\" \"" + FOLDER_1 + "\"", "* LIST () \"/\" \"" + FOLDER_2 + "\"", getNextTag(true) + " OK SUCCESS" }); final Folder[] folders = mStore.getPersonalNamespaces(); ArrayList<String> list = new ArrayList<String>(); for (Folder f : folders) { list.add(f.getName()); } MoreAsserts.assertEquals(new String[] { FOLDER_1, FOLDER_2, "INBOX" }, list.toArray(new String[0])); // Try to open the folders. expectNoop(mock, true); mock.expect(getNextTag(false) + " SELECT \"" + FOLDER_1_QUOTED + "\"", new String[] { "* FLAGS (\\Answered \\Flagged \\Draft \\Deleted \\Seen)", "* OK [PERMANENTFLAGS (\\Answered \\Flagged \\Draft \\Deleted \\Seen \\*)]", "* 0 EXISTS", "* 0 RECENT", "* OK [UNSEEN 0]", "* OK [UIDNEXT 1]", getNextTag(true) + " OK [READ-WRITE] " + FOLDER_1 }); folders[0].open(OpenMode.READ_WRITE, null); folders[0].close(false); expectNoop(mock, true); mock.expect(getNextTag(false) + " SELECT \"" + FOLDER_2 + "\"", new String[] { "* FLAGS (\\Answered \\Flagged \\Draft \\Deleted \\Seen)", "* OK [PERMANENTFLAGS (\\Answered \\Flagged \\Draft \\Deleted \\Seen \\*)]", "* 0 EXISTS", "* 0 RECENT", "* OK [UNSEEN 0]", "* OK [UIDNEXT 1]", getNextTag(true) + " OK [READ-WRITE] " + FOLDER_2 }); folders[1].open(OpenMode.READ_WRITE, null); folders[1].close(false); }
From source file:com.appaholics.email.mail.store.ImapStoreUnitTests.java
public void testSearchForUids() throws Exception { MockTransport mock = openAndInjectMockTransport(); setupOpenFolder(mock);//w ww .ja v a 2s . co m mFolder.open(OpenMode.READ_WRITE); // Single results mock.expect(getNextTag(false) + " UID SEARCH X", new String[] { "* sEARCH 1", getNextTag(true) + " oK success" }); MoreAsserts.assertEquals(new String[] { "1" }, mFolder.searchForUids("X")); // Multiple results, including SEARCH with no UIDs. mock.expect(getNextTag(false) + " UID SEARCH UID 123", new String[] { "* sEARCH 123 4 567", "* search", "* sEARCH 0", "* SEARCH", "* sEARCH 100 200 300", getNextTag(true) + " oK success" }); MoreAsserts.assertEquals(new String[] { "123", "4", "567", "0", "100", "200", "300" }, mFolder.searchForUids("UID 123")); // NO result mock.expect(getNextTag(false) + " UID SEARCH SOME CRITERIA", new String[] { getNextTag(true) + " nO not found" }); MoreAsserts.assertEquals(new String[] {}, mFolder.searchForUids("SOME CRITERIA")); // OK result, but result is empty. (Probably against RFC) mock.expect(getNextTag(false) + " UID SEARCH SOME CRITERIA", new String[] { getNextTag(true) + " oK success" }); MoreAsserts.assertEquals(new String[] {}, mFolder.searchForUids("SOME CRITERIA")); // OK result with empty search response. mock.expect(getNextTag(false) + " UID SEARCH SOME CRITERIA", new String[] { "* search", getNextTag(true) + " oK success" }); MoreAsserts.assertEquals(new String[] {}, mFolder.searchForUids("SOME CRITERIA")); }
From source file:com.appaholics.email.mail.store.ImapStoreUnitTests.java
/** * Apparently some servers send a size in the wrong format. e.g. 123E */// w w w .j a v a 2 s.co m public void testFetchBodyStructureMalformed() throws Exception { final MockTransport mock = openAndInjectMockTransport(); setupOpenFolder(mock); mFolder.open(OpenMode.READ_WRITE); final Message message = mFolder.createMessage("1"); final FetchProfile fp = new FetchProfile(); fp.add(FetchProfile.Item.STRUCTURE); mock.expect(getNextTag(false) + " UID FETCH 1 \\(UID BODYSTRUCTURE\\)", new String[] { "* 9 FETCH (UID 1 BODYSTRUCTURE (\"TEXT\" \"PLAIN\" ()" + " NIL NIL NIL 123E 3))", // 123E isn't a number! getNextTag(true) + " OK SUCCESS" }); mFolder.fetch(new Message[] { message }, fp, null); // Check mime structure... MoreAsserts.assertEquals(new String[] { "text/plain" }, message.getHeader("Content-Type")); assertNull(message.getHeader("Content-Transfer-Encoding")); assertNull(message.getHeader("Content-ID")); // Doesn't have size=xxx assertNull(message.getHeader("Content-Disposition")); }
From source file:com.appaholics.email.mail.store.ImapStoreUnitTests.java
/** * Folder name with special chars in it. * * Gmail puts the folder name in the OK response, which crashed the old parser if there's a * special char in the folder name.//from ww w.j av a2 s .c o m */ public void testFolderNameWithSpecialChars() throws Exception { final String FOLDER_1 = "@u88**%_St"; final String FOLDER_1_QUOTED = Pattern.quote(FOLDER_1); final String FOLDER_2 = "folder test_06"; MockTransport mock = openAndInjectMockTransport(); expectLogin(mock); // List folders. expectNoop(mock, true); mock.expect(getNextTag(false) + " LIST \"\" \"\\*\"", new String[] { "* LIST () \"/\" \"" + FOLDER_1 + "\"", "* LIST () \"/\" \"" + FOLDER_2 + "\"", getNextTag(true) + " OK SUCCESS" }); final Folder[] folders = mStore.updateFolders(); ArrayList<String> list = new ArrayList<String>(); for (Folder f : folders) { list.add(f.getName()); } MoreAsserts.assertEquals(new String[] { "INBOX", FOLDER_2, FOLDER_1 }, list.toArray(new String[0])); // Try to open the folders. expectNoop(mock, true); mock.expect(getNextTag(false) + " SELECT \"" + FOLDER_1_QUOTED + "\"", new String[] { "* FLAGS (\\Answered \\Flagged \\Draft \\Deleted \\Seen)", "* OK [PERMANENTFLAGS (\\Answered \\Flagged \\Draft \\Deleted \\Seen \\*)]", "* 0 EXISTS", "* 0 RECENT", "* OK [UNSEEN 0]", "* OK [UIDNEXT 1]", getNextTag(true) + " OK [READ-WRITE] " + FOLDER_1 }); folders[2].open(OpenMode.READ_WRITE); folders[2].close(false); expectNoop(mock, true); mock.expect(getNextTag(false) + " SELECT \"" + FOLDER_2 + "\"", new String[] { "* FLAGS (\\Answered \\Flagged \\Draft \\Deleted \\Seen)", "* OK [PERMANENTFLAGS (\\Answered \\Flagged \\Draft \\Deleted \\Seen \\*)]", "* 0 EXISTS", "* 0 RECENT", "* OK [UNSEEN 0]", "* OK [UIDNEXT 1]", getNextTag(true) + " OK [READ-WRITE] " + FOLDER_2 }); folders[1].open(OpenMode.READ_WRITE); folders[1].close(false); }