### Question:
ServletContextLicenseLocator extends ResourceLoaderLicenseLocator { @Override protected InputStream getResourceAsStream(String resourceName) { return servletContext.getResourceAsStream(prependIfAbsent(resourceName, "/")); } ServletContextLicenseLocator(ServletContext servletContext, Charset charset, String...licenseFiles);   }### Answer:
@Test public void shouldReturnFullLicenseContents() { String licenseName = "/aaa"; String licenseText = "some\nsample license\ntext"; testLocator = new ServletContextLicenseLocator(mockContext, UTF8, licenseName); given(mockContext.getResourceAsStream(licenseName)) .willReturn(new ByteArrayInputStream(licenseText.getBytes(UTF8))); LicenseSet result = testLocator.getRequiredLicenses(); assertNotNull(result); assertEquals(result.getLicenses().size(), 1); assertEquals(result.getLicenses().get(0), new License(licenseName, licenseText)); }
@Test public void shouldPrependSlashToLicensePathIfNotSpecified() { String licenseName = "aaa"; String licenseText = "..."; testLocator = new ServletContextLicenseLocator(mockContext, UTF8, licenseName); given(mockContext.getResourceAsStream(anyString())) .willReturn(new ByteArrayInputStream(licenseText.getBytes(UTF8))); LicenseSet result = testLocator.getRequiredLicenses(); verify(mockContext).getResourceAsStream("/" + licenseName); assertNotNull(result); }
@Test public void shouldNotPrependSlashToLicensePathIfAlreadySpecified() { String licenseName = "/aaa"; String licenseText = "..."; testLocator = new ServletContextLicenseLocator(mockContext, UTF8, licenseName); given(mockContext.getResourceAsStream(anyString())) .willReturn(new ByteArrayInputStream(licenseText.getBytes(UTF8))); LicenseSet result = testLocator.getRequiredLicenses(); verify(mockContext).getResourceAsStream(licenseName); assertNotNull(result); }