### Question:
HubOfflineGenerator extends AlertGenerator { @Override protected void handleMessage(SubsystemContext<PlaceMonitorSubsystemModel> context, AlertScratchPad scratch, PlatformMessage msg, Model m) { switch(msg.getMessageType()) { case PlaceMonitorSubsystemCapability.HubOfflineEvent.NAME: scratch.putAlert(SmartHomeAlerts.create( SmartHomeAlert.ALERTTYPE_PLACE_HUB_OFFLINE, SmartHomeAlert.SEVERITY_BLOCK, Address.platformService(context.getPlaceId(), PlaceCapability.NAMESPACE), generateAttributes(m), context.getPlaceId() )); break; case PlaceMonitorSubsystemCapability.HubOnlineEvent.NAME: case HubCapability.HubConnectedEvent.NAME: scratch.removeAlert(AlertKeys.key(SmartHomeAlert.ALERTTYPE_PLACE_HUB_OFFLINE, context.getPlaceId())); break; default: break; } }    }### Answer:
@Test public void testHubOfflineAddsAlert() { replay(); MessageBody body = PlaceMonitorSubsystemCapability.HubOfflineEvent.builder() .withHubAddress(hub.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, hub); String key = AlertKeys.key(SmartHomeAlert.ALERTTYPE_PLACE_HUB_OFFLINE, Address.platformService(PLACE_ID, PlaceCapability.NAMESPACE)); assertScratchPadHasAlert(key); SmartHomeAlert expected = createAlert(); assertAlert(expected, scratchPad.getAlert(key)); }
@Test public void testHubOnlineClearsAlert() { replay(); MessageBody body = PlaceMonitorSubsystemCapability.HubOnlineEvent.builder() .withHubAddress(hub.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, hub); String key = AlertKeys.key(SmartHomeAlert.ALERTTYPE_PLACE_HUB_OFFLINE, Address.platformService(PLACE_ID, PlaceCapability.NAMESPACE)); assertScratchPadNoAlert(key); }
@Test public void testHubConnected() { replay(); MessageBody body = HubCapability.HubConnectedEvent.instance(); PlatformMessage msg = PlatformMessage.buildBroadcast(body, hub.getAddress()) .withPlaceId(PLACE_ID) .create(); scratchPad.putAlert(createAlert()); generator.handleMessage(context, scratchPad, msg, hub); String key = AlertKeys.key(SmartHomeAlert.ALERTTYPE_PLACE_HUB_OFFLINE, Address.platformService(PLACE_ID, PlaceCapability.NAMESPACE)); assertScratchPadNoAlert(key); }