Search in sources :

Example 1 with TestCoreResourceProvider

use of com.fsck.k9.TestCoreResourceProvider in project k-9 by k9mail.

the class MessageViewInfoExtractorTest method setUp.

@Before
public void setUp() throws Exception {
    context = RuntimeEnvironment.application;
    HtmlProcessor htmlProcessor = createFakeHtmlProcessor();
    attachmentInfoExtractor = spy(DI.get(AttachmentInfoExtractor.class));
    messageViewInfoExtractor = new MessageViewInfoExtractor(attachmentInfoExtractor, htmlProcessor, new TestCoreResourceProvider());
}
Also used : HtmlProcessor(app.k9mail.html.cleaner.HtmlProcessor) TestCoreResourceProvider(com.fsck.k9.TestCoreResourceProvider) Before(org.junit.Before)

Example 2 with TestCoreResourceProvider

use of com.fsck.k9.TestCoreResourceProvider in project k-9 by k9mail.

the class MessageViewInfoExtractorTest method testShouldSanitizeOutputHtml.

@Test
public void testShouldSanitizeOutputHtml() throws MessagingException {
    // Create text/plain body
    TextBody body = new TextBody(BODY_TEXT);
    // Create message
    MimeMessage message = new MimeMessage();
    MimeMessageHelper.setBody(message, body);
    message.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/plain; format=flowed");
    // Prepare fixture
    HtmlProcessor htmlProcessor = mock(HtmlProcessor.class);
    MessageViewInfoExtractor messageViewInfoExtractor = new MessageViewInfoExtractor(null, htmlProcessor, new TestCoreResourceProvider());
    String value = "--sanitized html--";
    when(htmlProcessor.processForDisplay(anyString())).thenReturn(value);
    // Extract text
    List<Part> outputNonViewableParts = new ArrayList<>();
    ArrayList<Viewable> outputViewableParts = new ArrayList<>();
    MessageExtractor.findViewablesAndAttachments(message, outputViewableParts, outputNonViewableParts);
    ViewableExtractedText viewableExtractedText = messageViewInfoExtractor.extractTextFromViewables(outputViewableParts);
    assertSame(value, viewableExtractedText.html);
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) HtmlProcessor(app.k9mail.html.cleaner.HtmlProcessor) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) TestCoreResourceProvider(com.fsck.k9.TestCoreResourceProvider) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) ArrayList(java.util.ArrayList) Viewable(com.fsck.k9.mail.internet.Viewable) ViewableExtractedText(com.fsck.k9.mailstore.MessageViewInfoExtractor.ViewableExtractedText) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) K9RobolectricTest(com.fsck.k9.K9RobolectricTest) Test(org.junit.Test)

Aggregations

HtmlProcessor (app.k9mail.html.cleaner.HtmlProcessor)2 TestCoreResourceProvider (com.fsck.k9.TestCoreResourceProvider)2 K9RobolectricTest (com.fsck.k9.K9RobolectricTest)1 BodyPart (com.fsck.k9.mail.BodyPart)1 Part (com.fsck.k9.mail.Part)1 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)1 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)1 TextBody (com.fsck.k9.mail.internet.TextBody)1 Viewable (com.fsck.k9.mail.internet.Viewable)1 ViewableExtractedText (com.fsck.k9.mailstore.MessageViewInfoExtractor.ViewableExtractedText)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1