use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testSimpleMultipleNew_withRange_lowerBoundLessThan0.
@Test
public void testSimpleMultipleNew_withRange_lowerBoundLessThan0() throws Exception {
MyClass myClassMock1 = createMock(MyClass.class);
try {
expectNew(MyClass.class).andReturn(myClassMock1).times(-20, 2);
fail("Should throw IllegalArgumentException.");
} catch (IllegalArgumentException e) {
assertEquals("minimum must be >= 0", e.getMessage());
}
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest 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();
replayAll();
tested.simpleMultipleNew();
verifyAll();
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testSimpleMultipleNewPrivate_ok.
@Test
public void testSimpleMultipleNewPrivate_ok() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).times(3);
replayAll();
Whitebox.invokeMethod(tested, "simpleMultipleNewPrivate");
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testExpectNewButNoNewCallWasMade.
@Test
public void testExpectNewButNoNewCallWasMade() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).once();
replayAll();
try {
tested.makeDate();
verifyAll();
fail("Should throw AssertionError!");
} catch (AssertionError e) {
assertTrue(e.getMessage().contains(MyClass.class.getName() + "(): expected: 1, actual: 0"));
}
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest 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");
replayAll();
final String actual = tested.multipleNew();
verifyAll();
assertEquals("Hello World", actual);
}
Aggregations