@Test public void testAddRemoveObserver() { final Race observer = mock(Race.class); final GWeather weather = new GWeather(); weather.addObserver(observer); verifyZeroInteractions(observer); weather.timePasses(); assertEquals("The weather changed to rainy.", appender.getLastMessage()); verify(observer).update(weather, WeatherType.RAINY); weather.removeObserver(observer); weather.timePasses(); assertEquals("The weather changed to windy.", appender.getLastMessage()); verifyNoMoreInteractions(observer); assertEquals(2, appender.getLogSize()); }
public void timePasses() { WeatherType[] enumValues = WeatherType.values(); currentWeather = enumValues[(currentWeather.ordinal() + 1) % enumValues.length]; LOGGER.info("The weather changed to {}.", currentWeather); notifyObservers(currentWeather); }
GWeather extends Observable<GWeather, Race, WeatherType> { public void timePasses() { WeatherType[] enumValues = WeatherType.values(); currentWeather = enumValues[(currentWeather.ordinal() + 1) % enumValues.length]; LOGGER.info("The weather changed to {}.", currentWeather); notifyObservers(currentWeather); } }
GWeather extends Observable<GWeather, Race, WeatherType> { public void timePasses() { WeatherType[] enumValues = WeatherType.values(); currentWeather = enumValues[(currentWeather.ordinal() + 1) % enumValues.length]; LOGGER.info("The weather changed to {}.", currentWeather); notifyObservers(currentWeather); } GWeather(); }
GWeather extends Observable<GWeather, Race, WeatherType> { public void timePasses() { WeatherType[] enumValues = WeatherType.values(); currentWeather = enumValues[(currentWeather.ordinal() + 1) % enumValues.length]; LOGGER.info("The weather changed to {}.", currentWeather); notifyObservers(currentWeather); } GWeather(); void timePasses(); }
GWeather extends Observable<GWeather, Race, WeatherType> { public void timePasses() { WeatherType[] enumValues = WeatherType.values(); currentWeather = enumValues[(currentWeather.ordinal() + 1) % enumValues.length]; LOGGER.info("The weather changed to {}.", currentWeather); notifyObservers(currentWeather); } GWeather(); void timePasses();  }