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