Search in sources :

Example 1 with SimpleMix

use of samples.simplemix.SimpleMix 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)

Example 2 with SimpleMix

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

the class SimpleMixTest method finalSystemClassMocking.

@PrepareForTest({ SimpleMix.class })
@Test
public void finalSystemClassMocking() throws Exception {
    SimpleMix tested = new SimpleMix();
    mockStatic(System.class);
    when(System.currentTimeMillis()).thenReturn(2000L);
    assertEquals(2, Whitebox.invokeMethod(tested, "getValue"));
}
Also used : SimpleMix(samples.simplemix.SimpleMix) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

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