use of samples.newmocking.MyClass in project powermock by powermock.
the class VerifyNoMoreInteractionsTest method verifyNoMoreInteractionsDelegatesToPlainMockitoWhenMockIsNotAPowerMockitoMock.
@Test
public void verifyNoMoreInteractionsDelegatesToPlainMockitoWhenMockIsNotAPowerMockitoMock() throws Exception {
MyClass myClassMock = Mockito.mock(MyClass.class);
myClassMock.getMessage();
try {
verifyNoMoreInteractions(myClassMock);
fail("Should throw exception!");
} catch (AssertionError e) {
/*
* This string would have been deleted by PowerMockito but should
* exists if delegation took place.
*/
final String expectedTextThatProvesDelegation = "But found this interaction";
assertTrue(e.getMessage().contains(expectedTextThatProvesDelegation));
}
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class WhenNewCases method testInvokeVoidMethod.
@Test
public void testInvokeVoidMethod() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock = mock(MyClass.class);
whenNew(MyClass.class).withNoArguments().thenReturn(myClassMock);
doNothing().when(myClassMock).voidMethod();
tested.invokeVoidMethod();
verify(myClassMock).voidMethod();
verifyNew(MyClass.class).withNoArguments();
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class WhenNewCases method testGetMessage.
@Test
public void testGetMessage() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock = mock(MyClass.class);
whenNew(MyClass.class).withNoArguments().thenReturn(myClassMock);
String expected = "Hello altered World";
when(myClassMock.getMessage()).thenReturn("Hello altered World");
String actual = tested.getMessage();
verify(myClassMock).getMessage();
verifyNew(MyClass.class).withNoArguments();
assertEquals("Expected and actual did not match", expected, actual);
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class WhenNewCases method testSimpleMultipleNewPrivate_tooManyTimesExpected.
@Test
public void testSimpleMultipleNewPrivate_tooManyTimesExpected() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = mock(MyClass.class);
whenNew(MyClass.class).withNoArguments().thenReturn(myClassMock1);
Whitebox.invokeMethod(tested, "simpleMultipleNewPrivate");
try {
verifyNew(MyClass.class, times(4)).withNoArguments();
fail("Should throw an exception!.");
} catch (AssertionError e) {
assertEquals("samples.newmocking.MyClass();\nWanted 4 times but was 3 times.", e.getMessage());
}
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class WhenNewCases method testMultipleNew.
@Test
public void testMultipleNew() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock = mock(MyClass.class);
whenNew(MyClass.class).withNoArguments().thenReturn(myClassMock);
when(myClassMock.getMessage()).thenReturn("Hello");
final String actual = tested.multipleNew();
verify(myClassMock, times(2)).getMessage();
verifyNew(MyClass.class, times(2)).withNoArguments();
assertEquals("HelloHello", actual);
}
Aggregations