use of samples.newmocking.MyClass 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.newmocking.MyClass 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.newmocking.MyClass 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());
}
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest 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("<="));
}
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class VerifyNoMoreInteractionsTest method verifyNoMoreInteractionsOnNewInstancesThrowsAssertionErrorWhenMoreInteractionsTookPlace.
@Test
public void verifyNoMoreInteractionsOnNewInstancesThrowsAssertionErrorWhenMoreInteractionsTookPlace() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock = mock(MyClass.class);
whenNew(MyClass.class).withNoArguments().thenReturn(myClassMock);
tested.simpleMultipleNew();
try {
verifyNoMoreInteractions(MyClass.class);
fail("Should throw exception!");
} catch (MockitoAssertionError e) {
assertTrue(e.getMessage().startsWith("\nNo interactions wanted here:\n-> at samples.powermockito.junit4.verifynomoreinteractions.VerifyNoMoreInteractionsTest.verifyNoMoreInteractionsOnNewInstancesThrowsAssertionErrorWhenMoreInteractionsTookPlace(VerifyNoMoreInteractionsTest.java:"));
}
}
Aggregations