### Question:
CreatedEventHandler { @Selector(value="topic.deployment.status", reactor="@rootReactor") public void deploymentCreated(Event<DeploymentEvent> event) { DeploymentEvent deploymentEvent = event.getData(); if(deploymentEvent.getDeploymentStatus().equals(Dictionary.APPLICATION_STATUS_SUBMITTED)) { logger.info(" Moving deployment id: " + deploymentEvent.getDeploymentId() + " to NEGOTIATION state"); Deployment deployment = deploymentDAO.getById(deploymentEvent.getDeploymentId()); deployment.setStatus(Dictionary.APPLICATION_STATUS_NEGOTIATION); deploymentEvent.setDeploymentStatus(deployment.getStatus()); deploymentDAO.update(deployment); deploymentEventService.fireDeploymentEvent(deploymentEvent); } }  @Selector(value="topic.deployment.status", reactor="@rootReactor") void deploymentCreated(Event<DeploymentEvent> event);  }### Answer:
@Test public void testWrongStateDoesNothing() { DeploymentDAO deploymentDAO = mock(DeploymentDAO.class); DeploymentEventService deploymentEventService = mock(DeploymentEventService.class); CreatedEventHandler createdEvent = new CreatedEventHandler(); createdEvent.deploymentDAO = deploymentDAO; createdEvent.deploymentEventService = deploymentEventService; DeploymentEvent deploymentEvent = new DeploymentEvent(); deploymentEvent.setDeploymentId(22); deploymentEvent.setDeploymentStatus("1111"); createdEvent.deploymentCreated(Event.wrap(deploymentEvent)); verify(deploymentDAO, never()).getById(deploymentEvent.getDeploymentId()); verify(deploymentDAO, never()).update(any(Deployment.class)); verify(deploymentEventService, never()).fireDeploymentEvent(any(DeploymentEvent.class)); }
@Test public void testChangeState() { DeploymentDAO deploymentDAO = mock(DeploymentDAO.class); DeploymentEventService deploymentEventService = mock(DeploymentEventService.class); CreatedEventHandler createdEvent = new CreatedEventHandler(); createdEvent.deploymentDAO = deploymentDAO; createdEvent.deploymentEventService = deploymentEventService; DeploymentEvent deploymentEvent = new DeploymentEvent(); deploymentEvent.setDeploymentId(22); deploymentEvent.setApplicationName("applicationName"); deploymentEvent.setDeploymentStatus(Dictionary.APPLICATION_STATUS_SUBMITTED); Deployment deployment = new Deployment(); deployment.setId(22); deployment.setStatus("UNKNOWN"); when(deploymentDAO.getById(22)).thenReturn(deployment); when(deploymentDAO.update(deployment)).thenReturn(true); createdEvent.deploymentCreated(Event.wrap(deploymentEvent)); ArgumentCaptor<DeploymentEvent> argument = ArgumentCaptor.forClass(DeploymentEvent.class); verify(deploymentEventService).fireDeploymentEvent(argument.capture()); assertEquals(22, argument.getValue().getDeploymentId()); assertEquals(Dictionary.APPLICATION_STATUS_NEGOTIATION, argument.getValue().getDeploymentStatus()); assertEquals("applicationName", argument.getValue().getApplicationName()); }