Search in sources :

Example 1 with ExpectNewWithMultipleCtorDemo

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");
}
Also used : ExpectNewWithMultipleCtorDemo(samples.expectnew.ExpectNewWithMultipleCtorDemo) Service(samples.Service) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Service (samples.Service)1 ExpectNewWithMultipleCtorDemo (samples.expectnew.ExpectNewWithMultipleCtorDemo)1