use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewCases method testSimpleMultipleNew_withAtLeastOnce.
@Test
public void testSimpleMultipleNew_withAtLeastOnce() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).atLeastOnce();
replay(myClassMock1, MyClass.class);
tested.simpleMultipleNew();
verify(myClassMock1, MyClass.class);
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewCases 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();
replay(myClassMock1, MyClass.class);
tested.simpleSingleNew();
verify(myClassMock1, MyClass.class);
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewDemoTest method testSimpleMultipleNew_tooManyTimesExpected.
@Test
public void testSimpleMultipleNew_tooManyTimesExpected() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).times(4);
replay(myClassMock1, MyClass.class);
tested.simpleMultipleNew();
try {
verify(myClassMock1, MyClass.class);
fail("Should throw AssertionError.");
} catch (AssertionError e) {
assertEquals("\n Expectation failure on verify:" + "\n samples.newmocking.MyClass(): expected: 4, actual: 3", e.getMessage());
}
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewDemoTest 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 ExpectNewDemoTest 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);
replay(myClassMock1, MyClass.class);
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