properties, null);
return new MimeMessage(session);
}
This is my test method.
@Test(description = "test powermock mime message creation")
public void testCreateMessage() throws Exception {
Session realSession = Session.getDefaultInstance(this.properties, null);
PowerMockito.mock(Session.class);
PowerMockito.stub(PowerMockito.method(Session.class,
"getDefaultInstance", Properties.class, Authenticator.class))
.andReturn(realSession);
MimeMessage message = PowerMockito.mock(MimeMessage.class);
PowerMockito.whenNew(MimeMessage.class).withParameterTypes(Session.class)
.withArguments(realSession).thenReturn(message);
MimeHelper helper = new MimeHelper();
MimeMessage testMessage = helper.createMessage(this.properties);
Assert.assertNotNull(testMessage);
PowerMockito.verifyStatic(Mockito.times(2));
Session.getDefaultInstance(Mockito.isA(Properties.class),
(Authenticator) Mockito.isNull());
PowerMockito.verifyNew(MimeMessage.class).withArguments(Mockito.any(Session.class));
}
I have prepared for test MimeHelper: (Iclass to be instatiated) and (Session class) to
For the statement in bold, I have also tried the following options
1. PowerMockito.verifyNew(MimeMessage.class)withArguments(realSession);
2. PowerMockito.verifyNew(MimeMessage.class).withArguments(Mockito.isA(Session.class));
and I get the same error message. The funny thing is that this
verification statement causes my other test to fail, the one that you
helped me fix. If I remove this statement, my other test passes.
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
......
Caused by: org.mockito.exceptions.misusing.UnfinishedVerificationException:
Missing method call for verify(mock) here:
-> at org.powermock.api.mockito.PowerMockito.verifyStatic(PowerMockito.java:155)