use of samples.newmocking.MyClass in project powermock by powermock.
the class WhenNewCases method testSimpleMultipleNew_tooFewTimesExpected.
@Test
public void testSimpleMultipleNew_tooFewTimesExpected() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = mock(MyClass.class);
whenNew(MyClass.class).withNoArguments().thenReturn(myClassMock1);
tested.simpleMultipleNew();
try {
verifyNew(MyClass.class, times(1)).withNoArguments();
fail("Should throw AssertionError.");
} catch (AssertionError e) {
assertEquals("samples.newmocking.MyClass();\nWanted 1 time but was 3 times.", e.getMessage());
}
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ReplayAllForExpectNewTest method testGetMessage.
@Test
public void testGetMessage() 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");
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 ResetMockTest method assertManualResetWorksWhenMixingInstanceAndClassMocks.
@Test
public void assertManualResetWorksWhenMixingInstanceAndClassMocks() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock);
expect(myClassMock.getMessage()).andReturn("message");
replayAll();
String message = tested.getMessage();
verifyAll();
assertEquals("message", message);
reset(myClassMock, MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock);
expect(myClassMock.getMessage()).andReturn("message");
replayAll();
message = tested.getMessage();
verifyAll();
assertEquals("message", message);
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ResetMockTest method assertResetAllWorks.
@Test
public void assertResetAllWorks() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock);
expect(myClassMock.getMessage()).andReturn("message");
replayAll();
String message = tested.getMessage();
verifyAll();
assertEquals("message", message);
resetAll();
expectNew(MyClass.class).andReturn(myClassMock);
expect(myClassMock.getMessage()).andReturn("message");
replayAll();
message = tested.getMessage();
verifyAll();
assertEquals("message", message);
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testSimpleSingleNew_withOnce.
@Test
public void testSimpleSingleNew_withOnce() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).once();
replayAll();
tested.simpleSingleNew();
verifyAll();
}
Aggregations