Skip to content

Commit

Permalink
Prune duplicate elements in resources
Browse files Browse the repository at this point in the history
Prior to this commit a list with potential duplicates is generated
and verified when loading the `junit-platform.properties` file.

Addresses #2207
  • Loading branch information
sormuras committed Mar 20, 2020
1 parent edcbd81 commit 828cdb3
Showing 1 changed file with 4 additions and 3 deletions.
Expand Up @@ -14,10 +14,11 @@
import java.net.URL;
import java.net.URLConnection;
import java.util.Collections;
import java.util.List;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;

import org.junit.platform.commons.logging.Logger;
import org.junit.platform.commons.logging.LoggerFactory;
Expand Down Expand Up @@ -52,7 +53,7 @@ private static Properties fromClasspathResource(String configFileName) {

try {
ClassLoader classLoader = ClassLoaderUtils.getDefaultClassLoader();
List<URL> resources = Collections.list(classLoader.getResources(configFileName));
Set<URL> resources = new HashSet<>(Collections.list(classLoader.getResources(configFileName)));

This comment has been minimized.

Copy link
@marcphilipp

marcphilipp Mar 21, 2020

Member

@sormuras This should be a LinkedHashSet to preserve the original order, shouldn't it?

This comment has been minimized.

Copy link
@sormuras

sormuras Mar 21, 2020

Author Member

As we're interested in the singleton case, I thought that preserving order was not important.

This comment has been minimized.

Copy link
@marcphilipp

marcphilipp Mar 21, 2020

Member

We should still use the same on we were using before.

This comment has been minimized.

Copy link
@sbrannen

sbrannen Mar 21, 2020

Member

Indeed, we should still be taking the first one as previously.

Though, TBH, I'm not sure if the order in which they are returned by getResources() is deterministic, but just in case it is (potentially only for certain JDKs), we should maintain the existing behavior.


if (!resources.isEmpty()) {
if (resources.size() > 1) {
Expand All @@ -61,7 +62,7 @@ private static Properties fromClasspathResource(String configFileName) {
resources.size(), configFileName));
}

URL configFileUrl = resources.get(0);
URL configFileUrl = resources.iterator().next(); // same as List#get(0)
logger.info(() -> String.format(
"Loading JUnit Platform configuration parameters from classpath resource [%s].", configFileUrl));
URLConnection urlConnection = configFileUrl.openConnection();
Expand Down

0 comments on commit 828cdb3

Please sign in to comment.