Search in sources :

Example 1 with SimpleMixCollaborator

use of samples.simplemix.SimpleMixCollaborator in project powermock by powermock.

the class SimpleMixTest method staticPartialFinalMocking.

@PrepareForTest({ SimpleMixUtilities.class, SimpleMixCollaborator.class, SimpleMix.class })
@Test
public void staticPartialFinalMocking() throws Exception {
    SimpleMix tested = spy(new SimpleMix());
    when(tested, "getValue").thenReturn(0);
    SimpleMixCollaborator simpleMixCollaboratorMock = mock(SimpleMixCollaborator.class);
    mockStatic(SimpleMixUtilities.class);
    SimpleMixConstruction simpleMixConstructionMock = mock(SimpleMixConstruction.class);
    Whitebox.setInternalState(tested, simpleMixCollaboratorMock);
    when(SimpleMixUtilities.getRandomInteger()).thenReturn(10);
    when(simpleMixCollaboratorMock.getRandomInteger()).thenReturn(6);
    whenNew(SimpleMixConstruction.class).withNoArguments().thenReturn(simpleMixConstructionMock);
    when(simpleMixConstructionMock.getMyValue()).thenReturn(1);
    assertEquals(4, tested.calculate());
    verifyStatic();
    SimpleMixUtilities.getRandomInteger();
    verifyNew(SimpleMixConstruction.class).withNoArguments();
    verifyPrivate(tested).invoke(method(SimpleMix.class, "getValue"));
}
Also used : SimpleMixCollaborator(samples.simplemix.SimpleMixCollaborator) SimpleMix(samples.simplemix.SimpleMix) SimpleMixConstruction(samples.simplemix.SimpleMixConstruction) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 SimpleMix (samples.simplemix.SimpleMix)1 SimpleMixCollaborator (samples.simplemix.SimpleMixCollaborator)1 SimpleMixConstruction (samples.simplemix.SimpleMixConstruction)1