Weather { public void timePasses() { WeatherType[] enumValues = WeatherType.values(); currentWeather = enumValues[(currentWeather.ordinal() + 1) % enumValues.length]; LOGGER.info("The weather changed to {}.", currentWeather); notifyObservers(); } Weather(); void addObserver(WeatherObserver obs); void removeObserver(WeatherObserver obs); void timePasses();  }
@Test public void testTimePasses() { final WeatherObserver observer = mock(WeatherObserver.class); final Weather weather = new Weather(); weather.addObserver(observer); final InOrder inOrder = inOrder(observer); final WeatherType[] weatherTypes = WeatherType.values(); for (int i = 1; i < 20; i++) { weather.timePasses(); inOrder.verify(observer).update(weatherTypes[i % weatherTypes.length]); } verifyNoMoreInteractions(observer); }