### Question:
BetterMimeMessage extends MimeMessage { protected boolean isAutomaticMessage() throws MessagingException { String[] autoSubmittedHeaders = this.mimeMessage.getHeader(AUTO_SUBMITTED_HEADER); if (autoSubmittedHeaders != null) { for (String autoSubmittedHeader : autoSubmittedHeaders) { if ("auto-generated".equalsIgnoreCase(autoSubmittedHeader) || "auto-replied".equalsIgnoreCase(autoSubmittedHeader) || autoSubmittedHeader.startsWith("auto-notified")) { return true; } } } return false; } 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 testIsAutomaticMessage() throws MessagingException { MimeMessage automatic = mock(MimeMessage.class); when(automatic.getHeader("Auto-Submitted")).thenReturn(new String[]{"bart", "auto-replied"}); BetterMimeMessage instance = new BetterMimeMessage(automatic); assertTrue(instance.isAutomaticMessage()); automatic = mock(MimeMessage.class); when(automatic.getHeader("Auto-Submitted")).thenReturn(new String[]{"bart", "auto-generated"}); instance = new BetterMimeMessage(automatic); assertTrue(instance.isAutomaticMessage()); 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.isAutomaticMessage()); automatic = mock(MimeMessage.class); when(automatic.getHeader("Auto-Submitted")).thenReturn(new String[]{"bart", "auto-notified; " + "owner-token=af3NN2pK5dDXI0W"}); instance = new BetterMimeMessage(automatic); assertTrue(instance.isAutomaticMessage()); }