Search in sources :

Example 1 with MockSelfPrivateFieldServiceClass

use of samples.privatefield.MockSelfPrivateFieldServiceClass in project powermock by powermock.

the class MockSelfPrivateFieldServiceClassTest method testGetCompositeMessage.

@Test
public void testGetCompositeMessage() throws Exception {
    MockSelfPrivateFieldServiceClass tested = createPartialMock(MockSelfPrivateFieldServiceClass.class, "getOwnMessage");
    Service serviceMock = createMock(Service.class);
    setInternalState(tested, "service", serviceMock, MockSelfPrivateFieldServiceClass.class);
    final String expected = "Hello world";
    expectPrivate(tested, "getOwnMessage").andReturn("Hello");
    expect(serviceMock.getServiceMessage()).andReturn(" world");
    replay(serviceMock);
    replay(tested);
    final String actual = tested.getCompositeMessage();
    verify(serviceMock);
    verify(tested);
    assertEquals(expected, actual);
}
Also used : MockSelfPrivateFieldServiceClass(samples.privatefield.MockSelfPrivateFieldServiceClass) 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 MockSelfPrivateFieldServiceClass (samples.privatefield.MockSelfPrivateFieldServiceClass)1