1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.basepom.mojo.duplicatefinder.classpath;
15
16 import java.util.List;
17 import java.util.Optional;
18
19 import org.junit.Test;
20
21 import static org.junit.Assert.assertFalse;
22 import static org.junit.Assert.assertTrue;
23
24 public class TestClasspathDescriptor {
25
26 @Test
27 public void testValidIdentifierNames() {
28 String[] validNames = {
29 "_.class",
30 "hello/world.class",
31 "test.class",
32 "__auto_generated/from/some/tool.class",
33 "some/inner$thing.class",
34 "some/package/package-info.class",
35 "package-info.class",
36 "some/package/module-info.class",
37 "module-info.class"
38 };
39
40 for (String test : validNames) {
41 Optional<List<String>> result = ClasspathDescriptor.validateClassName(test);
42 assertTrue("Failure for '" + test + "'", result.isPresent());
43 }
44 }
45
46 @Test
47 public void testInvalidIdentifierNames() {
48 String[] invalidNames = {
49 null,
50 "",
51 "/",
52 "hello.world",
53 "foo/hello.world",
54 "META-INF/test.class",
55 "2.0/foo.class",
56 "foo/bar/baz-blo/tst.class",
57 "META-INF/versions/9/foo/module-info.class",
58 "META-INF/versions/9/foo/package-info.class"
59 };
60
61
62 for (String test : invalidNames) {
63 Optional<List<String>> result = ClasspathDescriptor.validateClassName(test);
64 assertFalse("Failure for '" + test + "'", result.isPresent());
65 }
66 }
67
68 @Test
69 public void testMatchDefaultClassnames() {
70 String[] validClassNames = {
71 "foo$bar",
72 "hello.foo$bar",
73 "package-info",
74 "module-info",
75 "demo.package-info",
76 "foo.module-info"
77 };
78
79 for (String test : validClassNames) {
80 assertTrue("Failure for '" + test + "'", ClasspathDescriptor.DEFAULT_IGNORED_CLASS_PREDICATE.apply(test));
81 }
82 }
83
84 }