use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testSimpleMultipleNewPrivate_tooFewTimesExpected.
/**
* Verifies that the issue
* http://code.google.com/p/powermock/issues/detail?id=10 is solved.
*/
@Test
public void testSimpleMultipleNewPrivate_tooFewTimesExpected() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).times(2);
replayAll();
try {
Whitebox.invokeMethod(tested, "simpleMultipleNewPrivate");
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 MultiReplayVerifyTest method replyFollowedByReplayAllIsAllowed.
@Test
public void replyFollowedByReplayAllIsAllowed() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock);
String expected = "Hello altered World";
expect(myClassMock.getMessage()).andReturn("Hello altered World");
replay(MyClass.class);
replayAll();
String actual = tested.getMessage();
verifyAll();
assertEquals("Expected and actual did not match", expected, actual);
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class StupidNewTest method testGetMessageWithArgument.
@Test
public void testGetMessageWithArgument() throws Exception {
StupidNew tested = new StupidNew();
MyClass myClassMock = createMockAndExpectNew(MyClass.class);
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 StupidNewTest method testGetMessage.
@Test
public void testGetMessage() throws Exception {
StupidNew tested = new StupidNew();
MyClass myClassMock = createMockAndExpectNew(MyClass.class);
String expected = "Hello altered World";
expect(myClassMock.getMessage()).andReturn("Hello altered World");
replay(myClassMock, MyClass.class);
String actual = tested.getMessage();
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 ExpectNewDemoUsingThePrepareEverythingAnnotationTest 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);
replayAll();
try {
Whitebox.invokeMethod(tested, "simpleMultipleNewPrivate");
verifyAll();
fail("Should throw an exception!.");
} catch (AssertionError e) {
assertEquals("\n Expectation failure on verify:" + "\n samples.newmocking.MyClass(): expected: 4, actual: 3", e.getMessage());
}
}
Aggregations