use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewDemoTest method testSimpleMultipleNewPrivate_tooManyTimesExpected.
@Test
public void testSimpleMultipleNewPrivate_tooManyTimesExpected() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).times(4);
replay(myClassMock1, MyClass.class);
try {
Whitebox.invokeMethod(tested, "simpleMultipleNewPrivate");
verify(myClassMock1, MyClass.class);
fail("Should throw an exception!.");
} 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 testGetMessageWithArgument.
@Test
public void testGetMessageWithArgument() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock);
String expected = "Hello altered World";
expect(myClassMock.getMessage("test")).andReturn("Hello altered World");
replay(myClassMock, MyClass.class);
String actual = tested.getMessageWithArgument();
verify(myClassMock, MyClass.class);
assertEquals("Expected and actual did not match", expected, actual);
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewDemoTest method testSimpleMultipleNew.
@Test
public void testSimpleMultipleNew() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).times(3);
replay(myClassMock1, MyClass.class);
tested.simpleMultipleNew();
verify(myClassMock1, MyClass.class);
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewDemoTest 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 testExpectNewButNoNewCallWasMade.
@Test
public void testExpectNewButNoNewCallWasMade() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).once();
replay(myClassMock1, MyClass.class);
try {
tested.makeDate();
verify(myClassMock1, MyClass.class);
fail("Should throw AssertionError!");
} catch (AssertionError e) {
assertTrue(e.getMessage().contains(MyClass.class.getName() + "(): expected: 1, actual: 0"));
}
}
Aggregations