File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed
java/test/com/github/bazel_contrib/contrib_rules_jvm/junit5 Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ java_test_suite(
4343 artifact ("org.mockito:mockito-core" , "contrib_rules_jvm_tests" ),
4444 artifact ("org.opentest4j:opentest4j" , "contrib_rules_jvm_tests" ),
4545 ] + junit5_vintage_deps ("contrib_rules_jvm_tests" ),
46+ resources = glob (["resources/*" ])
4647)
4748
4849java_test_suite (
Original file line number Diff line number Diff line change 1+ package com .github .bazel_contrib .contrib_rules_jvm .junit5 ;
2+
3+ import org .junit .jupiter .api .Test ;
4+
5+ import java .io .File ;
6+ import java .io .IOException ;
7+ import java .util .ArrayList ;
8+ import java .util .List ;
9+ import java .util .concurrent .atomic .AtomicInteger ;
10+ import java .util .zip .ZipFile ;
11+
12+ import static org .junit .jupiter .api .Assertions .assertEquals ;
13+ import static org .junit .jupiter .api .Assertions .fail ;
14+
15+ public class JavaTestSuiteTest {
16+
17+ @ Test
18+ public void testClasspathDoesNotContainDuplicateResources () throws IOException {
19+ final String resourceName = "duplicate_resource_test.txt" ;
20+ String [] classpath = System .getProperty ("java.class.path" ).split (":" );
21+ List <String > resourcesFound = new ArrayList <>();
22+ for (String entry : classpath ) {
23+ if (entry .endsWith (".jar" )) {
24+ try (ZipFile zipfile = new ZipFile (new File (entry ))) {
25+ zipfile .entries ().asIterator ().forEachRemaining (zipEntry -> {
26+ if (zipEntry .getName ().endsWith (resourceName )) {
27+ resourcesFound .add (entry );
28+ }
29+ });
30+ }
31+ } else {
32+ fail ("Classpath contains non-jar files" );
33+ }
34+ }
35+ assertEquals (1 , resourcesFound .size (),
36+ "Expected a single instance of a resource to be on the classpath, instead found entries in: " + resourcesFound );
37+ }
38+ }
Original file line number Diff line number Diff line change 1+ Simple resource to validate suites only pick up a single resource
You can’t perform that action at this time.
0 commit comments