Java Code Examples for org.powermock.reflect.Whitebox#newInstance()

The following examples show how to use org.powermock.reflect.Whitebox#newInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CloudNannyTest.java    From ec2-spot-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
private CloudNanny getMockCloudNannyInstance() {
    CloudNanny cloudNanny = Whitebox.newInstance(CloudNanny.class);

    // next execution should trigger running the status check.
    recurrenceCounter1.set(1);
    recurrenceCounter2.set(1);

    Whitebox.setInternalState(cloudNanny, "recurrenceCounters", recurrenceCounters);

    return cloudNanny;
}
 
Example 2
Source File: DelegateClassWithFloatTest.java    From unmock-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testCallFloat() throws Exception {
    Sensor sensor = Whitebox.newInstance(Sensor.class);

    mockStatic(ABridge.class);
    when(ABridge.callFloat(eq("android.hardware.Sensor.getPower()"), any(Object.class), any(Object[].class))).thenReturn(42f);

    assertEquals(42f, sensor.getPower(), 0f);
}
 
Example 3
Source File: EmbeddedLinuxJVMDebuggerTest.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 5 votes vote down vote up
@Test
public void testCanRun() {
    RunProfile profile = Mockito.mock(EmbeddedLinuxJVMRunConfiguration.class);

    EmbeddedLinuxJVMDebugger debugger = Whitebox.newInstance(EmbeddedLinuxJVMDebugger.class);
    boolean canRun = debugger.canRun("Debug", profile);
    assertTrue(canRun);

    RunProfile wrongProfile = Mockito.mock(RunProfile.class);
    boolean cannotRun = debugger.canRun("Debug", wrongProfile);
    assertFalse(cannotRun);
}
 
Example 4
Source File: EmbeddedLinuxJVMRunnerTest.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 5 votes vote down vote up
@Test
public void testCanRun() {
    RunProfile profile = Mockito.mock(EmbeddedLinuxJVMRunConfiguration.class);

    EmbeddedLinuxJVMRunner runner = Whitebox.newInstance(EmbeddedLinuxJVMRunner.class);
    boolean canRun = runner.canRun("Run", profile);
    assertTrue(canRun);

    boolean cannotRun = runner.canRun("Debug", profile);
    assertFalse(cannotRun);

    RunProfile wrongProfile = Mockito.mock(RunProfile.class);
    boolean cannotRun2 = runner.canRun("Run", wrongProfile);
    assertFalse(cannotRun2);
}
 
Example 5
Source File: AccumuloConnectionFactoryTest.java    From datawave with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() throws Exception {
    
    MyAccumuloConnectionPoolFactory warehouseFactory = Whitebox.newInstance(MyAccumuloConnectionPoolFactory.class);
    Whitebox.setInternalState(warehouseFactory, "username", "root");
    Whitebox.setInternalState(warehouseFactory, "password", "");
    MyAccumuloConnectionPoolFactory metricsFactory = Whitebox.newInstance(MyAccumuloConnectionPoolFactory.class);
    Whitebox.setInternalState(metricsFactory, "username", "root");
    Whitebox.setInternalState(metricsFactory, "password", "");
    warehouseFactory.setConnector(warehouseConnection);
    metricsFactory.setConnector(metricsConnection);
    
    Map<String,ConnectionPoolConfiguration> configs = new HashMap<>();
    configs.put("WAREHOUSE", null);
    configs.put("METRICS", null);
    ConnectionPoolsConfiguration conf = new ConnectionPoolsConfiguration();
    Whitebox.setInternalState(conf, "defaultPool", "WAREHOUSE");
    Whitebox.setInternalState(conf, "poolNames", Lists.newArrayList("WAREHOUSE", "METRICS"));
    Whitebox.setInternalState(conf, "pools", configs);
    
    String defaultPoolName = conf.getDefaultPool();
    HashMap<String,Map<Priority,AccumuloConnectionPool>> pools = new HashMap<>();
    MyAccumuloConnectionPool warehousePool = new MyAccumuloConnectionPool(warehouseFactory);
    MyAccumuloConnectionPool metricsPool = new MyAccumuloConnectionPool(metricsFactory);
    for (Entry<String,ConnectionPoolConfiguration> entry : conf.getPools().entrySet()) {
        AccumuloConnectionPool acp = null;
        switch (entry.getKey()) {
            case "METRICS":
                acp = metricsPool;
                break;
            case "WAREHOUSE":
                acp = warehousePool;
                break;
            default:
                fail("Unknown pool name " + entry.getKey());
        }
        Map<Priority,AccumuloConnectionPool> p = new HashMap<>();
        p.put(Priority.ADMIN, acp);
        p.put(Priority.HIGH, acp);
        p.put(Priority.NORMAL, acp);
        p.put(Priority.LOW, acp);
        pools.put(entry.getKey(), Collections.unmodifiableMap(p));
    }
    Whitebox.setInternalState(bean, ConnectionPoolsConfiguration.class, conf);
    Whitebox.setInternalState(bean, "defaultPoolName", defaultPoolName);
    Whitebox.setInternalState(bean, "pools", pools);
}
 
Example 6
Source File: ExampleWithEvilConstructorTest.java    From powermock-examples-maven with Apache License 2.0 4 votes vote down vote up
@Test
public void testSuppressOwnConstructor() throws Exception {
	ExampleWithEvilConstructor tested = Whitebox.newInstance(ExampleWithEvilConstructor.class);
	assertNull(tested.getMessage());
}
 
Example 7
Source File: EmbeddedLinuxJVMDebuggerTest.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetRunnerId() {
    EmbeddedLinuxJVMDebugger debugger = Whitebox.newInstance(EmbeddedLinuxJVMDebugger.class);
    String runnerId = debugger.getRunnerId();
    assertEquals("RaspberryPIDebugger", runnerId);
}
 
Example 8
Source File: EmbeddedLinuxJVMRunnerTest.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetRunnerId() {
    EmbeddedLinuxJVMRunner debugger = Whitebox.newInstance(EmbeddedLinuxJVMRunner.class);
    String runnerId = debugger.getRunnerId();
    assertEquals("RaspberryPIRunner", runnerId);
}
 
Example 9
Source File: DeepSparkContextTest.java    From deep-spark with Apache License 2.0 4 votes vote down vote up
private DeepSparkContext createDeepSparkContext() {
    PowerMockito.suppress(PowerMockito.constructor(DeepSparkContext.class, SparkContext.class));
    return Whitebox.newInstance(DeepSparkContext.class);
}