use of samples.expectnew.ExpectNewWithMultipleCtorDemo 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");
}
Aggregations