SimpleURLPatternMapper extends BaseURLPatternMapper<T> { @Override public T getValue(String urlPath) { if (Objects.isNull(urlPath)) { return null; } T value = _exactURLPatternValues.get(urlPath); if (Objects.nonNull(value)) { return value; } value = _wildcardURLPatternValues.get(urlPath + "/*"); if (Objects.nonNull(value)) { return value; } int index = 0; for (int i = urlPath.length(); i > 0; --i) { if ((index < 1) && (urlPath.charAt(i - 1) == '.')) { index = i - 1; } if (urlPath.charAt(i - 1) != '/') { continue; } value = _wildcardURLPatternValues.get( urlPath.substring(0, i) + "*"); if (Objects.nonNull(value)) { return value; } } return _extensionURLPatternValues.get("*" + urlPath.substring(index)); } SimpleURLPatternMapper(Map<String, T> values); @Override T getValue(String urlPath);  }
@Test public void testGetValue() { Map<String, String> urlPatterns = _createURLPatterns(); URLPatternMapper<String> urlPatternMapper = createURLPatternMapper( _createValues(urlPatterns)); for (Map.Entry<String, String> entry : urlPatterns.entrySet()) { String value = urlPatternMapper.getValue(entry.getKey()); try { if (Objects.isNull(value)) { Assert.assertEquals("", entry.getValue()); continue; } Assert.assertEquals(entry.getValue(), value); } catch (ComparisonFailure comparisonFailure) { throw new ComparisonFailure( "When testing " + entry.getKey() + ":", comparisonFailure.getExpected(), comparisonFailure.getActual()); } } urlPatternMapper = createURLPatternMapper( new HashMap() { { put("*.jsp", "*.jsp"); } }); Assert.assertEquals("*.jsp", urlPatternMapper.getValue(".jsp")); Assert.assertNull(urlPatternMapper.getValue("jsp")); Assert.assertNull(urlPatternMapper.getValue(null)); }