use of org.powermock.core.classloader.annotations.PrepareForTest in project qpp-conversion-tool by CMSgov.
the class ConversionFileWriterWrapperTest method testFailureToWriteQpp.
@Test
@PrepareForTest({ Files.class, ConversionFileWriterWrapper.class })
public void testFailureToWriteQpp() throws IOException {
PowerMockito.mockStatic(Files.class);
PowerMockito.when(Files.newBufferedWriter(ArgumentMatchers.any(Path.class))).thenThrow(new IOException());
Path path = Paths.get("../qrda-files/valid-QRDA-III-latest.xml");
ConversionFileWriterWrapper converterWrapper = new ConversionFileWriterWrapper(path);
converterWrapper.transform();
assertFileDoesNotExists("valid-QRDA-III-latest.qpp.json");
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project powermock by powermock.
the class SuppressConstructorHierarchyDemoTest method testSuppressConstructorHierarchyAgain.
/**
* This simple test demonstrate that it's possible to continue execution
* with the default {@code PrepareForTest} settings (i.e. using a
* byte-code manipulated version of the SuppressConstructorHierarchyDemo
* class).
*/
@Test
public void testSuppressConstructorHierarchyAgain() throws Exception {
suppress(constructor(SuppressConstructorHierarchy.class));
SuppressConstructorHierarchy tested = new SuppressConstructorHierarchy("message");
assertEquals(42, tested.getNumber());
}
use of org.powermock.core.classloader.annotations.PrepareForTest 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.class);
SimpleMixUtilities.getRandomInteger();
verifyNew(SimpleMixConstruction.class).withNoArguments();
verifyPrivate(tested).invoke(method(SimpleMix.class, "getValue")).withNoArguments();
}
use of org.powermock.core.classloader.annotations.PrepareForTest 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"));
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project heron by twitter.
the class HeronSubmitterTest method testTopologySubmissionWhenTmpDirectoryIsSetAsInvalidPath.
@Test(expected = TopologySubmissionException.class)
@PrepareForTest(HeronSubmitter.class)
public void testTopologySubmissionWhenTmpDirectoryIsSetAsInvalidPath() throws AlreadyAliveException, InvalidTopologyException {
TopologyBuilder builder = createTopologyBuilderWithMinimumSetup();
Config conf = new Config();
Map<String, String> map = new HashMap();
map.put("cmdline.topologydefn.tmpdirectory", "invalid_path");
PowerMockito.spy(HeronSubmitter.class);
Mockito.when(HeronSubmitter.getHeronCmdOptions()).thenReturn(map);
HeronSubmitter.submitTopology("test", conf, builder.createTopology());
}
Aggregations