use of samples.expectnew.ExpectNewDemo in project powermock by powermock.
the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testSimpleSingleNew_withAtLeastOnce.
@Test
public void testSimpleSingleNew_withAtLeastOnce() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).atLeastOnce();
replayAll();
tested.simpleSingleNew();
verifyAll();
}
use of samples.expectnew.ExpectNewDemo in project powermock by powermock.
the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testNewWithRuntimeException.
@Test
public void testNewWithRuntimeException() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
final String expectedFailMessage = "testing";
expectNew(MyClass.class).andThrow(new RuntimeException(expectedFailMessage));
replayAll();
try {
tested.throwExceptionWhenInvoction();
fail("Should throw RuntimeException!");
} catch (RuntimeException e) {
assertEquals(expectedFailMessage, e.getMessage());
}
verifyAll();
}
use of samples.expectnew.ExpectNewDemo in project powermock by powermock.
the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testInvokeVoidMethod.
@Test
public void testInvokeVoidMethod() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock);
myClassMock.voidMethod();
expectLastCall().times(1);
replayAll();
tested.invokeVoidMethod();
verifyAll();
}
use of samples.expectnew.ExpectNewDemo in project powermock by powermock.
the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testSimpleMultipleNew_withRange_notWithinRange.
@Test
public void testSimpleMultipleNew_withRange_notWithinRange() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).times(5, 7);
replayAll();
tested.simpleMultipleNew();
try {
verifyAll();
fail("Should throw AssertionError.");
} catch (AssertionError e) {
assertEquals("\n Expectation failure on verify:" + "\n samples.newmocking.MyClass(): expected: between 5 and 7, actual: 3", e.getMessage());
}
}
use of samples.expectnew.ExpectNewDemo in project powermock by powermock.
the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testSimpleMultipleNew_tooFewTimesExpected.
@Test
public void testSimpleMultipleNew_tooFewTimesExpected() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).times(2);
replayAll();
try {
tested.simpleMultipleNew();
fail("Should throw AssertionError.");
} catch (AssertionError e) {
assertEquals("\n Unexpected constructor call samples.newmocking.MyClass():" + "\n samples.newmocking.MyClass(): expected: 2, actual: 3", e.getMessage());
}
}
Aggregations