由于包含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());
这里有什么问题?我可以嘲笑什么来加快速度?