|
26 | 26 | import java.io.ByteArrayInputStream;
|
27 | 27 | import java.io.File;
|
28 | 28 | import java.io.FileOutputStream;
|
| 29 | +import java.io.IOException; |
29 | 30 | import java.io.StringWriter;
|
30 | 31 | import java.nio.file.Files;
|
31 | 32 | import java.text.SimpleDateFormat;
|
32 | 33 | import java.util.Arrays;
|
| 34 | +import java.util.Collections; |
33 | 35 | import java.util.List;
|
34 | 36 | import javax.xml.parsers.DocumentBuilder;
|
35 | 37 | import javax.xml.parsers.DocumentBuilderFactory;
|
36 | 38 | import org.junit.After;
|
37 | 39 | import org.junit.Before;
|
38 | 40 | import org.junit.Test;
|
39 | 41 | import org.opengrok.indexer.configuration.RuntimeEnvironment;
|
| 42 | +import org.opengrok.indexer.history.HistoryException; |
40 | 43 | import org.opengrok.indexer.history.RepositoryFactory;
|
| 44 | +import org.opengrok.indexer.search.DirectoryEntry; |
| 45 | +import org.opengrok.indexer.web.EftarFileReader; |
41 | 46 | import org.w3c.dom.Document;
|
42 | 47 | import org.w3c.dom.Element;
|
43 | 48 | import org.w3c.dom.Node;
|
|
47 | 52 | import static org.junit.Assert.assertNotNull;
|
48 | 53 | import static org.junit.Assert.assertTrue;
|
49 | 54 | import static org.junit.Assert.fail;
|
| 55 | +import static org.mockito.ArgumentMatchers.anyString; |
| 56 | +import static org.mockito.Mockito.mock; |
| 57 | +import static org.mockito.Mockito.when; |
50 | 58 |
|
51 | 59 | /**
|
52 | 60 | * JUnit test to test that the DirectoryListing produce the expected result.
|
@@ -365,4 +373,14 @@ public void directoryListing() throws Exception {
|
365 | 373 | validateEntry((Element) nl.item(i));
|
366 | 374 | }
|
367 | 375 | }
|
| 376 | + |
| 377 | + @Test |
| 378 | + public void directoryListingWithEftarException() throws IOException, HistoryException { |
| 379 | + EftarFileReader mockReader = mock(EftarFileReader.class); |
| 380 | + when(mockReader.getNode(anyString())).thenThrow(IOException.class); |
| 381 | + DirectoryListing instance = new DirectoryListing(mockReader); |
| 382 | + File file = new File(directory, "foo"); |
| 383 | + instance.extraListTo("ctx", directory, new StringWriter(), directory.getPath(), |
| 384 | + Collections.singletonList(new DirectoryEntry(file))); |
| 385 | + } |
368 | 386 | }
|
0 commit comments