Search in sources :

Example 11 with ExpectNewServiceUser

use of samples.expectnew.ExpectNewServiceUser in project powermock by powermock.

the class ReplayAllForExpectNewTest method testReplayAllWithAdditionalMocks.

@Test
public void testReplayAllWithAdditionalMocks() throws Exception {
    final int numberOfTimes = 2;
    final String expected = "used";
    ExpectNewDemo tested = new ExpectNewDemo();
    ExpectNewServiceUser expectNewServiceImplMock = EasyMock.createMock(ExpectNewServiceUser.class);
    Service serviceMock = createMock(Service.class);
    expectNew(ExpectNewServiceUser.class, serviceMock, numberOfTimes).andReturn(expectNewServiceImplMock);
    expect(expectNewServiceImplMock.useService()).andReturn(expected);
    replayAll(expectNewServiceImplMock);
    assertEquals(expected, tested.newWithArguments(serviceMock, numberOfTimes));
    verifyAll();
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) ExpectNewServiceUser(samples.expectnew.ExpectNewServiceUser) Service(samples.Service) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with ExpectNewServiceUser

use of samples.expectnew.ExpectNewServiceUser in project powermock by powermock.

the class ExpectNewDemoUsingThePrepareEverythingAnnotationTest 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);
    replayAll();
    try {
        assertEquals(expected, tested.newWithWrongArguments(serviceMock, numberOfTimes));
        verifyAll();
        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());
    }
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) ExpectNewServiceUser(samples.expectnew.ExpectNewServiceUser) Service(samples.Service) Test(org.junit.Test) PrepareEverythingForTest(org.powermock.core.classloader.annotations.PrepareEverythingForTest)

Example 13 with ExpectNewServiceUser

use of samples.expectnew.ExpectNewServiceUser 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());
    }
}
Also used : ExpectNewDemo(samples.expectnew.ExpectNewDemo) ExpectNewServiceUser(samples.expectnew.ExpectNewServiceUser) Service(samples.Service) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)13 Service (samples.Service)13 ExpectNewDemo (samples.expectnew.ExpectNewDemo)13 ExpectNewServiceUser (samples.expectnew.ExpectNewServiceUser)13 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 PrepareEverythingForTest (org.powermock.core.classloader.annotations.PrepareEverythingForTest)2