use of samples.Service in project powermock by powermock.
the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest method testNewWithArguments.
@Test
public void testNewWithArguments() 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);
replayAll();
assertEquals(expected, tested.newWithArguments(serviceMock, numberOfTimes));
verifyAll();
}
use of samples.Service in project powermock by powermock.
the class WhenNewCases method whenNewAnyArgumentsWorksInClassesWithMultipleCtors.
@Test
public void whenNewAnyArgumentsWorksInClassesWithMultipleCtors() throws Exception {
ExpectNewWithMultipleCtorDemo expectNewWithMultipleCtorDemoMock = mock(ExpectNewWithMultipleCtorDemo.class);
Service serviceMock = mock(Service.class);
whenNew(ExpectNewWithMultipleCtorDemo.class).withAnyArguments().thenReturn(expectNewWithMultipleCtorDemoMock);
when(expectNewWithMultipleCtorDemoMock.useService()).thenReturn("message");
// When
final ExpectNewWithMultipleCtorDemo expectNewWithMultipleCtorDemo = new ExpectNewWithMultipleCtorDemo(serviceMock);
final String message1 = expectNewWithMultipleCtorDemo.useService();
final ExpectNewWithMultipleCtorDemo expectNewWithMultipleCtorDemo1 = new ExpectNewWithMultipleCtorDemo(serviceMock, 5);
final String message2 = expectNewWithMultipleCtorDemo1.useService();
assertEquals(message1, "message");
assertEquals(message2, "message");
}
use of samples.Service in project powermock by powermock.
the class WhenNewCases method testNewWithArguments.
@Test
public void testNewWithArguments() throws Exception {
final int numberOfTimes = 2;
final String expected = "used";
ExpectNewDemo tested = new ExpectNewDemo();
ExpectNewServiceUser expectNewServiceImplMock = mock(ExpectNewServiceUser.class);
Service serviceMock = mock(Service.class);
whenNew(ExpectNewServiceUser.class).withArguments(serviceMock, numberOfTimes).thenReturn(expectNewServiceImplMock);
when(expectNewServiceImplMock.useService()).thenReturn(expected);
assertEquals(expected, tested.newWithArguments(serviceMock, numberOfTimes));
verifyNew(ExpectNewServiceUser.class).withArguments(serviceMock, numberOfTimes);
}
use of samples.Service in project powermock by powermock.
the class WhenNewCases method testNewUsingConstructorWithArguments.
@Test
public void testNewUsingConstructorWithArguments() throws Exception {
final int numberOfTimes = 2;
final String expected = "used";
ExpectNewDemo tested = new ExpectNewDemo();
ExpectNewServiceUser expectNewServiceImplMock = mock(ExpectNewServiceUser.class);
Service serviceMock = mock(Service.class);
whenNew(constructor(ExpectNewServiceUser.class)).withArguments(serviceMock, numberOfTimes).thenReturn(expectNewServiceImplMock);
when(expectNewServiceImplMock.useService()).thenReturn(expected);
assertEquals(expected, tested.newWithArguments(serviceMock, numberOfTimes));
verifyNew(ExpectNewServiceUser.class).withArguments(serviceMock, numberOfTimes);
}
use of samples.Service in project powermock by powermock.
the class WhenNewCases method testNewWithParameterTypesAndArguments.
@Test
public void testNewWithParameterTypesAndArguments() throws Exception {
final int numberOfTimes = 2;
final String expected = "used";
ExpectNewDemo tested = new ExpectNewDemo();
ExpectNewServiceUser expectNewServiceImplMock = mock(ExpectNewServiceUser.class);
Service serviceMock = mock(Service.class);
whenNew(ExpectNewServiceUser.class).withParameterTypes(Service.class, int.class).withArguments(serviceMock, numberOfTimes).thenReturn(expectNewServiceImplMock);
when(expectNewServiceImplMock.useService()).thenReturn(expected);
assertEquals(expected, tested.newWithArguments(serviceMock, numberOfTimes));
verifyNew(ExpectNewServiceUser.class).withArguments(serviceMock, numberOfTimes);
}
Aggregations