### Question:
PlatformAlarmIncidentService extends BaseAlarmIncidentService implements AlarmIncidentService { public void onEvent(PlatformMessage msg) { switch(msg.getMessageType()) { case AlarmService.CancelAlertResponse.NAME: case MessageConstants.MSG_EMPTY_MESSAGE: case MessageConstants.MSG_ERROR: onResponse(msg); break; } } @Inject  PlatformAlarmIncidentService(
			SubsystemRegistry registry,
			AlarmIncidentDAO incidentDao,
			AlarmIncidentHistoryListener historyListener,
			PlatformMessageBus platformBus,
			PlacePopulationCacheManager populationCacheMgr
	); void setAttributes(PlatformMessage msg); void onEvent(PlatformMessage msg);  }### Answer:
@Test public void testCancelSucceeds() { AlarmIncident current = IncidentFixtures.createSmokeAlarm(serviceLevel); expectCurrentAndReturn(current); expectFindByAndReturn(current); expectCancelling(current, cancelledBy, AlarmService.CancelAlertRequest.METHOD_APP); Capture<AlarmIncident> cancellingCapture = expectUpdate(); Capture<AlarmIncident> cancelledCapture = expectUpdate(); replay(); service.cancel(context, cancelledBy, AlarmService.CancelAlertRequest.METHOD_APP); assertTrue(cancellingCapture.hasCaptured()); assertFalse(cancelledCapture.hasCaptured()); PlatformMessage vc = bus.poll(); assertEquals(Capability.EVENT_VALUE_CHANGE, vc.getMessageType()); assertEquals( ImmutableMap.of( AlarmIncidentCapability.ATTR_ALERTSTATE, AlarmIncidentCapability.ALERTSTATE_CANCELLING, AlarmIncidentCapability.ATTR_PLATFORMSTATE, AlarmIncidentCapability.PLATFORMSTATE_CANCELLING ), vc.getValue().getAttributes() ); assertEquals(AlertState.CANCELLING, cancellingCapture.getValue().getAlertState()); assertEquals(null, cancellingCapture.getValue().getHubAlertState()); assertEquals(AlertState.CANCELLING, cancellingCapture.getValue().getPlatformAlertState()); PlatformMessage request = bus.poll(); assertEquals(AlarmService.CancelAlertRequest.NAME, request.getMessageType()); PlatformMessage response = PlatformMessage .respondTo(request) .withPayload(AlarmService.CancelAlertResponse.instance()) .create(); service.onEvent(response); AlarmIncident incident = cancelledCapture.getValue(); for(TrackerEvent cur : incident.getTracker()) { assertTrackerEvent(cur); } assertEquals(cancelledBy, incident.getCancelledBy()); assertNotNull(incident.getEndTime()); assertEquals(AlertState.COMPLETE, incident.getAlertState()); verify(); }
@Test public void testCancelFails() { AlarmIncident current = IncidentFixtures.createSmokeAlarm(serviceLevel); expectCurrentAndReturn(current); expectCancelling(current, cancelledBy, AlarmService.CancelAlertRequest.METHOD_APP); Capture<AlarmIncident> cancellingCapture = expectUpdate(); replay(); service.cancel(context, cancelledBy, AlarmService.CancelAlertRequest.METHOD_APP); PlatformMessage vc = bus.poll(); assertEquals(Capability.EVENT_VALUE_CHANGE, vc.getMessageType()); assertEquals( ImmutableMap.of( AlarmIncidentCapability.ATTR_ALERTSTATE, AlarmIncidentCapability.ALERTSTATE_CANCELLING, AlarmIncidentCapability.ATTR_PLATFORMSTATE, AlarmIncidentCapability.PLATFORMSTATE_CANCELLING ), vc.getValue().getAttributes() ); assertEquals(AlertState.CANCELLING, cancellingCapture.getValue().getAlertState()); PlatformMessage request = bus.poll(); assertEquals(AlarmService.CancelAlertRequest.NAME, request.getMessageType()); PlatformMessage response = PlatformMessage .respondTo(request) .withPayload(Errors.requestCancelled()) .create(); service.onEvent(response); verify(); }