use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewCases 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);
replay(myClassMock, MyClass.class);
tested.invokeVoidMethod();
verify(myClassMock, MyClass.class);
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewCases method testPreviousProblemsWithByteCodeManipulation.
@Test
public void testPreviousProblemsWithByteCodeManipulation() throws Exception {
MyClass myClassMock1 = createMock(MyClass.class);
expect(myClassMock1.getMessage()).andReturn("Hello");
expect(myClassMock1.getMessage()).andReturn("World");
replay(myClassMock1);
assertEquals("Hello", myClassMock1.getMessage());
assertEquals("World", myClassMock1.getMessage());
verify(myClassMock1);
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewCases 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);
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: between 5 and 7, actual: 3", e.getMessage());
}
}
Aggregations