@Test(expected = IllegalArgumentException.class) public void test_FindByCreatedBy_illegal_args() { when(detectorRepo.findByCreatedBy(anyString())).thenReturn(null); controllerUnderTest.findByCreatedBy("kashah"); }
@GetMapping(path = "/findByCreatedBy", produces = "application/json") @ResponseStatus(HttpStatus.OK) public List<DetectorDocument> findByCreatedBy(@RequestParam String user) { List<DetectorDocument> detectors = detectorRepo.findByCreatedBy(user); if (detectors == null || detectors.isEmpty()) { throw new IllegalArgumentException("Invalid user: " + user); } return detectors; }
LegacyDetectorController { @GetMapping(path = "/findByCreatedBy", produces = "application/json") @ResponseStatus(HttpStatus.OK) public List<DetectorDocument> findByCreatedBy(@RequestParam String user) { List<DetectorDocument> detectors = detectorRepo.findByCreatedBy(user); if (detectors == null || detectors.isEmpty()) { throw new IllegalArgumentException("Invalid user: " + user); } return detectors; } }
LegacyDetectorController { @GetMapping(path = "/findByCreatedBy", produces = "application/json") @ResponseStatus(HttpStatus.OK) public List<DetectorDocument> findByCreatedBy(@RequestParam String user) { List<DetectorDocument> detectors = detectorRepo.findByCreatedBy(user); if (detectors == null || detectors.isEmpty()) { throw new IllegalArgumentException("Invalid user: " + user); } return detectors; }  }
LegacyDetectorController { @GetMapping(path = "/findByCreatedBy", produces = "application/json") @ResponseStatus(HttpStatus.OK) public List<DetectorDocument> findByCreatedBy(@RequestParam String user) { List<DetectorDocument> detectors = detectorRepo.findByCreatedBy(user); if (detectors == null || detectors.isEmpty()) { throw new IllegalArgumentException("Invalid user: " + user); } return detectors; }  @PostMapping @ResponseStatus(HttpStatus.CREATED) String createDetector(@Valid @RequestBody DetectorDocument document); @GetMapping(path = "/findByUuid", produces = "application/json") @ResponseStatus(HttpStatus.OK) DetectorDocument findByUuid(@RequestParam String uuid); @GetMapping(path = "/findByCreatedBy", produces = "application/json") @ResponseStatus(HttpStatus.OK) List<DetectorDocument> findByCreatedBy(@RequestParam String user); @PostMapping(path = "/toggleDetector", consumes = "application/json", produces = "application/json") @ResponseStatus(HttpStatus.OK) void toggleDetector(@RequestParam String uuid, @RequestParam Boolean enabled); @PostMapping(path = "/trustDetector", consumes = "application/json", produces = "application/json") @ResponseStatus(HttpStatus.OK) void trustDetector(@RequestParam String uuid, @RequestParam Boolean trusted); @GetMapping(path = "/getLastUpdatedDetectors", produces = "application/json") @ResponseStatus(HttpStatus.OK) List<DetectorDocument> getLastUpdatedDetectors(@RequestParam long interval); @PutMapping @ResponseStatus(HttpStatus.OK) void updateDetector(@RequestParam String uuid, @RequestBody DetectorDocument document); @DeleteMapping @ResponseStatus(HttpStatus.OK) void deleteDetector(@RequestParam String uuid); }
LegacyDetectorController { @GetMapping(path = "/findByCreatedBy", produces = "application/json") @ResponseStatus(HttpStatus.OK) public List<DetectorDocument> findByCreatedBy(@RequestParam String user) { List<DetectorDocument> detectors = detectorRepo.findByCreatedBy(user); if (detectors == null || detectors.isEmpty()) { throw new IllegalArgumentException("Invalid user: " + user); } return detectors; }  @PostMapping @ResponseStatus(HttpStatus.CREATED) String createDetector(@Valid @RequestBody DetectorDocument document); @GetMapping(path = "/findByUuid", produces = "application/json") @ResponseStatus(HttpStatus.OK) DetectorDocument findByUuid(@RequestParam String uuid); @GetMapping(path = "/findByCreatedBy", produces = "application/json") @ResponseStatus(HttpStatus.OK) List<DetectorDocument> findByCreatedBy(@RequestParam String user); @PostMapping(path = "/toggleDetector", consumes = "application/json", produces = "application/json") @ResponseStatus(HttpStatus.OK) void toggleDetector(@RequestParam String uuid, @RequestParam Boolean enabled); @PostMapping(path = "/trustDetector", consumes = "application/json", produces = "application/json") @ResponseStatus(HttpStatus.OK) void trustDetector(@RequestParam String uuid, @RequestParam Boolean trusted); @GetMapping(path = "/getLastUpdatedDetectors", produces = "application/json") @ResponseStatus(HttpStatus.OK) List<DetectorDocument> getLastUpdatedDetectors(@RequestParam long interval); @PutMapping @ResponseStatus(HttpStatus.OK) void updateDetector(@RequestParam String uuid, @RequestBody DetectorDocument document); @DeleteMapping @ResponseStatus(HttpStatus.OK) void deleteDetector(@RequestParam String uuid);  }