use of samples.newmocking.MyClass in project powermock by powermock.
the class VerifyNoMoreInteractionsTest method verifyNoMoreInteractionsOnNewInstancesWorks.
@Test
public void verifyNoMoreInteractionsOnNewInstancesWorks() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock = mock(MyClass.class);
whenNew(MyClass.class).withNoArguments().thenReturn(myClassMock);
tested.simpleMultipleNew();
verifyNew(MyClass.class, times(3)).withNoArguments();
verifyNoMoreInteractions(MyClass.class);
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class WhenNewCases method testSimpleMultipleNewPrivate_ok.
@Test
public void testSimpleMultipleNewPrivate_ok() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = mock(MyClass.class);
whenNew(MyClass.class).withNoArguments().thenReturn(myClassMock1);
Whitebox.invokeMethod(tested, "simpleMultipleNewPrivate");
verifyNew(MyClass.class, times(3)).withNoArguments();
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewDemoTest method testMultipleNew.
@Test
public void testMultipleNew() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
MyClass myClassMock2 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1);
expectNew(MyClass.class).andReturn(myClassMock2);
expect(myClassMock1.getMessage()).andReturn("Hello ");
expect(myClassMock2.getMessage()).andReturn("World");
replay(myClassMock1, myClassMock2, MyClass.class);
final String actual = tested.multipleNew();
verify(myClassMock1, myClassMock2, MyClass.class);
assertEquals("Hello World", actual);
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewDemoTest method testSimpleMultipleNew_anyTimes.
@Test
public void testSimpleMultipleNew_anyTimes() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).anyTimes();
replay(myClassMock1, MyClass.class);
tested.simpleMultipleNew();
verify(myClassMock1, MyClass.class);
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewDemoTest method testSimpleMultipleNew_withRange_upperBoundLessThanLowerBound.
@Test
public void testSimpleMultipleNew_withRange_upperBoundLessThanLowerBound() throws Exception {
MyClass myClassMock1 = createMock(MyClass.class);
try {
expectNew(MyClass.class).andReturn(myClassMock1).times(10, 2);
fail("Should throw IllegalArgumentException.");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("<="));
}
}
Aggregations