jmxSensor.update(CoreService.this);
@Test public void jmxSensor() { when(platformSensors.isEmpty()).thenReturn(true); doReturn(new ArrayIterator(new IJmxSensor[] { jmxSensor })).when(jmxSensors).iterator(); Runnable sensorRefresher = coreService.new SensorRefresher(); sensorRefresher.run(); verify(jmxSensor).update(coreService); verifyNoMoreInteractions(jmxSensor); }
@Test public void jmxSensorTwice() { when(platformSensors.isEmpty()).thenReturn(true); doAnswer(new Answer<Iterator<?>>() { @Override public Iterator<?> answer(InvocationOnMock invocation) throws Throwable { return new ArrayIterator(new IJmxSensor[] { jmxSensor }); } }).when(jmxSensors).iterator(); Runnable sensorRefresher = coreService.new SensorRefresher(); sensorRefresher.run(); sensorRefresher.run(); verify(jmxSensor, times(2)).update(coreService); verifyNoMoreInteractions(jmxSensor); }