### Question:
TransformService { public String retrieveApiBasePath(String serviceId, String serviceUrl, RoutedServices routes) throws URLTransformationException { URI serviceUri = URI.create(serviceUrl); String serviceUriPath = serviceUri.getPath(); if (serviceUriPath == null) { String message = String.format("The URI %s is not valid.", serviceUri); throw new URLTransformationException(message); } RoutedService route = routes.getBestMatchingApiUrl(serviceUriPath); if (route == null) { String message = String.format("Not able to select API base path for the service %s. Original url used.", serviceId); throw new URLTransformationException(message); } return String.format("/%s/%s", serviceId, route.getGatewayUrl()); }  String transformURL(ServiceType type,
                               String serviceId,
                               String serviceUrl,
                               RoutedServices routes); String retrieveApiBasePath(String serviceId,
                                      String serviceUrl,
                                      RoutedServices routes);  }### Answer:
@Test public void givenServiceAndApiRoute_whenGetApiBasePath_thenReturnApiPath() throws URLTransformationException { String url = "https: String serviceUrl = String.format("/%s/%s", SERVICE_ID, API_PREFIX); RoutedServices routedServices = new RoutedServices(); RoutedService routedService = new RoutedService(SERVICE_ID, API_PREFIX, serviceUrl); routedServices.addRoutedService(routedService); TransformService transformService = new TransformService(null); String actualPath = transformService.retrieveApiBasePath(SERVICE_ID, url, routedServices); String expectedPath = String.format("/%s/%s", SERVICE_ID, API_PREFIX); assertEquals(expectedPath, actualPath); }
@Test public void givenInvalidUriPath_whenGetApiBasePath_thenThrowError() throws URLTransformationException { String url = "https:localhost:8080/wss"; TransformService transformService = new TransformService(null); exception.expect(URLTransformationException.class); exception.expectMessage("The URI " + url + " is not valid."); transformService.retrieveApiBasePath(null, url, null); }
@Test public void givenNoRoutes_whenGetApiBasePath_thenThrowError() throws URLTransformationException { String url = "https: RoutedServices routedServices = new RoutedServices(); RoutedService routedService1 = new RoutedService(SERVICE_ID, UI_PREFIX, "/ui"); RoutedService routedService2 = new RoutedService(SERVICE_ID, "api/v1", "/api"); routedServices.addRoutedService(routedService1); routedServices.addRoutedService(routedService2); TransformService transformService = new TransformService(null); exception.expect(URLTransformationException.class); exception.expectMessage("Not able to select API base path for the service " + SERVICE_ID + ". Original url used."); transformService.retrieveApiBasePath(SERVICE_ID, url, routedServices); }