### Question:
ContextExtendedURLURLNormalizer implements URLNormalizer<ExtendedURL> { @Override public ExtendedURL normalize(ExtendedURL partialURL) { String contextPath = StringUtils.strip(getContextPath(), URL_SEGMENT_DELIMITER); if (contextPath == null) { throw new RuntimeException(String.format("Failed to normalize the URL [%s] since the " + "application's Servlet context couldn't be computed.", partialURL)); } List<String> segments = new ArrayList<>(); if (StringUtils.isNotEmpty(contextPath)) { segments.add(contextPath); } segments.addAll(partialURL.getSegments()); return new ExtendedURL(segments, partialURL.getParameters()); }  @Override ExtendedURL normalize(ExtendedURL partialURL);  }### Answer:
@Test void normalizeWhenConfigurationPropertyDefined() { when(this.configurationSource.getProperty("xwiki.webapppath")).thenReturn("xwiki"); ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("one", "two")); assertEquals("/xwiki/one/two", this.normalizer.normalize(extendedURL).serialize()); }
@Test void normalizeWhenConfigurationPropertyDefinedButWithLeadingAndTrailingSlash() { when(this.configurationSource.getProperty("xwiki.webapppath")).thenReturn("/xwiki/"); ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("one", "two")); assertEquals("/xwiki/one/two", this.normalizer.normalize(extendedURL).serialize()); }
@Test void normalizeWhenNoConfigurationPropertyAndNoServletEnvironment() { ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("one", "two")); Throwable expected = assertThrows(RuntimeException.class, () -> this.normalizer.normalize(extendedURL)); assertEquals("Failed to normalize the URL [/one/two] since the application's Servlet context couldn't be " + "computed.", expected.getMessage()); }
@Test void normalizeExtendedURLWithParameters() { when(this.configurationSource.getProperty("xwiki.webapppath")).thenReturn("xwiki"); Map<String, List<String>> params = new HashMap<>(); params.put("age", Arrays.asList("32")); params.put("colors", Arrays.asList("red", "blue")); ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("one", "two"), params); assertSame(params, this.normalizer.normalize(extendedURL).getParameters()); }
@Test void normalizeWhenRootWebapp() { when(this.configurationSource.getProperty("xwiki.webapppath")).thenReturn(""); ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("one", "two")); assertEquals("/one/two", this.normalizer.normalize(extendedURL).serialize()); }