1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.lang3;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertFalse;
21 import static org.junit.jupiter.api.Assertions.assertNotNull;
22 import static org.junit.jupiter.api.Assertions.assertThrows;
23 import static org.junit.jupiter.api.Assertions.assertTrue;
24
25 import java.lang.reflect.Constructor;
26 import java.lang.reflect.Modifier;
27
28 import org.junit.jupiter.api.Test;
29
30
31
32 public class ClassPathUtilsTest extends AbstractLangTest {
33
34 @Test
35 public void testConstructor() {
36 assertNotNull(new ClassPathUtils());
37 final Constructor<?>[] cons = ClassPathUtils.class.getDeclaredConstructors();
38 assertEquals(1, cons.length);
39 assertTrue(Modifier.isPublic(cons[0].getModifiers()));
40 assertTrue(Modifier.isPublic(ClassPathUtils.class.getModifiers()));
41 assertFalse(Modifier.isFinal(ClassPathUtils.class.getModifiers()));
42 }
43
44 @Test
45 public void testPackageToPath() {
46 assertEquals("a", ClassPathUtils.packageToPath("a"));
47 assertEquals("a/b", ClassPathUtils.packageToPath("a.b"));
48 assertEquals("a/b/c", ClassPathUtils.packageToPath("a.b.c"));
49 }
50
51 @Test
52 public void testPathToPackage() {
53 assertEquals("a", ClassPathUtils.pathToPackage("a"));
54 assertEquals("a.b", ClassPathUtils.pathToPackage("a/b"));
55 assertEquals("a.b.c", ClassPathUtils.pathToPackage("a/b/c"));
56 }
57
58 @Test
59 public void testToFullyQualifiedNameClassNull() {
60 assertThrows(NullPointerException.class, () -> ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class, null));
61 }
62
63 @Test
64 public void testToFullyQualifiedNameClassString() {
65 final String expected = "org.apache.commons.lang3.Test.properties";
66 final String actual = ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class, "Test.properties");
67
68 assertEquals(expected, actual);
69 }
70
71 @Test
72 public void testToFullyQualifiedNameNullClassString() {
73 assertThrows(NullPointerException.class,
74 () -> ClassPathUtils.toFullyQualifiedName((Class<?>) null, "Test.properties"));
75 }
76
77 @Test
78 public void testToFullyQualifiedNameNullPackageString() {
79 assertThrows(NullPointerException.class,
80 () -> ClassPathUtils.toFullyQualifiedName((Package) null, "Test.properties"));
81 }
82
83 @Test
84 public void testToFullyQualifiedNamePackageNull() {
85 assertThrows(NullPointerException.class,
86 () -> ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class.getPackage(), null));
87 }
88
89 @Test
90 public void testToFullyQualifiedNamePackageString() {
91 final String expected = "org.apache.commons.lang3.Test.properties";
92 final String actual = ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class.getPackage(), "Test.properties");
93
94 assertEquals(expected, actual);
95 }
96
97 @Test
98 public void testToFullyQualifiedPathClass() {
99 final String expected = "org/apache/commons/lang3/Test.properties";
100 final String actual = ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class, "Test.properties");
101
102 assertEquals(expected, actual);
103 }
104
105 @Test
106 public void testToFullyQualifiedPathClassNull() {
107 assertThrows(NullPointerException.class, () -> ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class, null));
108 }
109
110 @Test
111 public void testToFullyQualifiedPathClassNullString() {
112 assertThrows(NullPointerException.class,
113 () -> ClassPathUtils.toFullyQualifiedPath((Class<?>) null, "Test.properties"));
114 }
115
116 @Test
117 public void testToFullyQualifiedPathPackage() {
118 final String expected = "org/apache/commons/lang3/Test.properties";
119 final String actual = ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class.getPackage(), "Test.properties");
120
121 assertEquals(expected, actual);
122 }
123
124 @Test
125 public void testToFullyQualifiedPathPackageNull() {
126 assertThrows(NullPointerException.class,
127 () -> ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class.getPackage(), null));
128 }
129
130 @Test
131 public void testToFullyQualifiedPathPackageNullString() {
132 assertThrows(NullPointerException.class,
133 () -> ClassPathUtils.toFullyQualifiedPath((Package) null, "Test.properties"));
134 }
135 }