Configuration { public void setErrorPageUris(Map<Integer, String> errorPageUris) { if (errorPageUris == null) { this.errorPageUris = emptyMap(); } else { for (Map.Entry<Integer, String> entry : errorPageUris.entrySet()) { int httpStatusCode = entry.getKey(); String errorPageUri = entry.getValue(); if ((httpStatusCode < 100) || (httpStatusCode > 999)) { throw new IllegalArgumentException( "HTTP status code of an error page entry must be between 100 and 999. Instead found '" + httpStatusCode + "' for URI '" + errorPageUri + "'."); } if (errorPageUri == null) { throw new IllegalArgumentException( "URI of an error page entry cannot be null. Found a null URI for HTTP status code '" + httpStatusCode + "'."); } else if (errorPageUri.isEmpty()) { throw new IllegalArgumentException( "URI of an error page entry cannot be empty. Found an empty URI for HTTP status code '" + httpStatusCode + "'."); } else if (errorPageUri.charAt(0) != '/') { throw new IllegalArgumentException( "URI of an error page entry must start with a '/'. Instead found '" + errorPageUri.charAt(0) + "' at the beginning of the URI for HTTP status code '" + httpStatusCode + "'."); } } this.errorPageUris = errorPageUris; } } Configuration(); Optional<String> getContextPath(); void setContextPath(String contextPath); Optional<String> getThemeName(); void setThemeName(String themeName); Optional<String> getLoginPageUri(); void setLoginPageUri(String loginPageUri); Optional<String> getAuthorizer(); void setAuthorizer(String authorizer); Optional<String> getSessionManagerFactoryClassName(); void setSessionManagerFactoryClassName(String factoryClassName); long getSessionTimeout(); void setSessionTimeout(long sessionTimeout); Optional<String> getErrorPageUri(int httpStatusCode); void setErrorPageUris(Map<Integer, String> errorPageUris); Optional<String> getDefaultErrorPageUri(); void setDefaultErrorPageUri(String defaultErrorPageUri); List<MenuItem> getMenu(String name); void setMenus(List<? extends Menu> menus); Set<UriPatten> getCsrfIgnoreUris(); void setCsrfIgnoreUris(Set<String> csrfIgnoreUris); Set<UriPatten> getXssIgnoreUris(); void setXssIgnoreUris(Set<String> xssIgnoreUris); ResponseHeaders getResponseHeaders(); void setResponseHeaders(ResponseHeaders responseHeaders); Map<String, Object> other(); void setOther(Map<String, Object> other);  }
@Test public void testErrorPageUrisValidation() { Configuration configuration = createConfiguration(); Assert.assertThrows(IllegalArgumentException.class, () -> configuration.setErrorPageUris(ImmutableMap.of(99, "/error/99"))); Assert.assertThrows(IllegalArgumentException.class, () -> configuration.setErrorPageUris(ImmutableMap.of(1000, "/error/100"))); Assert.assertThrows(IllegalArgumentException.class, () -> configuration.setErrorPageUris(Collections.singletonMap(500, null))); Assert.assertThrows(IllegalArgumentException.class, () -> configuration.setErrorPageUris(ImmutableMap.of(500, ""))); Assert.assertThrows(IllegalArgumentException.class, () -> configuration.setErrorPageUris(ImmutableMap.of(500, "error/500"))); configuration.setErrorPageUris(null); configuration.setErrorPageUris(Collections.emptyMap()); configuration.setErrorPageUris(ImmutableMap.of(500, "/error/500")); }