### Question:
AMSetupUtils { public static InputStream getResourceAsStream(ServletContext servletContext, String file) { if (servletContext == null) { if (file.startsWith("/")) { file = file.substring(1); } return Thread.currentThread().getContextClassLoader().getResourceAsStream(file); } else { return servletContext.getResourceAsStream(file); } } private  AMSetupUtils(); static String readFile(ServletContext servletContext, String file); static String getRandomString(); static int getFirstUnusedPort(String hostname, int start, int increment); static boolean isPortInUse(String hostname, int port); static Map<String, String> getRemoteServerInfo(String serverUrl, String userId, String password); static InputStream getResourceAsStream(ServletContext servletContext, String file);  }### Answer:
@Test public void shouldGetResourceAsStreamUsingServletContext() { ServletContext context = mock(ServletContext.class); String file = "AMSetupUtilsTestFile.txt"; getResourceAsStream(context, file); verify(context).getResourceAsStream(file); }
@Test public void shouldGetResourceAsStreamUsingClassLoader() throws IOException { String file = "/AMSetupUtilsTestFile.txt"; InputStream stream = getResourceAsStream(null, file); assertThat(IOUtils.readStream(stream)).isEqualTo("FILE_CONTENTS\n"); }