Using Spring mockMvc to test optional path variables
Using an array of @RequestMapping values like this … @RequestMapping( value = {“/some/uri/{foo}”, “/some/uri/{foo}/{bar}”}, method = RequestMethod.PUT) public ResponseEntity<String> someMethod( @PathVariable(“foo”) String foo, @PathVariable(value = “bar”, required = false) String bar ) { return new ResponseEntity<>(foo + ” and ” + (bar == null ? “<null>” : bar), HttpStatus.OK); } … will enable this test … Read more