### Question:
NotificationsApiController { @GetMapping(value = "/alerts", produces = { "application/json" }) public ResponseEntity<AlertData> checkAlerts() { AlertStatus alertStatus = notificationService.getAlerts(); return new ResponseEntity<>(alertDataConverter.convert(alertStatus), HttpStatus.OK); } @Autowired  NotificationsApiController(
            NotificationService notificationService, AlertDataConverter alertDataConverter); @GetMapping(value = "/session-status", produces = { "application/json" }) ResponseEntity<StatusData> isSessionAlive(HttpServletRequest request); @GetMapping(value = "/alerts", produces = { "application/json" }) ResponseEntity<AlertData> checkAlerts(); @PreAuthorize("hasAnyAuthority('BACKUP_CONFIGURATION', 'RESTORE_CONFIGURATION')") @PutMapping(value = "/alerts/reset") ResponseEntity<Void> resetBackupRestoreRunningSince(); static final String NOTIFICATIONS_API_V1_PATH; }### Answer:
@Test @WithMockUser public void checkAlerts() { AlertStatus alertStatus = new AlertStatus(); alertStatus.setGlobalConfValid(true); alertStatus.setSoftTokenPinEntered(true); when(notificationService.getAlerts()).thenReturn(alertStatus); ResponseEntity<AlertData> response = notificationsApiController.checkAlerts(); assertEquals(HttpStatus.OK, response.getStatusCode()); AlertData alertData = response.getBody(); assertEquals(null, alertData.getBackupRestoreRunningSince()); assertEquals(null, alertData.getCurrentTime()); assertEquals(alertStatus.getGlobalConfValid(), alertData.getGlobalConfValid()); assertEquals(alertStatus.getSoftTokenPinEntered(), alertData.getSoftTokenPinEntered()); }
@Test @WithMockUser public void checkAlertsBackupRestoreRunning() { OffsetDateTime date = OffsetDateTime.now(ZoneOffset.UTC); AlertStatus alertStatus = new AlertStatus(); alertStatus.setBackupRestoreRunningSince(date); alertStatus.setCurrentTime(date); alertStatus.setGlobalConfValid(true); alertStatus.setSoftTokenPinEntered(true); when(notificationService.getAlerts()).thenReturn(alertStatus); ResponseEntity<AlertData> response = notificationsApiController.checkAlerts(); assertEquals(HttpStatus.OK, response.getStatusCode()); AlertData alertData = response.getBody(); assertEquals(alertStatus.getBackupRestoreRunningSince(), alertData.getBackupRestoreRunningSince()); assertEquals(alertStatus.getCurrentTime(), alertData.getCurrentTime()); assertEquals(alertStatus.getGlobalConfValid(), alertData.getGlobalConfValid()); assertEquals(alertStatus.getSoftTokenPinEntered(), alertData.getSoftTokenPinEntered()); }
@Test @WithMockUser public void checkAlertsSoftTokenNotFound() { doThrow(new RuntimeException("")).when(notificationService).getAlerts(); try { ResponseEntity<AlertData> response = notificationsApiController.checkAlerts(); fail("should throw RuntimeException"); } catch (RuntimeException expected) { } }