Skip to content

Commit

Permalink
Issue #5137 - Restoring clashing resource test
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed Sep 21, 2020
1 parent 8166f7f commit f5a8995
Showing 1 changed file with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;

import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
Expand All @@ -38,11 +39,11 @@

import static org.eclipse.jetty.toolchain.test.ExtraMatchers.ordered;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
Expand Down Expand Up @@ -346,23 +347,19 @@ public void testClashingResource() throws Exception
// The existence of a URLStreamHandler changes the behavior
assumeTrue(URLStreamHandlerUtil.getFactory() == null, "URLStreamHandler changes behavior, skip test");

// This cannot test order of resources from the URLClassLoader, as there is no
// guarantee of order from any Java ClassLoader.
// It can only test if both resources are being returned (in any order).

List<URL> resources = Collections.list(_loader.getResources("org/acme/clashing.txt"));
assertThat("Resource clashing count", resources.size(), is(2));

for (URL url : resources)
Enumeration<URL> resources = _loader.getResources("org/acme/clashing.txt");
assertTrue(resources.hasMoreElements());
URL resource = resources.nextElement();
try (InputStream data = resource.openStream())
{
try (InputStream data = url.openStream())
{
assertThat("correct contents of " + url, IO.toString(data),
anyOf(
is("alpha"),
is("omega")
));
}
assertThat("correct contents of " + resource, IO.toString(data), is("alpha"));
}
assertTrue(resources.hasMoreElements());
resource = resources.nextElement();
try (InputStream data = resource.openStream())
{
assertThat("correct contents of " + resource, IO.toString(data), is("omega"));
}
assertFalse(resources.hasMoreElements());
}
}

0 comments on commit f5a8995

Please sign in to comment.