Search in sources :

Example 41 with PrepareForTest

use of org.powermock.core.classloader.annotations.PrepareForTest in project apache-kafka-on-k8s by banzaicloud.

the class BufferPoolTest method testCleanupMemoryAvailabilityOnMetricsException.

@PrepareForTest({ Sensor.class, MetricName.class })
@Test
public void testCleanupMemoryAvailabilityOnMetricsException() throws Exception {
    Metrics mockedMetrics = createNiceMock(Metrics.class);
    Sensor mockedSensor = createNiceMock(Sensor.class);
    MetricName metricName = createNiceMock(MetricName.class);
    MetricName rateMetricName = createNiceMock(MetricName.class);
    MetricName totalMetricName = createNiceMock(MetricName.class);
    expect(mockedMetrics.sensor(BufferPool.WAIT_TIME_SENSOR_NAME)).andReturn(mockedSensor);
    mockedSensor.record(anyDouble(), anyLong());
    expectLastCall().andThrow(new OutOfMemoryError());
    expect(mockedMetrics.metricName(anyString(), eq(metricGroup), anyString())).andReturn(metricName);
    expect(mockedSensor.add(new Meter(TimeUnit.NANOSECONDS, rateMetricName, totalMetricName))).andReturn(true);
    replay(mockedMetrics, mockedSensor, metricName);
    BufferPool bufferPool = new BufferPool(2, 1, mockedMetrics, time, metricGroup);
    bufferPool.allocate(1, 0);
    try {
        bufferPool.allocate(2, 1000);
        assertTrue("Expected oom.", false);
    } catch (OutOfMemoryError expected) {
    }
    assertEquals(1, bufferPool.availableMemory());
    assertEquals(0, bufferPool.queued());
    // This shouldn't timeout
    bufferPool.allocate(1, 0);
}
Also used : MetricName(org.apache.kafka.common.MetricName) Metrics(org.apache.kafka.common.metrics.Metrics) Meter(org.apache.kafka.common.metrics.stats.Meter) Sensor(org.apache.kafka.common.metrics.Sensor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 42 with PrepareForTest

use of org.powermock.core.classloader.annotations.PrepareForTest in project incubator-weex by apache.

the class WXImageTest method testInitComponentHostView.

@Test
@PrepareForTest(WXImageView.class)
public void testInitComponentHostView() throws Exception {
    ImageView imageView = mWXImage.initComponentHostView(Robolectric.setupActivity(TestActivity.class));
    assertEquals(imageView.getClass(), WXImageView.class);
}
Also used : TestActivity(com.taobao.weex.TestActivity) ImageView(android.widget.ImageView) WXImageView(com.taobao.weex.ui.view.WXImageView) WXSDKInstanceTest(com.taobao.weex.WXSDKInstanceTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 43 with PrepareForTest

use of org.powermock.core.classloader.annotations.PrepareForTest in project motech by motech.

the class BootstrapManagerTest method shouldLoadPropertiesInTheCorrectOrder.

@PrepareForTest(ConfigPropertiesUtils.class)
@Test
public void shouldLoadPropertiesInTheCorrectOrder() throws IOException {
    PowerMockito.mockStatic(ConfigPropertiesUtils.class);
    Iterable<ConfigLocation> configLocations = new ArrayList<ConfigLocation>();
    Properties properties = createProperties();
    properties.put(SQL_URL, "");
    when(environment.getConfigDir()).thenReturn(null);
    when(environment.getBootstrapProperties()).thenReturn(properties);
    when(configLocationFileStore.getAll()).thenReturn(configLocations);
    when(ConfigPropertiesUtils.getDefaultPropertiesFile(ConfigLocation.FileAccessType.READABLE, configLocations, BootstrapManager.BOOTSTRAP_PROPERTIES)).thenThrow(new MotechConfigurationException("Error loading file from config locations"));
    try {
        bootstrapManager.loadBootstrapConfig();
    } catch (MotechConfigurationException e) {
    // Ignore error because invocation order is to be verified.
    }
    InOrder inOrder = Mockito.inOrder(environment, configLocationFileStore);
    inOrder.verify(environment).getConfigDir();
    inOrder.verify(environment).getBootstrapProperties();
    inOrder.verify(configLocationFileStore).getAll();
}
Also used : InOrder(org.mockito.InOrder) ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) ArrayList(java.util.ArrayList) MotechConfigurationException(org.motechproject.config.core.exception.MotechConfigurationException) Properties(java.util.Properties) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 44 with PrepareForTest

use of org.powermock.core.classloader.annotations.PrepareForTest in project motech by motech.

the class BootstrapManagerTest method shouldReturnBootstrapConfigFromFileSpecifiedInTheEnvironmentVariable.

@PrepareForTest(ConfigPropertiesUtils.class)
@Test
public void shouldReturnBootstrapConfigFromFileSpecifiedInTheEnvironmentVariable() throws IOException {
    PowerMockito.mockStatic(ConfigPropertiesUtils.class);
    when(environment.getConfigDir()).thenReturn(bootstrapFileLocation);
    Properties properties = createProperties();
    when(ConfigPropertiesUtils.getPropertiesFromFile(new File(bootstrapFile))).thenReturn(properties);
    BootstrapConfig expectedBootstrapConfig = new BootstrapConfig(new SQLDBConfig(sqlUrl, sqlDriver, sqlUsername, sqlPassword), ConfigSource.FILE, null, null, queueUrl);
    assertThat(bootstrapManager.loadBootstrapConfig(), equalTo(expectedBootstrapConfig));
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) Properties(java.util.Properties) File(java.io.File) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 45 with PrepareForTest

use of org.powermock.core.classloader.annotations.PrepareForTest in project motech by motech.

the class BootstrapManagerTest method shouldThrowExceptionIfConfigFileReaderCanNotReadFileSpecifiedInEnvironmentVariable.

@PrepareForTest(ConfigPropertiesUtils.class)
@Test(expected = MotechConfigurationException.class)
public void shouldThrowExceptionIfConfigFileReaderCanNotReadFileSpecifiedInEnvironmentVariable() throws IOException {
    PowerMockito.mockStatic(ConfigPropertiesUtils.class);
    when(environment.getConfigDir()).thenReturn(bootstrapFileLocation);
    when(ConfigPropertiesUtils.getPropertiesFromFile(new File(bootstrapFile))).thenThrow(new IOException());
    bootstrapManager.loadBootstrapConfig();
}
Also used : IOException(java.io.IOException) File(java.io.File) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)188 Test (org.junit.Test)186 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)21 ArrayList (java.util.ArrayList)15 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)14 Method (java.lang.reflect.Method)13 Config (com.twitter.heron.spi.common.Config)12 DialogInterface (android.content.DialogInterface)11 Intent (android.content.Intent)11 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)11 Job (hudson.model.Job)11 Point (org.pentaho.di.core.gui.Point)10 Date (java.util.Date)9 HashMap (java.util.HashMap)9 Matchers.anyString (org.mockito.Matchers.anyString)9 InvocationOnMock (org.mockito.invocation.InvocationOnMock)9