|
32 | 32 | package org.scijava.annotations; |
33 | 33 |
|
34 | 34 | import static org.junit.Assert.assertEquals; |
| 35 | +import static org.junit.Assert.assertFalse; |
35 | 36 | import static org.junit.Assert.assertNotNull; |
36 | 37 | import static org.junit.Assert.assertTrue; |
37 | 38 | import static org.junit.Assume.assumeTrue; |
|
40 | 41 | import java.io.IOException; |
41 | 42 | import java.lang.annotation.Annotation; |
42 | 43 | import java.net.URL; |
| 44 | +import java.net.URLClassLoader; |
43 | 45 | import java.net.URLConnection; |
44 | 46 | import java.util.ArrayList; |
45 | 47 | import java.util.Collections; |
46 | 48 | import java.util.Enumeration; |
| 49 | +import java.util.HashSet; |
47 | 50 | import java.util.List; |
48 | 51 | import java.util.Map; |
| 52 | +import java.util.Set; |
49 | 53 | import java.util.TreeMap; |
50 | 54 |
|
51 | 55 | import org.junit.Test; |
@@ -89,6 +93,26 @@ public void testIndexer() throws Exception { |
89 | 93 | testDefaultAnnotations(map); |
90 | 94 | } |
91 | 95 |
|
| 96 | + @Test |
| 97 | + public void testRepeatedClassPathElements() throws Exception { |
| 98 | + final String suffix = getResourcePath(AnnotatedA.class); |
| 99 | + final String classURL = |
| 100 | + getClass().getResource("/" + suffix).toString(); |
| 101 | + final URL classPathURL = new URL(classURL.substring(0, |
| 102 | + classURL.length() - suffix.length())); |
| 103 | + final ClassLoader loader = new URLClassLoader(new URL[] { |
| 104 | + classPathURL, classPathURL |
| 105 | + }); |
| 106 | + final Set<String> seen = new HashSet<String>(); |
| 107 | + for (final IndexItem<Simple> item : |
| 108 | + Index.load(Simple.class, loader)) { |
| 109 | + final String name = item.className(); |
| 110 | + assertFalse(seen.contains(name)); |
| 111 | + seen.add(name); |
| 112 | + } |
| 113 | + assertEquals(2, seen.size()); |
| 114 | + } |
| 115 | + |
92 | 116 | public static void |
93 | 117 | testDefaultAnnotations(Map<String, IndexItem<Complex>> map) |
94 | 118 | { |
|
0 commit comments