@Test public void updateUnknownEvent() { alertingScheduler.onApplicationEvent(new AlertingDefinitionCreatedEvent(this, definitionOne)); AbstractAlertingDefinitionEvent event = new AlertingDefinitionUpdateEvent(this, definitionTwo); when(definitionOne.getId()).thenReturn("id"); when(definitionTwo.getId()).thenReturn("id_2"); alertingScheduler.onApplicationEvent(event); assertThat(getAlertingStates(), hasSize(1)); assertThat(getAlertingStates().get(0).getAlertingDefinition(), equalTo(definitionOne)); verify(definitionOne).getId(); verify(definitionTwo).getId(); verifyNoMoreInteractions(definitionOne, definitionTwo); verifyZeroInteractions(thresholdChecker, executorService); assertThat(getAlertingStates(), hasSize(1)); } }
eventPublisher.publishEvent(new AbstractAlertingDefinitionEvent.AlertingDefinitionUpdateEvent(this, alertingDefinition));
@Test public void updateEventAlertActive() { alertingScheduler.onApplicationEvent(new AlertingDefinitionCreatedEvent(this, definitionOne)); AbstractAlertingDefinitionEvent event = new AlertingDefinitionUpdateEvent(this, definitionOne); when(definitionOne.getId()).thenReturn("id"); Alert alertMock = mock(Alert.class); // set manually because it would done by the threshold checker which is also mocked getAlertingStates().get(0).setAlert(alertMock); alertingScheduler.onApplicationEvent(event); verify(alertMock, times(1)).setAlertingDefinition(definitionOne); verify(definitionOne, times(2)).getId(); verifyNoMoreInteractions(definitionOne); verifyZeroInteractions(thresholdChecker, executorService); assertThat(getAlertingStates(), hasSize(1)); }
@Test public void updateEvent() { alertingScheduler.onApplicationEvent(new AlertingDefinitionCreatedEvent(this, definitionOne)); assertThat(getAlertingStates().get(0).getAlertingDefinition(), equalTo(definitionOne)); AbstractAlertingDefinitionEvent event = new AlertingDefinitionUpdateEvent(this, definitionTwo); when(definitionOne.getId()).thenReturn("id"); when(definitionTwo.getId()).thenReturn("id"); alertingScheduler.onApplicationEvent(event); verify(definitionOne).getId(); verify(definitionTwo).getId(); verifyNoMoreInteractions(definitionOne, definitionTwo); verifyZeroInteractions(thresholdChecker, executorService); assertThat(getAlertingStates(), hasSize(1)); assertThat(getAlertingStates().get(0).getAlertingDefinition(), equalTo(definitionTwo)); }