### Question:
LockJamGenerator extends AlertGenerator { @Override protected void handleModelChanged(SubsystemContext<PlaceMonitorSubsystemModel> context, Model model, AlertScratchPad scratchPad) { if(!DOOR_LOCK.apply(model)) { return; } Map<String, String> errs = DeviceAdvancedModel.getErrors(model, ImmutableMap.of()); if(errs.containsKey(WARN_KEY)) { scratchPad.putAlert(SmartHomeAlerts.create( SmartHomeAlert.ALERTTYPE_DEV_WARN_LOCK_JAM, SmartHomeAlert.SEVERITY_CRITICAL, model.getAddress(), SmartHomeAlerts.baseDeviceAttribues(model, prodCat), context.getPlaceId() )); } else { scratchPad.removeAlert(AlertKeys.key(SmartHomeAlert.ALERTTYPE_DEV_WARN_LOCK_JAM, model.getAddress())); } } @Inject  LockJamGenerator(ProductCatalogManager prodCat); @Override void onStarted(SubsystemContext<PlaceMonitorSubsystemModel> context, AlertScratchPad scratch); static final String WARN_KEY; }### Answer:
@Test public void testHandleModelChangedAddsAlert() { replay(); lock.setAttribute(DeviceAdvancedCapability.ATTR_ERRORS, ImmutableMap.of(LockJamGenerator.WARN_KEY, "jammed")); generator.handleModelChanged(context, lock, scratchPad); String key = AlertKeys.key(SmartHomeAlert.ALERTTYPE_DEV_WARN_LOCK_JAM, lock.getAddress()); assertScratchPadHasAlert(key); SmartHomeAlert expected = createAlert(); assertAlert(expected, scratchPad.getAlert(key)); }
@Test public void testHandleModelChangedClearsAlert() { replay(); scratchPad.putAlert(createAlert()); generator.handleModelChanged(context, lock, scratchPad); String key = AlertKeys.key(SmartHomeAlert.ALERTTYPE_DEV_WARN_LOCK_JAM, lock.getAddress()); assertScratchPadNoAlert(key); }
@Test public void testHandleModelChangedIgnoresNonLock() { replay(); door.setAttribute(DeviceAdvancedCapability.ATTR_ERRORS, ImmutableMap.of(LockJamGenerator.WARN_KEY, "jammed")); generator.handleModelChanged(context, door, scratchPad); String key = AlertKeys.key(SmartHomeAlert.ALERTTYPE_DEV_WARN_LOCK_JAM, door.getAddress()); assertScratchPadNoAlert(key); }