### Question:
ResponseDtoValidator extends ResponseEntityExceptionHandler { String getResourceName(WebRequest request) { String description = request.getDescription(false); String[] uriParts = description.split("/"); String resourceName; if (uriParts.length >= 5) { resourceName = uriParts[4]; } else if (uriParts.length >= 3) { resourceName = uriParts[2]; } else { log.error("No resource in {}", description); resourceName = "unknown"; } return resourceName; }    }### Answer:
@Test public void getResourceName_ShouldReturnSubResourceOfProject_WhenUrlHasASubResourceOfProject() { when(request.getDescription(false)) .thenReturn("uri=/api/projects/some-project/some-resources/api"); final String resourceName = cut.getResourceName(request); assertThat(resourceName).isEqualTo("some-resources"); }
@Test public void getResourceName_ShouldReturnProjects_WhenUrlIsAProjectUrl() { when(request.getDescription(false)) .thenReturn("uri=/api/projects/some-project"); final String resourceName = cut.getResourceName(request); assertThat(resourceName).isEqualTo("projects"); }