### Question:
CellModemNeededGenerator extends AlertGenerator { @Override protected void handleModelChanged(SubsystemContext<PlaceMonitorSubsystemModel> context, Model model, AlertScratchPad scratchPad) { Model hub = SmartHomeAlerts.hubModel(context); if(hub == null) { context.logger().info("ignoring model changes for cellbackup because {} has no hub", context.getPlaceId()); return; } if(CellBackupSubsystemModel.isStatusNOTREADY(model) && CellBackupSubsystemModel.isNotReadyStateNEEDSMODEM(model)) { scratchPad.putAlert(SmartHomeAlerts.create( SmartHomeAlert.ALERTTYPE_PLACE_4G_MODEM_NEEDED, SmartHomeAlert.SEVERITY_CRITICAL, Address.platformService(context.getPlaceId(), PlaceCapability.NAMESPACE), ImmutableMap.of(CONTEXT_ATTR_HUBID, hub.getId()), context.getPlaceId() )); } else { scratchPad.removeAlert(AlertKeys.key(SmartHomeAlert.ALERTTYPE_PLACE_4G_MODEM_NEEDED, context.getPlaceId())); } }  @Override void onStarted(SubsystemContext<PlaceMonitorSubsystemModel> context, AlertScratchPad scratch);  }### Answer:
@Test public void testHandleModelChangedPutsAlert() { replay(); cellbackup.setAttribute(CellBackupSubsystemCapability.ATTR_NOTREADYSTATE, CellBackupSubsystemCapability.NOTREADYSTATE_NEEDSMODEM); generator.handleModelChanged(context, cellbackup, scratchPad); String key = AlertKeys.key(SmartHomeAlert.ALERTTYPE_PLACE_4G_MODEM_NEEDED, PLACE_ID); assertScratchPadHasAlert(key); SmartHomeAlert expected = SmartHomeAlerts.create( SmartHomeAlert.ALERTTYPE_PLACE_4G_MODEM_NEEDED, SmartHomeAlert.SEVERITY_CRITICAL, Address.platformService(PLACE_ID, PlaceCapability.NAMESPACE), ImmutableMap.of(CONTEXT_ATTR_HUBID, hub.getId()), PLACE_ID ); assertAlert(expected, scratchPad.getAlert(key)); }
@Test public void testHandleModelChangedRemovesAlert() { replay(); scratchPad.putAlert(SmartHomeAlerts.create( SmartHomeAlert.ALERTTYPE_PLACE_4G_MODEM_NEEDED, SmartHomeAlert.SEVERITY_CRITICAL, Address.platformService(PLACE_ID, PlaceCapability.NAMESPACE), ImmutableMap.of(CONTEXT_ATTR_HUBID, hub.getId()), PLACE_ID) ); generator.handleModelChanged(context, cellbackup, scratchPad); String key = AlertKeys.key(SmartHomeAlert.ALERTTYPE_PLACE_4G_MODEM_NEEDED, PLACE_ID); assertScratchPadNoAlert(key); }
@Test public void testNoHubNoAlert() { replay(); cellbackup.setAttribute(CellBackupSubsystemCapability.ATTR_NOTREADYSTATE, CellBackupSubsystemCapability.NOTREADYSTATE_NEEDSMODEM); modelStore.removeModel(hub.getAddress()); generator.handleModelChanged(context, cellbackup, scratchPad); String key = AlertKeys.key(SmartHomeAlert.ALERTTYPE_PLACE_4G_MODEM_NEEDED, PLACE_ID); assertScratchPadNoAlert(key); }