### Question:
OfflineBatteryPostProcessor implements AlertPostProcessor { @Override public void postProcess(SubsystemContext<PlaceMonitorSubsystemModel> context, AlertScratchPad originalAlerts, AlertScratchPad scratch) { originalAlerts.alerts(lowBatteryFilter).forEach(alert -> { String offlineKey = AlertKeys.key(SmartHomeAlert.ALERTTYPE_DEV_ERR_OFFLINE, alert.getSubjectaddr()); if(originalAlerts.hasAlert(offlineKey)) { scratch.removeAlert(offlineKey); scratch.removeAlert(alert.getAlertkey()); scratch.putAlert(createOfflineBattery(alert)); } }); }  @Override void postProcess(SubsystemContext<PlaceMonitorSubsystemModel> context, AlertScratchPad originalAlerts, AlertScratchPad scratch);  }### Answer:
@Test public void testBatteryButNotOfflineMakesNoChange() { replay(); SmartHomeAlert alert = SmartHomeAlerts.create( SmartHomeAlert.ALERTTYPE_DEV_WARN_BATTERY_LOW, SmartHomeAlert.SEVERITY_LOW, lock.getAddress(), ImmutableMap.of(), PLACE_ID ); scratchPad.putAlert(alert); AlertScratchPad copy = scratchPad.copy(); processor.postProcess(context, scratchPad, copy); assertScratchPadHasAlert(copy, alert.getAlertkey()); }
@Test public void testOfflineNoBatteryMakesNoChange() { replay(); SmartHomeAlert alert = SmartHomeAlerts.create( SmartHomeAlert.ALERTTYPE_DEV_ERR_OFFLINE, SmartHomeAlert.SEVERITY_CRITICAL, lock.getAddress(), ImmutableMap.of(), PLACE_ID ); scratchPad.putAlert(alert); AlertScratchPad copy = scratchPad.copy(); processor.postProcess(context, scratchPad, copy); assertScratchPadHasAlert(copy, alert.getAlertkey()); }
@Test public void testOfflineWithBatteryReplaced() { replay(); SmartHomeAlert alert = SmartHomeAlerts.create( SmartHomeAlert.ALERTTYPE_DEV_ERR_OFFLINE, SmartHomeAlert.SEVERITY_CRITICAL, lock.getAddress(), ImmutableMap.of(), PLACE_ID ); SmartHomeAlert battery = SmartHomeAlerts.create( SmartHomeAlert.ALERTTYPE_DEV_WARN_BATTERY_LOW, SmartHomeAlert.SEVERITY_LOW, lock.getAddress(), ImmutableMap.of(), PLACE_ID ); scratchPad.putAlert(alert); scratchPad.putAlert(battery); AlertScratchPad copy = scratchPad.copy(); processor.postProcess(context, scratchPad, copy); assertScratchPadHasAlert(copy, AlertKeys.key(SmartHomeAlert.ALERTTYPE_DEV_ERR_OFFLINE_BATTERY, lock.getAddress())); assertScratchPadNoAlert(copy, alert.getAlertkey()); assertScratchPadNoAlert(copy, battery.getAlertkey()); }