• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
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
testConstructor()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
testPackageToPath()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
testPathToPackage()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
testToFullyQualifiedNameNullClassString()59     public void testToFullyQualifiedNameNullClassString() {
60         assertThrows(NullPointerException.class,
61                 () -> ClassPathUtils.toFullyQualifiedName((Class<?>) null, "Test.properties"));
62     }
63 
64     @Test
testToFullyQualifiedNameClassNull()65     public void testToFullyQualifiedNameClassNull() {
66         assertThrows(NullPointerException.class, () -> ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class, null));
67     }
68 
69     @Test
testToFullyQualifiedNameClassString()70     public void testToFullyQualifiedNameClassString() {
71         final String expected = "org.apache.commons.lang3.Test.properties";
72         final String actual = ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class, "Test.properties");
73 
74         assertEquals(expected, actual);
75     }
76 
77     @Test
testToFullyQualifiedNameNullPackageString()78     public void testToFullyQualifiedNameNullPackageString() {
79         assertThrows(NullPointerException.class,
80                 () -> ClassPathUtils.toFullyQualifiedName((Package) null, "Test.properties"));
81     }
82 
83     @Test
testToFullyQualifiedNamePackageNull()84     public void testToFullyQualifiedNamePackageNull() {
85         assertThrows(NullPointerException.class,
86                 () -> ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class.getPackage(), null));
87     }
88 
89     @Test
testToFullyQualifiedNamePackageString()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
testToFullyQualifiedPathClassNullString()98     public void testToFullyQualifiedPathClassNullString() {
99         assertThrows(NullPointerException.class,
100                 () -> ClassPathUtils.toFullyQualifiedPath((Class<?>) null, "Test.properties"));
101     }
102 
103     @Test
testToFullyQualifiedPathClassNull()104     public void testToFullyQualifiedPathClassNull() {
105         assertThrows(NullPointerException.class, () -> ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class, null));
106     }
107 
108     @Test
testToFullyQualifiedPathClass()109     public void testToFullyQualifiedPathClass() {
110         final String expected = "org/apache/commons/lang3/Test.properties";
111         final String actual = ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class, "Test.properties");
112 
113         assertEquals(expected, actual);
114     }
115 
116     @Test
testToFullyQualifiedPathPackageNullString()117     public void testToFullyQualifiedPathPackageNullString() {
118         assertThrows(NullPointerException.class,
119                 () -> ClassPathUtils.toFullyQualifiedPath((Package) null, "Test.properties"));
120     }
121 
122     @Test
testToFullyQualifiedPathPackageNull()123     public void testToFullyQualifiedPathPackageNull() {
124         assertThrows(NullPointerException.class,
125                 () -> ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class.getPackage(), null));
126     }
127 
128     @Test
testToFullyQualifiedPathPackage()129     public void testToFullyQualifiedPathPackage() {
130         final String expected = "org/apache/commons/lang3/Test.properties";
131         final String actual = ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class.getPackage(), "Test.properties");
132 
133         assertEquals(expected, actual);
134     }
135 }
136