private void verifyParsedMessage(ParsedMessage pm, ExpectedResults expected) throws Exception { // Run tests multiple times to make sure the API's don't alter the state of the ParsedMessage for (int i = 1; i < 3; i++) { // Test accessors. assertEquals(expected.rawContent, new String(pm.getRawData())); assertEquals(expected.convertedSubject, pm.getSubject()); // Test sender and recipient String sender = TestUtil.getAddress(SENDER_NAME); String recipient = TestUtil.getAddress(RECIPIENT_NAME); assertTrue(pm.getSender().contains(sender)); assertEquals(sender, pm.getSenderEmail()); assertTrue(pm.getRecipients().contains(recipient)); // Test InputStream accessor String contentFromStream = new String(ByteUtil.getContent(pm.getRawInputStream(), expected.rawContent.length())); assertEquals(expected.rawContent, contentFromStream); // Test MimeMessage accessor assertTrue(getContent(pm.getMimeMessage()).contains(expected.convertedSubject)); // Test mutated status assertEquals(expected.wasMutated, pm.wasMutated()); pm.analyzeFully(); } }
private void verifyMutatedMessage(ParsedMessage pm, String substring, boolean wasMutated) throws Exception { assertEquals(wasMutated, pm.wasMutated()); assertTrue(pm.getSubject().contains(substring)); assertTrue((new String(pm.getRawData()).contains(substring))); byte[] data = ByteUtil.getContent(pm.getRawInputStream(), 0); assertTrue((new String(data)).contains(substring)); data = pm.getRawData(); assertTrue((new String(data)).contains(substring)); }