use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewCases 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 ExpectNewCases method testSimpleMultipleNew_anyTimes.
@Test
public void testSimpleMultipleNew_anyTimes() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).anyTimes();
replay(myClassMock1, MyClass.class);
tested.simpleMultipleNew();
verify(myClassMock1, MyClass.class);
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewCases 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 ExpectNewCases method testSimpleMultipleNew_withRange_OK.
@Test
public void testSimpleMultipleNew_withRange_OK() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1).times(1, 5);
replay(myClassMock1, MyClass.class);
tested.simpleMultipleNew();
verify(myClassMock1, MyClass.class);
}
use of samples.newmocking.MyClass in project powermock by powermock.
the class ExpectNewCases method testMultipleNew.
@Test
public void testMultipleNew() throws Exception {
ExpectNewDemo tested = new ExpectNewDemo();
MyClass myClassMock1 = createMock(MyClass.class);
MyClass myClassMock2 = createMock(MyClass.class);
expectNew(MyClass.class).andReturn(myClassMock1);
expectNew(MyClass.class).andReturn(myClassMock2);
expect(myClassMock1.getMessage()).andReturn("Hello ");
expect(myClassMock2.getMessage()).andReturn("World");
replay(myClassMock1, myClassMock2, MyClass.class);
final String actual = tested.multipleNew();
verify(myClassMock1, myClassMock2, MyClass.class);
assertEquals("Hello World", actual);
}
Aggregations