### Question:
BetterMimeMessage extends MimeMessage { public boolean isBounced() throws IOException, MessagingException { if (isAutomaticMessage()) { return true; } if (mimeMessage.getContent() instanceof Multipart) { Multipart parts = (Multipart) this.mimeMessage.getContent(); for (int i = 0; i < parts.getCount(); i++) { String contentType = parts.getBodyPart(i).getContentType(); if (isNotification(contentType)) { return true; } } } return isNotification(this.mimeMessage.getContentType()); } BetterMimeMessage(MimeMessage message); boolean isSpam(); float getSpamLevel(); boolean isBounced(); static final String SPAM_FLAG_HEADER; static final String SPAM_LEVEL_HEADER; static final String AUTO_SUBMITTED_HEADER; }### Answer:
@Test public void testIsBounced() throws Exception { MimeMessage automatic = mock(MimeMessage.class); when(automatic.getHeader("Auto-Submitted")).thenReturn(new String[]{"bart", "auto-replied"}); BetterMimeMessage instance = new BetterMimeMessage(automatic); assertTrue(instance.isBounced()); automatic = mock(MimeMessage.class); when(automatic.getHeader("Auto-Submitted")).thenReturn(new String[]{"bart", "auto-generated"}); instance = new BetterMimeMessage(automatic); assertTrue(instance.isBounced()); automatic = mock(MimeMessage.class); when(automatic.getHeader("Auto-Submitted")).thenReturn(new String[]{"bart", "auto-notified; " + "owner-email=\"me@example.com\""}); instance = new BetterMimeMessage(automatic); assertTrue(instance.isBounced()); automatic = mock(MimeMessage.class); when(automatic.getHeader("Auto-Submitted")).thenReturn(new String[]{"bart", "auto-notified; " + "owner-token=af3NN2pK5dDXI0W"}); instance = new BetterMimeMessage(automatic); assertTrue(instance.isBounced()); automatic = mock(MimeMessage.class); when(automatic.getContent()).thenReturn("Hello World"); instance = new BetterMimeMessage(automatic); when(automatic.getContentType()).thenReturn("multipart/report; report-type=delivery-status;\n\t" + "boundary=\"A3DB01912007.1281602599/zimbra.oevo.com\""); assertTrue(instance.isBounced()); when(automatic.getContentType()).thenReturn("message/delivery-status"); assertTrue(instance.isBounced()); when(automatic.getContentType()).thenReturn("message/rfc822"); assertFalse(instance.isBounced()); when(automatic.getContentType()).thenReturn("text/plain; charset=utf-8"); assertFalse(instance.isBounced()); }