Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-10.0.x
Browse files Browse the repository at this point in the history
Signed-off-by: gregw <gregw@webtide.com>
  • Loading branch information
gregw committed Oct 28, 2020
2 parents 651f23e + 6698a31 commit c793b54
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Expand Up @@ -26,6 +26,7 @@
import java.net.URI;
import java.nio.channels.ReadableByteChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -416,14 +417,17 @@ public long length()
public String[] list()
{
assertResourcesSet();

HashSet<String> set = new HashSet<>();
for (Resource r : _resources)
{
Collections.addAll(set, r.list());
String[] list = r.list();
if (list != null)
Collections.addAll(set, list);
}

return (String[])set.stream().sorted().toArray();
String[] result = set.toArray(new String[0]);
Arrays.sort(result);
return result;
}

@Override
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Path;
import java.util.Arrays;

import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
Expand All @@ -33,7 +34,10 @@
import org.junit.jupiter.api.extension.ExtendWith;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.emptyArray;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -175,6 +179,19 @@ private void assertThrowIllegalStateException(ResourceCollection coll)
});
}

@Test
public void testList() throws Exception
{
ResourceCollection rc1 = new ResourceCollection(
Resource.newResource("src/test/resources/org/eclipse/jetty/util/resource/one/"),
Resource.newResource("src/test/resources/org/eclipse/jetty/util/resource/two/"),
Resource.newResource("src/test/resources/org/eclipse/jetty/util/resource/three/"));

assertThat(Arrays.asList(rc1.list()), contains("1.txt", "2.txt", "3.txt", "dir/"));
assertThat(Arrays.asList(rc1.addPath("dir").list()), contains("1.txt", "2.txt", "3.txt"));
assertThat(rc1.addPath("unknown").list(), emptyArray());
}

@Test
public void testMultipleSources1() throws Exception
{
Expand Down

0 comments on commit c793b54

Please sign in to comment.