use of samples.privatemocking.PrivateMethodDemo in project powermock by powermock.
the class PrivateInstanceMockingTest method expectationsWorkWhenSpyingOnPrivateVoidMethods.
@Test(expected = ArrayStoreException.class)
public void expectationsWorkWhenSpyingOnPrivateVoidMethods() throws Exception {
PrivateMethodDemo tested = spy(new PrivateMethodDemo());
tested.doObjectStuff(new Object());
when(tested, "doObjectInternal", isA(Object.class)).thenThrow(new ArrayStoreException());
tested.doObjectStuff(new Object());
}
use of samples.privatemocking.PrivateMethodDemo in project powermock by powermock.
the class PrivateInstanceMockingTest method answersWorkWhenSpyingOnPrivateVoidMethods.
@Test
public void answersWorkWhenSpyingOnPrivateVoidMethods() throws Exception {
PrivateMethodDemo tested = spy(new PrivateMethodDemo());
tested.doObjectStuff(new Object());
when(tested, "doObjectInternal", isA(String.class)).thenAnswer(new Answer<Void>() {
private static final long serialVersionUID = 20645008237481667L;
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
assertEquals("Testing", invocation.getArguments()[0]);
return null;
}
});
tested.doObjectStuff(new Object());
tested.doObjectStuff("Testing");
}
use of samples.privatemocking.PrivateMethodDemo in project powermock by powermock.
the class PrivateInstanceMockingTest method expectationsWorkWithArgumentMatchersWhenSpyingOnPrivateMethods.
@Test
public void expectationsWorkWithArgumentMatchersWhenSpyingOnPrivateMethods() throws Exception {
PrivateMethodDemo tested = spy(new PrivateMethodDemo());
assertEquals("Hello Temp, you are 50 old.", tested.sayYear("Temp", 50));
when(tested, "doSayYear", Mockito.anyInt(), Mockito.anyString()).thenReturn("another");
assertEquals("another", tested.sayYear("Johan", 29));
assertEquals("another", tested.sayYear("test", 12));
verifyPrivate(tested).invoke("doSayYear", 29, "Johan");
verifyPrivate(tested).invoke("doSayYear", 12, "test");
verifyPrivate(tested).invoke("doSayYear", 50, "Temp");
}
use of samples.privatemocking.PrivateMethodDemo in project powermock by powermock.
the class PrivateInstanceMockingTest method expectationsWorkWhenSpyingOnPrivateMethods.
@Test
public void expectationsWorkWhenSpyingOnPrivateMethods() throws Exception {
PrivateMethodDemo tested = spy(new PrivateMethodDemo());
assertEquals("Hello Temp, you are 50 old.", tested.sayYear("Temp", 50));
when(tested, "doSayYear", 12, "test").thenReturn("another");
assertEquals("Hello Johan, you are 29 old.", tested.sayYear("Johan", 29));
assertEquals("another", tested.sayYear("test", 12));
verifyPrivate(tested).invoke("doSayYear", 12, "test");
}
use of samples.privatemocking.PrivateMethodDemo in project powermock by powermock.
the class PrivateInstanceMockingTest method expectationsWorkWithArgumentMatchersWhenSpyingOnPrivateMethods.
@Test
public void expectationsWorkWithArgumentMatchersWhenSpyingOnPrivateMethods() throws Exception {
PrivateMethodDemo tested = spy(new PrivateMethodDemo());
assertEquals("Hello Temp, you are 50 old.", tested.sayYear("Temp", 50));
when(tested, "doSayYear", Mockito.anyInt(), Mockito.anyString()).thenReturn("another");
assertEquals("another", tested.sayYear("Johan", 29));
assertEquals("another", tested.sayYear("test", 12));
verifyPrivate(tested).invoke("doSayYear", 29, "Johan");
verifyPrivate(tested).invoke("doSayYear", 12, "test");
verifyPrivate(tested).invoke("doSayYear", 50, "Temp");
}
Aggregations