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"));
}
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"));
}
Aggregations