@Test public void testDirListing() throws IOException { when(request.resolvePath()).thenReturn(tempDir.resolve("some-dir")); when(request.getUri()).thenReturn("/some-dir"); assertTrue(new DirectoryListing().process(request, response)); assertEquals(readResource("/directory-listing/some-dir.html"), stringWriter.toString()); }
@Before public void setup() throws IOException { stringWriter = new StringWriter(); tempDir = Files.createTempDirectory("jhttp-test"); request = mock(HttpRequest.class); when(request.resolvePath()).thenReturn(tempDir); when(request.getUri()).thenReturn("/"); response = mock(HttpResponse.class); when(response.getPrintWriter()).thenReturn(new PrintWriter(stringWriter)); Files.write(tempDir.resolve("file1"), "test123".getBytes()); Files.write(tempDir.resolve("file2"), "test123".getBytes()); Files.write(tempDir.resolve("file3"), "test123".getBytes()); Files.createDirectories(tempDir.resolve("some-dir")); Files.write(tempDir.resolve("some-dir/xyz"), "test123".getBytes()); }