### Question:
DeviceOfflineGenerator extends AlertGenerator { @Override protected void handleMessage(SubsystemContext<PlaceMonitorSubsystemModel> context, AlertScratchPad scratch, PlatformMessage msg, Model m) { switch(msg.getMessageType()) { case PlaceMonitorSubsystemCapability.DeviceOfflineEvent.NAME: scratch.putAlert(SmartHomeAlerts.create( SmartHomeAlert.ALERTTYPE_DEV_ERR_OFFLINE, SmartHomeAlert.SEVERITY_CRITICAL, PlaceMonitorSubsystemCapability.DeviceOfflineEvent.getDeviceAddress(msg.getValue()), SmartHomeAlerts.baseDeviceAttribues(m, prodCat), context.getPlaceId() )); break; case PlaceMonitorSubsystemCapability.DeviceOnlineEvent.NAME: scratch.removeAlert(AlertKeys.key(SmartHomeAlert.ALERTTYPE_DEV_ERR_OFFLINE, PlaceMonitorSubsystemCapability.DeviceOnlineEvent.getDeviceAddress(msg.getValue()))); scratch.removeAlert(AlertKeys.key(SmartHomeAlert.ALERTTYPE_DEV_ERR_OFFLINE_BATTERY, PlaceMonitorSubsystemCapability.DeviceOnlineEvent.getDeviceAddress(msg.getValue()))); break; default: break; } } @Inject  DeviceOfflineGenerator(ProductCatalogManager prodCat);   }### Answer:
@Test public void testDeviceOfflineAddsAlert() { replay(); MessageBody body = PlaceMonitorSubsystemCapability.DeviceOfflineEvent.builder() .withDeviceAddress(lock.getAddress().getRepresentation()) .withLastOnlineTime(new Date()) .build(); PlatformMessage msg = PlatformMessage.buildBroadcast(body, Address.platformService(PLACE_ID, PlaceMonitorSubsystemCapability.NAMESPACE)) .withPlaceId(PLACE_ID) .create(); generator.handleMessage(context, scratchPad, msg, lock); String key = AlertKeys.key(SmartHomeAlert.ALERTTYPE_DEV_ERR_OFFLINE, lock.getAddress()); assertScratchPadHasAlert(key); SmartHomeAlert expected = createAlert(); assertAlert(expected, scratchPad.getAlert(key)); }
@Test public void testDeviceOnlineClearsAlert() { replay(); MessageBody body = PlaceMonitorSubsystemCapability.DeviceOnlineEvent.builder() .withDeviceAddress(lock.getAddress().getRepresentation()) .withOnlineTime(new Date()) .build(); PlatformMessage msg = PlatformMessage.buildBroadcast(body, Address.platformService(PLACE_ID, PlaceMonitorSubsystemCapability.NAMESPACE)) .withPlaceId(PLACE_ID) .create(); scratchPad.putAlert(createAlert()); generator.handleMessage(context, scratchPad, msg, lock); String key = AlertKeys.key(SmartHomeAlert.ALERTTYPE_DEV_ERR_OFFLINE, lock.getAddress()); assertScratchPadNoAlert(key); }
@Test public void testDeviceOnlineClearsLowBatteryOfflineAlert() { replay(); MessageBody body = PlaceMonitorSubsystemCapability.DeviceOnlineEvent.builder() .withDeviceAddress(lock.getAddress().getRepresentation()) .withOnlineTime(new Date()) .build(); PlatformMessage msg = PlatformMessage.buildBroadcast(body, Address.platformService(PLACE_ID, PlaceMonitorSubsystemCapability.NAMESPACE)) .withPlaceId(PLACE_ID) .create(); scratchPad.putAlert(createBatteryLowOfflineAlert()); generator.handleMessage(context, scratchPad, msg, lock); String key = AlertKeys.key(SmartHomeAlert.ALERTTYPE_DEV_ERR_OFFLINE_BATTERY, lock.getAddress()); assertScratchPadNoAlert(key); }