@Test public void getStorageById() { String id = "id"; when(storageData.getId()).thenReturn(id); when(storageService.getExistingStorages()).thenReturn(Collections.singletonList(storageData)); assertThat(restfulService.getStorageById(id), is(storageData)); when(storageData.getId()).thenReturn(""); assertThat(restfulService.getStorageById(id), is(nullValue())); }
@RequestMapping(method = GET, value = "{id}") @ResponseBody public StorageData getStorageById(@PathVariable String id) { List<StorageData> storages = storageService.getExistingStorages(); for (StorageData storageData : storages) { if (Objects.equals(id, storageData.getId())) { return storageData; } } return null; }
StorageRestfulService { @RequestMapping(method = GET, value = "{id}") @ResponseBody public StorageData getStorageById(@PathVariable String id) { List<StorageData> storages = storageService.getExistingStorages(); for (StorageData storageData : storages) { if (Objects.equals(id, storageData.getId())) { return storageData; } } return null; } }
StorageRestfulService { @RequestMapping(method = GET, value = "{id}") @ResponseBody public StorageData getStorageById(@PathVariable String id) { List<StorageData> storages = storageService.getExistingStorages(); for (StorageData storageData : storages) { if (Objects.equals(id, storageData.getId())) { return storageData; } } return null; }  }
StorageRestfulService { @RequestMapping(method = GET, value = "{id}") @ResponseBody public StorageData getStorageById(@PathVariable String id) { List<StorageData> storages = storageService.getExistingStorages(); for (StorageData storageData : storages) { if (Objects.equals(id, storageData.getId())) { return storageData; } } return null; }  @ExceptionHandler(Exception.class) ModelAndView handleAllException(Exception exception); @RequestMapping(method = GET, value = "") @ResponseBody List<StorageData> getAllStorages(); @RequestMapping(method = GET, value = "{id}") @ResponseBody StorageData getStorageById(@PathVariable String id); @RequestMapping(method = GET, value = "{name}/create") @ResponseBody Object createStorage(@PathVariable String name); @RequestMapping(method = GET, value = "{id}/finalize") @ResponseBody Object finalizeStorage(@PathVariable String id); @RequestMapping(method = GET, value = "{id}/delete") @ResponseBody Object deleteStorage(@PathVariable String id); @RequestMapping(method = GET, value = "state") @ResponseBody Map<String, Object> getRecordingState(); @RequestMapping(method = GET, value = "stop") @ResponseBody Object stopRecording(); @RequestMapping(method = RequestMethod.GET, value = "start") @ResponseBody Object startOrScheduleRecording(@RequestParam(value = "id", required = true) String id, @RequestParam(value = "startDelay", required = false) Long startDelay,
			@RequestParam(value = "recordingDuration", required = false) Long recordingDuration,
			@RequestParam(value = "extractInvocations", required = false, defaultValue = "true") Boolean extractInvocations,
			@RequestParam(value = "autoFinalize", required = false, defaultValue = "true") Boolean autoFinalize); @ModelAttribute void setVaryResponseHeader(HttpServletResponse response); }
StorageRestfulService { @RequestMapping(method = GET, value = "{id}") @ResponseBody public StorageData getStorageById(@PathVariable String id) { List<StorageData> storages = storageService.getExistingStorages(); for (StorageData storageData : storages) { if (Objects.equals(id, storageData.getId())) { return storageData; } } return null; }  @ExceptionHandler(Exception.class) ModelAndView handleAllException(Exception exception); @RequestMapping(method = GET, value = "") @ResponseBody List<StorageData> getAllStorages(); @RequestMapping(method = GET, value = "{id}") @ResponseBody StorageData getStorageById(@PathVariable String id); @RequestMapping(method = GET, value = "{name}/create") @ResponseBody Object createStorage(@PathVariable String name); @RequestMapping(method = GET, value = "{id}/finalize") @ResponseBody Object finalizeStorage(@PathVariable String id); @RequestMapping(method = GET, value = "{id}/delete") @ResponseBody Object deleteStorage(@PathVariable String id); @RequestMapping(method = GET, value = "state") @ResponseBody Map<String, Object> getRecordingState(); @RequestMapping(method = GET, value = "stop") @ResponseBody Object stopRecording(); @RequestMapping(method = RequestMethod.GET, value = "start") @ResponseBody Object startOrScheduleRecording(@RequestParam(value = "id", required = true) String id, @RequestParam(value = "startDelay", required = false) Long startDelay,
			@RequestParam(value = "recordingDuration", required = false) Long recordingDuration,
			@RequestParam(value = "extractInvocations", required = false, defaultValue = "true") Boolean extractInvocations,
			@RequestParam(value = "autoFinalize", required = false, defaultValue = "true") Boolean autoFinalize); @ModelAttribute void setVaryResponseHeader(HttpServletResponse response);  }