/** * {@inheritDoc} */ @Override public Alert getAlert(String alertId) { return alertRegistry.getAlert(alertId); }
@Test public void getUnknownAlert() { Alert alert = alertRegistry.getAlert("unknown-id"); assertThat(alert, is(nullValue())); }
@Test public void getByNull() { Alert alert = alertRegistry.getAlert(null); assertThat(alert, is(nullValue())); } }
@Test public void getAlert() { Alert testAlert = Mockito.mock(Alert.class, Mockito.RETURNS_MOCKS); when(testAlert.getId()).thenReturn("id"); alertRegistry.registerAlert(testAlert); Alert alert = alertRegistry.getAlert("id"); verify(testAlert, times(2)).getId(); verify(testAlert).getAlertingDefinition(); verifyNoMoreInteractions(testAlert); assertThat(alert, equalTo(testAlert)); }
@Test public void registerSuccessful() { Alert testAlert = Mockito.mock(Alert.class, Mockito.RETURNS_MOCKS); when(testAlert.getId()).thenReturn("id"); alertRegistry.registerAlert(testAlert); verify(testAlert, times(2)).getId(); verify(testAlert).getAlertingDefinition(); verifyNoMoreInteractions(testAlert); assertThat(alertRegistry.getAlert("id"), equalTo(testAlert)); }
@Test public void replaceAlert() throws Exception { Alert alertOne = Mockito.mock(Alert.class, Mockito.RETURNS_MOCKS); when(alertOne.getId()).thenReturn("id"); Alert alertTwo = Mockito.mock(Alert.class, Mockito.RETURNS_MOCKS); when(alertTwo.getId()).thenReturn("id"); alertRegistry.registerAlert(alertOne); alertRegistry.registerAlert(alertTwo); verify(alertOne, times(2)).getId(); verify(alertOne).getAlertingDefinition(); verify(alertTwo, times(2)).getId(); verify(alertTwo).getAlertingDefinition(); verifyNoMoreInteractions(alertOne, alertTwo); assertThat(alertRegistry.getAlert("id"), equalTo(alertTwo)); } }
throw new BusinessException("Retrieving invocation sequences for alert with id '" + alertId + "'", AlertErrorCodeEnum.DATABASE_OFFLINE); Alert alert = alertRegistry.getAlert(alertId); if (null == alert) { throw new BusinessException("Retrieving invocation sequences for alert with id '" + alertId + "'", AlertErrorCodeEnum.UNKNOWN_ALERT_ID);