Example usage for android.test MoreAsserts assertEquals

List of usage examples for android.test MoreAsserts assertEquals

Introduction

In this page you can find the example usage for android.test MoreAsserts assertEquals.

Prototype

public static void assertEquals(Set<? extends Object> expected, Set<? extends Object> actual) 

Source Link

Document

Asserts that two sets contain the same elements.

Usage

From source file:com.example.android.vault.EncryptedDocumentTest.java

private void testMetadataAndContents(byte[] content) throws Exception {
    final EncryptedDocument doc = new EncryptedDocument(4, mFile, mDataKey, mMacKey);
    final byte[] beforeContent = content;

    final ParcelFileDescriptor[] beforePipe = ParcelFileDescriptor.createReliablePipe();
    new Thread() {
        @Override/*  w  w  w . j a v  a2  s  .c  om*/
        public void run() {
            final FileOutputStream os = new FileOutputStream(beforePipe[1].getFileDescriptor());
            try {
                os.write(beforeContent);
                beforePipe[1].close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }.start();

    // fully write metadata and content
    final JSONObject before = new JSONObject();
    before.put("meow", "cake");
    doc.writeMetadataAndContent(before, beforePipe[0]);

    // now go back and verify we can read
    final JSONObject after = doc.readMetadata();
    assertEquals("cake", after.getString("meow"));

    final CountDownLatch latch = new CountDownLatch(1);
    final ParcelFileDescriptor[] afterPipe = ParcelFileDescriptor.createReliablePipe();
    final byte[] afterContent = new byte[beforeContent.length];
    new Thread() {
        @Override
        public void run() {
            final FileInputStream is = new FileInputStream(afterPipe[0].getFileDescriptor());
            try {
                int i = 0;
                while (i < afterContent.length) {
                    int n = is.read(afterContent, i, afterContent.length - i);
                    i += n;
                }
                afterPipe[0].close();
                latch.countDown();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }.start();

    doc.readContent(afterPipe[1]);
    latch.await(5, TimeUnit.SECONDS);

    MoreAsserts.assertEquals(beforeContent, afterContent);
}

From source file:org.uribeacon.beacon.UriBeaconTest.java

public void testToByteArrayWithEmptyUriString() throws URISyntaxException {
    UriBeacon beacon = new UriBeacon.Builder().uriString("").build();
    MoreAsserts.assertEquals(TestData.emptyAdbPacketBytes, beacon.toByteArray());

}

From source file:org.uribeacon.beacon.UriBeaconTest.java

public void testToByteArrayWithUriString() throws URISyntaxException {
    UriBeacon beacon = new UriBeacon.Builder().uriString(TestData.urlTestString).build();
    MoreAsserts.assertEquals(TestData.validUrlAdbPacketBytes, beacon.toByteArray());

}

From source file:org.uribeacon.beacon.UriBeaconTest.java

public void testToByteArrayWithUriByteArray() throws URISyntaxException {
    UriBeacon beacon = new UriBeacon.Builder().uriString(TestData.urlTestByteArray).build();
    MoreAsserts.assertEquals(TestData.validUrlAdbPacketBytes, beacon.toByteArray());
}

From source file:org.uribeacon.beacon.UriBeaconTest.java

public void testUriBeaconTestData() throws JSONException, IOException {
    Context context = getContext();
    AssetManager am = context.getAssets();
    JSONObject testObject = inputJson(am.open("testdata.json"));
    JSONArray testData = testObject.getJSONArray("test-data");
    for (int i = 0; i < testData.length(); i++) {
        JSONObject encodingTest = testData.getJSONObject(i);

        String uri = encodingTest.getString("url");
        assertNotNull(uri);//from w ww  . ja  v  a 2s  .  co m
        Integer txPowerLevel = encodingTest.optInt("tx", 20);
        Integer flags = encodingTest.optInt("flags", 0);
        UriBeacon uriBeacon;
        try {
            uriBeacon = new UriBeacon.Builder().uriString(uri).txPowerLevel(txPowerLevel.byteValue())
                    .flags(flags.byteValue()).build();
        } catch (URISyntaxException e) {
            uriBeacon = null;
        }
        JSONArray scanRecordJson = encodingTest.optJSONArray("scanRecord");
        if (scanRecordJson == null || uriBeacon == null) {
            assertNull("Null assert failed for uriBeacon", scanRecordJson);
            assertNull("Null assert failed for " + uriBeacon, uriBeacon);
        } else {
            byte[] scanRecord = jsonToByteArray(scanRecordJson);
            byte[] uriBeaconScanRecord = uriBeacon.toByteArray();
            MoreAsserts.assertEquals(scanRecord, uriBeaconScanRecord);
        }
    }
}

From source file:com.android.email.mail.store.ImapStoreUnitTests.java

/**
 * Test for fetching simple BODYSTRUCTURE.
 *///from   w  ww . j av  a 2s.c o m
public void testFetchBodyStructureSimple() 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 nIL 18 3 nIL nIL nIL))",
            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"));
    MoreAsserts.assertEquals(new String[] { ";\n size=18" }, message.getHeader("Content-Disposition"));

    MoreAsserts.assertEquals(new String[] { "TEXT" }, message.getHeader("X-Android-Attachment-StoreData"));

    // TODO: Test NO response.
}

From source file:com.android.email.mail.store.ImapStoreUnitTests.java

/**
 * Test for fetching complex muiltipart BODYSTRUCTURE.
 *//*from w  ww.j av a  2 s.c  om*/
public void testFetchBodyStructureMultipart() 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\" () {20}",
                    "long content id#@!@#"
                            + " NIL \"7BIT\" 18 3 NIL NIL NIL)" + "(\"IMAGE\" \"PNG\" (\"NAME\" {10}",
                    "device.png) NIL NIL \"BASE64\" {6}",
                    "117840 NIL (\"aTTACHMENT\" (\"fILENAME\" \"device.png\")) NIL)"
                            + "(\"TEXT\" \"HTML\" () NIL NIL \"7BIT\" 100 NIL 123 (\"aTTACHMENT\""
                            + "(\"fILENAME\" {15}",
                    "attachment.html \"SIZE\" 555)) NIL)"
                            + "((\"TEXT\" \"HTML\" NIL NIL \"BASE64\")(\"XXX\" \"YYY\"))" + // Nested
                            "\"mIXED\" (\"bOUNDARY\" \"00032556278a7005e40486d159ca\") NIL NIL))",
                    getNextTag(true) + " oK SUCCESS" });
    mFolder.fetch(new Message[] { message }, fp, null);

    // Check mime structure...
    final Body body = message.getBody();
    assertTrue(body instanceof MimeMultipart);
    MimeMultipart mimeMultipart = (MimeMultipart) body;
    assertEquals(4, mimeMultipart.getCount());
    assertEquals("mixed", mimeMultipart.getSubTypeForTest());

    final Part part1 = mimeMultipart.getBodyPart(0);
    final Part part2 = mimeMultipart.getBodyPart(1);
    final Part part3 = mimeMultipart.getBodyPart(2);
    final Part part4 = mimeMultipart.getBodyPart(3);
    assertTrue(part1 instanceof MimeBodyPart);
    assertTrue(part2 instanceof MimeBodyPart);
    assertTrue(part3 instanceof MimeBodyPart);
    assertTrue(part4 instanceof MimeBodyPart);

    final MimeBodyPart mimePart1 = (MimeBodyPart) part1; // text/plain
    final MimeBodyPart mimePart2 = (MimeBodyPart) part2; // image/png
    final MimeBodyPart mimePart3 = (MimeBodyPart) part3; // text/html
    final MimeBodyPart mimePart4 = (MimeBodyPart) part4; // Nested

    MoreAsserts.assertEquals(new String[] { "1" }, part1.getHeader("X-Android-Attachment-StoreData"));
    MoreAsserts.assertEquals(new String[] { "2" }, part2.getHeader("X-Android-Attachment-StoreData"));
    MoreAsserts.assertEquals(new String[] { "3" }, part3.getHeader("X-Android-Attachment-StoreData"));

    MoreAsserts.assertEquals(new String[] { "text/plain" }, part1.getHeader("Content-Type"));
    MoreAsserts.assertEquals(new String[] { "image/png;\n NAME=\"device.png\"" },
            part2.getHeader("Content-Type"));
    MoreAsserts.assertEquals(new String[] { "text/html" }, part3.getHeader("Content-Type"));

    MoreAsserts.assertEquals(new String[] { "long content id#@!@#" }, part1.getHeader("Content-ID"));
    assertNull(part2.getHeader("Content-ID"));
    assertNull(part3.getHeader("Content-ID"));

    MoreAsserts.assertEquals(new String[] { "7BIT" }, part1.getHeader("Content-Transfer-Encoding"));
    MoreAsserts.assertEquals(new String[] { "BASE64" }, part2.getHeader("Content-Transfer-Encoding"));
    MoreAsserts.assertEquals(new String[] { "7BIT" }, part3.getHeader("Content-Transfer-Encoding"));

    MoreAsserts.assertEquals(new String[] { ";\n size=18" }, part1.getHeader("Content-Disposition"));
    MoreAsserts.assertEquals(new String[] { "attachment;\n filename=\"device.png\";\n size=117840" },
            part2.getHeader("Content-Disposition"));
    MoreAsserts.assertEquals(new String[] { "attachment;\n filename=\"attachment.html\";\n size=\"555\"" },
            part3.getHeader("Content-Disposition"));

    // Check the nested parts.
    final Body part4body = part4.getBody();
    assertTrue(part4body instanceof MimeMultipart);
    MimeMultipart mimeMultipartPart4 = (MimeMultipart) part4body;
    assertEquals(2, mimeMultipartPart4.getCount());

    final MimeBodyPart mimePart41 = (MimeBodyPart) mimeMultipartPart4.getBodyPart(0);
    final MimeBodyPart mimePart42 = (MimeBodyPart) mimeMultipartPart4.getBodyPart(1);

    MoreAsserts.assertEquals(new String[] { "4.1" }, mimePart41.getHeader("X-Android-Attachment-StoreData"));
    MoreAsserts.assertEquals(new String[] { "4.2" }, mimePart42.getHeader("X-Android-Attachment-StoreData"));
}

From source file:com.appaholics.email.mail.store.ImapStoreUnitTests.java

/**
 * Test for fetching simple BODYSTRUCTURE.
 *//*  ww  w.ja v a2s . c om*/
public void testFetchBodyStructureSimple() 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 nIL 18 3 nIL nIL nIL))",
            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"));
    MoreAsserts.assertEquals(new String[] { ";\n size=18" }, message.getHeader("Content-Disposition"));

    MoreAsserts.assertEquals(new String[] { "TEXT" }, message.getHeader("X-Android-Attachment-StoreData"));

    // TODO: Test NO response.
}

From source file:com.appaholics.email.mail.store.ImapStoreUnitTests.java

/**
 * Test for fetching complex muiltipart BODYSTRUCTURE.
 *//* ww w.java 2 s. c  o m*/
public void testFetchBodyStructureMultipart() 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\" () {20}",
                    "long content id#@!@#"
                            + " NIL \"7BIT\" 18 3 NIL NIL NIL)" + "(\"IMAGE\" \"PNG\" (\"NAME\" {10}",
                    "device.png) NIL NIL \"BASE64\" {6}",
                    "117840 NIL (\"aTTACHMENT\" (\"fILENAME\" \"device.png\")) NIL)"
                            + "(\"TEXT\" \"HTML\" () NIL NIL \"7BIT\" 100 NIL 123 (\"aTTACHMENT\""
                            + "(\"fILENAME\" {15}",
                    "attachment.html \"SIZE\" 555)) NIL)"
                            + "((\"TEXT\" \"HTML\" NIL NIL \"BASE64\")(\"XXX\" \"YYY\"))" + // Nested
                            "\"mIXED\" (\"bOUNDARY\" \"00032556278a7005e40486d159ca\") NIL NIL))",
                    getNextTag(true) + " oK SUCCESS" });
    mFolder.fetch(new Message[] { message }, fp, null);

    // Check mime structure...
    final Body body = message.getBody();
    assertTrue(body instanceof MimeMultipart);
    MimeMultipart mimeMultipart = (MimeMultipart) body;
    assertEquals(4, mimeMultipart.getCount());
    assertEquals("mixed", mimeMultipart.getSubTypeForTest());

    final Part part1 = mimeMultipart.getBodyPart(0);
    final Part part2 = mimeMultipart.getBodyPart(1);
    final Part part3 = mimeMultipart.getBodyPart(2);
    final Part part4 = mimeMultipart.getBodyPart(3);
    assertTrue(part1 instanceof MimeBodyPart);
    assertTrue(part2 instanceof MimeBodyPart);
    assertTrue(part3 instanceof MimeBodyPart);
    assertTrue(part4 instanceof MimeBodyPart);

    final MimeBodyPart mimePart1 = (MimeBodyPart) part1; // text/plain
    final MimeBodyPart mimePart2 = (MimeBodyPart) part2; // image/png
    final MimeBodyPart mimePart3 = (MimeBodyPart) part3; // text/html
    final MimeBodyPart mimePart4 = (MimeBodyPart) part4; // Nested

    MoreAsserts.assertEquals(new String[] { "1" }, part1.getHeader("X-Android-Attachment-StoreData"));
    MoreAsserts.assertEquals(new String[] { "2" }, part2.getHeader("X-Android-Attachment-StoreData"));
    MoreAsserts.assertEquals(new String[] { "3" }, part3.getHeader("X-Android-Attachment-StoreData"));

    MoreAsserts.assertEquals(new String[] { "text/plain" }, part1.getHeader("Content-Type"));
    MoreAsserts.assertEquals(new String[] { "image/png;\n NAME=\"device.png\"" },
            part2.getHeader("Content-Type"));
    MoreAsserts.assertEquals(new String[] { "text/html" }, part3.getHeader("Content-Type"));

    MoreAsserts.assertEquals(new String[] { "long content id#@!@#" }, part1.getHeader("Content-ID"));
    assertNull(part2.getHeader("Content-ID"));
    assertNull(part3.getHeader("Content-ID"));

    MoreAsserts.assertEquals(new String[] { "7BIT" }, part1.getHeader("Content-Transfer-Encoding"));
    MoreAsserts.assertEquals(new String[] { "BASE64" }, part2.getHeader("Content-Transfer-Encoding"));
    MoreAsserts.assertEquals(new String[] { "7BIT" }, part3.getHeader("Content-Transfer-Encoding"));

    MoreAsserts.assertEquals(new String[] { ";\n size=18" }, part1.getHeader("Content-Disposition"));
    MoreAsserts.assertEquals(new String[] { "attachment;\n filename=\"device.png\";\n size=117840" },
            part2.getHeader("Content-Disposition"));
    MoreAsserts.assertEquals(new String[] { "attachment;\n filename=\"attachment.html\";\n size=\"555\"" },
            part3.getHeader("Content-Disposition"));

    // Check the nested parts.
    final Body part4body = part4.getBody();
    assertTrue(part4body instanceof MimeMultipart);
    MimeMultipart mimeMultipartPart4 = (MimeMultipart) part4body;
    assertEquals(2, mimeMultipartPart4.getCount());

    final MimeBodyPart mimePart41 = (MimeBodyPart) mimeMultipartPart4.getBodyPart(0);
    final MimeBodyPart mimePart42 = (MimeBodyPart) mimeMultipartPart4.getBodyPart(1);

    MoreAsserts.assertEquals(new String[] { "4.1" }, mimePart41.getHeader("X-Android-Attachment-StoreData"));
    MoreAsserts.assertEquals(new String[] { "4.2" }, mimePart42.getHeader("X-Android-Attachment-StoreData"));
}

From source file:com.android.email.mail.store.ImapStoreUnitTests.java

public void testGetPersonalNamespaces() throws Exception {
    MockTransport mock = openAndInjectMockTransport();
    expectLogin(mock);/*from   ww w .j  a  va 2 s . c  o m*/

    mock.expect(getNextTag(false) + " LIST \"\" \"\\*\"",
            new String[] { "* lIST (\\HAsNoChildren) \"/\" \"inbox\"",
                    "* lIST (\\hAsnochildren) \"/\" \"Drafts\"", "* lIST (\\nOselect) \"/\" \"no select\"",
                    "* lIST (\\HAsNoChildren) \"/\" \"&ZeVnLIqe-\"", // Japanese folder name
                    getNextTag(true) + " oK SUCCESS" });
    Folder[] folders = mStore.getPersonalNamespaces();

    ArrayList<String> list = new ArrayList<String>();
    for (Folder f : folders) {
        list.add(f.getName());
    }
    MoreAsserts.assertEquals(new String[] { "Drafts", "\u65E5\u672C\u8A9E", "INBOX" },
            list.toArray(new String[0]));

    // TODO test with path prefix
    // TODO: Test NO response.
}