### Question:
GZIPAwareResourceLoader implements ResourceLoader { public InputStream openResource(final String resource) throws IOException { final InputStream is = delegate.openResource(resource); if (is == null) { return null; } else { return detectGZIPAndWrap(is); } } GZIPAwareResourceLoader(ResourceLoader delegate); InputStream openResource(final String resource); @Override Class<? extends T> findClass(final String cname, final Class<T> expectedType); @Override T newInstance(final String cname, final Class<T> expectedType);  }### Answer:
@Test public void testOpenEmptyResource() throws IOException { when(resourceLoader.openResource("some_name")).thenReturn(new ByteArrayInputStream(new byte[] {})); final GZIPAwareResourceLoader loader = new GZIPAwareResourceLoader(resourceLoader); final InputStream inputStream = loader.openResource("some_name"); inputStream.close(); verify(resourceLoader, times(1)).openResource("some_name"); }
@Test public void testZippedResource() throws IOException { when(resourceLoader.openResource("some_name")).thenReturn(getClass().getClassLoader() .getResourceAsStream("rules.txt.gz")); final GZIPAwareResourceLoader loader = new GZIPAwareResourceLoader(resourceLoader); try (final BufferedReader reader = new BufferedReader( new InputStreamReader(loader.openResource("some_name")))) { assertEquals("HELLO QUERQY!", reader.readLine()); assertNull(reader.readLine()); } verify(resourceLoader, times(1)).openResource("some_name"); }
@Test public void testUnzippedResource() throws IOException { when(resourceLoader.openResource("some_name")).thenReturn(new ByteArrayInputStream("HELLO, I wasn't zipped!" .getBytes(Charset.defaultCharset()))); final GZIPAwareResourceLoader loader = new GZIPAwareResourceLoader(resourceLoader); try (final BufferedReader reader = new BufferedReader( new InputStreamReader(loader.openResource("some_name")))) { assertEquals("HELLO, I wasn't zipped!", reader.readLine()); assertNull(reader.readLine()); } verify(resourceLoader, times(1)).openResource("some_name"); }