use of samples.Service in project powermock by powermock.
the class SimplePrivateFieldServiceClassTest method testSimplePrivateFieldServiceClassTypeSafe.
@Test
public void testSimplePrivateFieldServiceClassTypeSafe() throws Exception {
SimplePrivateFieldServiceClass tested = new SimplePrivateFieldServiceClass();
Service serviceMock = createMock(Service.class);
setInternalState(tested, serviceMock);
final String expected = "Hello world!";
expect(serviceMock.getServiceMessage()).andReturn(expected);
replay(serviceMock);
final String actual = tested.useService();
verify(serviceMock);
assertEquals(expected, actual);
}
use of samples.Service in project powermock by powermock.
the class ExpectNewCases method testNewWithWrongArgument.
@Test
public void testNewWithWrongArgument() throws Exception {
final int numberOfTimes = 2;
final String expected = "used";
ExpectNewDemo tested = new ExpectNewDemo();
ExpectNewServiceUser expectNewServiceImplMock = createMock(ExpectNewServiceUser.class);
Service serviceMock = createMock(Service.class);
expectNew(ExpectNewServiceUser.class, serviceMock, numberOfTimes).andReturn(expectNewServiceImplMock);
expect(expectNewServiceImplMock.useService()).andReturn(expected);
replay(expectNewServiceImplMock, serviceMock, ExpectNewServiceUser.class);
try {
assertEquals(expected, tested.newWithWrongArguments(serviceMock, numberOfTimes));
verify(expectNewServiceImplMock, serviceMock, ExpectNewServiceUser.class);
fail("Should throw AssertionError!");
} catch (AssertionError e) {
assertEquals("\n Unexpected constructor call samples.expectnew.ExpectNewServiceUser(EasyMock for interface samples.Service, 4):" + "\n samples.expectnew.ExpectNewServiceUser(EasyMock for interface samples.Service, 2): expected: 1, actual: 0", e.getMessage());
}
}
Aggregations