@Override public String getString(String fullName, Charset encoding, JinjavaInterpreter interpreter) throws IOException { for (ResourceLocator locator : locators) { try { return locator.getString(fullName, encoding, interpreter); } catch (ResourceNotFoundException e) { /* */ } } throw new ResourceNotFoundException("Couldn't find resource: " + fullName); }
public String getResource(String resource) throws IOException { return application.getResourceLocator().getString(resource, config.getCharset(), this); }
@Test(expected = ResourceNotFoundException.class) public void notFoundWhenAllLocatorsReturnNotFound() throws Exception { when(first.getString("foo", StandardCharsets.UTF_8, interpreter)).thenThrow(ResourceNotFoundException.class); when(second.getString("foo", StandardCharsets.UTF_8, interpreter)).thenThrow(ResourceNotFoundException.class); locator.getString("foo", StandardCharsets.UTF_8, interpreter); } }
@Test public void itUsesResponseFromSecondWhenNotFoundOnFirst() throws Exception { when(first.getString("foo", StandardCharsets.UTF_8, interpreter)).thenThrow(ResourceNotFoundException.class); when(second.getString("foo", StandardCharsets.UTF_8, interpreter)).thenReturn("bar"); assertThat(locator.getString("foo", StandardCharsets.UTF_8, interpreter)).isEqualTo("bar"); }
@Test(expected = ResourceNotFoundException.class) public void notFoundWhenAllLocatorsReturnNotFound() throws Exception { when(first.getString("foo", StandardCharsets.UTF_8, interpreter)).thenThrow(ResourceNotFoundException.class); when(second.getString("foo", StandardCharsets.UTF_8, interpreter)).thenThrow(ResourceNotFoundException.class); locator.getString("foo", StandardCharsets.UTF_8, interpreter); } }
@Test public void itUsesResponseFromSecondWhenNotFoundOnFirst() throws Exception { when(first.getString("foo", StandardCharsets.UTF_8, interpreter)).thenThrow(ResourceNotFoundException.class); when(second.getString("foo", StandardCharsets.UTF_8, interpreter)).thenReturn("bar"); assertThat(locator.getString("foo", StandardCharsets.UTF_8, interpreter)).isEqualTo("bar"); }
@Test public void itUsesResponseFromFirstIfPresent() throws Exception { when(first.getString("foo", StandardCharsets.UTF_8, interpreter)).thenReturn("bar"); assertThat(locator.getString("foo", StandardCharsets.UTF_8, interpreter)).isEqualTo("bar"); }
@Test public void itUsesResponseFromFirstIfPresent() throws Exception { when(first.getString("foo", StandardCharsets.UTF_8, interpreter)).thenReturn("bar"); assertThat(locator.getString("foo", StandardCharsets.UTF_8, interpreter)).isEqualTo("bar"); }