use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewDemoTest 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");
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 ExpectNewDemoTest 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();
replay(myClassMock1, MyClass.class);
tested.simpleSingleNew();
verify(myClassMock1, MyClass.class);
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewDemoTest method testSimpleMultipleNewPrivate_ok.
@Test
public void testSimpleMultipleNewPrivate_ok() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).times(3);
replay(myClassMock1, MyClass.class);
Whitebox.invokeMethod(tested, "simpleMultipleNewPrivate");
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class WhenNewCases method testSimpleSingleNew_withOnce.
@Test
public void testSimpleSingleNew_withOnce() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = mock(MyClass.class);
whenNew(MyClass.class).withNoArguments().thenReturn(myClassMock1);
tested.simpleSingleNew();
verifyNew(MyClass.class).withNoArguments();
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class WhenNewCases method testSimpleMultipleNew.
@Test
public void testSimpleMultipleNew() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock = mock(MyClass.class);
whenNew(MyClass.class).withNoArguments().thenReturn(myClassMock);
tested.simpleMultipleNew();
verifyNew(MyClass.class, times(3)).withNoArguments();
}
Aggregations