### Question:
ServletApplicationFactory extends DefaultApplicationFactory { @Override protected String getServiceUrl() { if (instance.getServiceUrl() != null) { return instance.getServiceUrl(); } return UriComponentsBuilder.fromUriString(getServiceBaseUrl()).path(getServicePath()) .path(getServerContextPath()).toUriString(); } ServletApplicationFactory(InstanceProperties instance, ManagementServerProperties management,
			ServerProperties server, ServletContext servletContext, PathMappedEndpoints pathMappedEndpoints,
			WebEndpointProperties webEndpoint, MetadataContributor metadataContributor,
			DispatcherServletPath dispatcherServletPath);   }### Answer:
@Test public void test_contextPath_mgmtPath() { servletContext.setContextPath("app"); webEndpoint.setBasePath("/admin"); when(pathMappedEndpoints.getPath(EndpointId.of("health"))).thenReturn("/admin/health"); publishApplicationReadyEvent(factory, 8080, null); Application app = factory.createApplication(); assertThat(app.getManagementUrl()).isEqualTo("http: assertThat(app.getHealthUrl()).isEqualTo("http: assertThat(app.getServiceUrl()).isEqualTo("http: }
@Test public void test_contextPath_mgmtPortPath() { servletContext.setContextPath("app"); webEndpoint.setBasePath("/admin"); when(pathMappedEndpoints.getPath(EndpointId.of("health"))).thenReturn("/admin/health"); publishApplicationReadyEvent(factory, 8080, 8081); Application app = factory.createApplication(); assertThat(app.getManagementUrl()).isEqualTo("http: assertThat(app.getHealthUrl()).isEqualTo("http: assertThat(app.getServiceUrl()).isEqualTo("http: }
@Test public void test_contextPath() { servletContext.setContextPath("app"); when(pathMappedEndpoints.getPath(EndpointId.of("health"))).thenReturn("/actuator/health"); publishApplicationReadyEvent(factory, 80, null); Application app = factory.createApplication(); assertThat(app.getManagementUrl()).isEqualTo("http: assertThat(app.getHealthUrl()).isEqualTo("http: assertThat(app.getServiceUrl()).isEqualTo("http: }
@Test public void test_servletPath() { when(dispatcherServletPath.getPrefix()).thenReturn("app"); servletContext.setContextPath("srv"); when(pathMappedEndpoints.getPath(EndpointId.of("health"))).thenReturn("/actuator/health"); publishApplicationReadyEvent(factory, 80, null); Application app = factory.createApplication(); assertThat(app.getManagementUrl()).isEqualTo("http: assertThat(app.getHealthUrl()).isEqualTo("http: assertThat(app.getServiceUrl()).isEqualTo("http: }
@Test public void test_servicePath() { servletContext.setContextPath("app"); when(pathMappedEndpoints.getPath(EndpointId.of("health"))).thenReturn("/actuator/health"); publishApplicationReadyEvent(factory, 80, null); instance.setServicePath("/servicePath/"); Application app = factory.createApplication(); assertThat(app.getManagementUrl()).isEqualTo("http: assertThat(app.getHealthUrl()).isEqualTo("http: assertThat(app.getServiceUrl()).isEqualTo("http: }