### Question:
ResourceExtensionResolver { public File resolveRestApiControllerFile(PageResourceProviderImpl pageResourceProvider) throws NotFoundException { final Properties properties = new Properties(); try (final InputStream resourceAsStream = pageResourceProvider.getResourceAsStream("page.properties");) { properties.load(resourceAsStream); } catch (final IOException e) { throw new NotFoundException("error while getting resource:" + generateMappingKey()); } final String apiExtensionList = (String) properties.get("apiExtensions"); final String[] apiExtensions = apiExtensionList.split(","); return toFile(pageResourceProvider, findMatchingExtension(properties, apiExtensions)); } ResourceExtensionResolver(Request request, PageMappingService pageMappingService); Long resolvePageId(APISession apiSession); String generateMappingKey(); File resolveRestApiControllerFile(PageResourceProviderImpl pageResourceProvider); static final String MAPPING_KEY_SEPARATOR; static final String MAPPING_KEY_PREFIX; static final String API_EXTENSION_TEMPLATE_PREFIX; }### Answer:
@Test public void should_post_resolve_class_file_name() throws Exception { final Request request = new Request(Method.POST, "/bonita/API/extension/myPostResource"); final ResourceExtensionResolver resourceExtensionResolver = createSpy(request, "/bonita/API/extension/myPostResource"); when(pageResourceProvider.getPageDirectory()).thenReturn(new File("")); final File file = resourceExtensionResolver.resolveRestApiControllerFile(pageResourceProvider); assertThat(file.getName()).isEqualTo("PostResource.groovy"); }
@Test public void should_get_resolve_class_file_name() throws Exception { final Request request = new Request(Method.GET, "/bonita/API/extension/helloWorld"); final ResourceExtensionResolver resourceExtensionResolver = createSpy(request, "/bonita/API/extension/helloWorld"); when(pageResourceProvider.getPageDirectory()).thenReturn(new File("")); final File restApiControllerFile = resourceExtensionResolver.resolveRestApiControllerFile(pageResourceProvider); assertThat(restApiControllerFile.getName()).isEqualTo("Index.groovy"); }
@Test public void should_resolve_class_file_name_when_name_begins_the_same_than_another() throws Exception { final Request request = new Request(Method.POST, "/bonita/API/extension/myPostResourceB"); final ResourceExtensionResolver resourceExtensionResolver = createSpy(request, "/bonita/API/extension/myPostResourceB"); when(pageResourceProvider.getPageDirectory()).thenReturn(new File("")); final File file = resourceExtensionResolver.resolveRestApiControllerFile(pageResourceProvider); assertThat(file.getName()).isEqualTo("PostResourceB.groovy"); }
@Test public void should_not_resolve_class_file_name() throws Exception { expectedException.expect(NotFoundException.class); expectedException.expectMessage("error while getting resource:apiExtension|POST|notResource"); final Request request = new Request(Method.POST, "/bonita/API/extension/notResource"); final ResourceExtensionResolver resourceExtensionResolver = createSpy(request, "/bonita/API/extension/notResource"); resourceExtensionResolver.resolveRestApiControllerFile(pageResourceProvider); }