Search in sources :

Example 56 with PrepareForTest

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");
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 57 with PrepareForTest

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());
}
Also used : SuppressConstructorHierarchy(samples.suppressconstructor.SuppressConstructorHierarchy) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 58 with PrepareForTest

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();
}
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 59 with PrepareForTest

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"));
}
Also used : SimpleMix(samples.simplemix.SimpleMix) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 60 with PrepareForTest

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());
}
Also used : TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) HashMap(java.util.HashMap) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)196 Test (org.junit.Test)194 HttpServletRequest (javax.servlet.http.HttpServletRequest)30 HttpServletResponse (javax.servlet.http.HttpServletResponse)30 StringWriter (java.io.StringWriter)28 PrintWriter (java.io.PrintWriter)27 File (java.io.File)24 ArrayList (java.util.ArrayList)16 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)14 Method (java.lang.reflect.Method)13 ManagedErrorLog (com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog)12 Config (com.twitter.heron.spi.common.Config)12 Matchers.anyString (org.mockito.Matchers.anyString)12 DialogInterface (android.content.DialogInterface)11 Intent (android.content.Intent)11 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)11 Job (hudson.model.Job)11 IOException (java.io.IOException)11 Date (java.util.Date)10 HashMap (java.util.HashMap)10