java mimemessage_java – MimeMessage.saveChanges真的很慢

  • Post author:
  • Post category:java


由于包含m.saveChanges(),以下测试大约需要5秒钟才能执行.

import org.junit.Before;

import org.junit.Test;

import javax.mail.MessagingException;

import javax.mail.Session;

import javax.mail.internet.MimeMessage;

import java.io.IOException;

import java.util.Properties;

import static org.junit.Assert.assertEquals;

import static org.mockito.Mockito.mock;

import static org.mockito.Mockito.when;

@Test

public void test1() throws MessagingException, IOException {

Session s = Session.getDefaultInstance(new Properties());

MimeMessage m = new MimeMessage(s);

m.setContent(”

Hello

“, “text/html; charset=utf-8”);

m.saveChanges();

assertEquals(m.getContent(), ”

Hello

“);

assertEquals(m.getContentType(), “text/html; charset=utf-8”);

}

我也用mockito嘲笑了Session,但它没有帮助:

Session s = mock(Session.class);

when(s.getProperties()).thenReturn(new Properties());

这里有什么问题?我可以嘲笑什么来加快速度?



版权声明:本文为weixin_42134117原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。