Changes for checkstyle 8.32
[policy/apex-pdp.git] / core / core-infrastructure / src / test / java / org / onap / policy / apex / core / infrastructure / java / classes / ClassUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (c) 2020 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * 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  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.core.infrastructure.java.classes;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
25
26 import java.io.File;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.util.Set;
30 import java.util.TreeSet;
31 import org.junit.Test;
32 import org.mockito.Mockito;
33
34 public class ClassUtilsTest {
35
36     @Test
37     public void testGetClassNames() throws IOException {
38         InputStream input = null;
39         ClassUtils.getClassNames();
40         assertEquals(new TreeSet<>(), ClassUtils.processJar(input));
41     }
42
43     @Test
44     public void testProcessFileName() {
45         assertEquals("testing.txt", ClassUtils.processFileName("testing.txt"));
46         assertNull(ClassUtils.processFileName(null));
47         assertEquals("", ClassUtils.processFileName("/classes/"));
48     }
49
50     @Test
51     public void testProcessDir() throws Exception {
52         File mockFile = Mockito.mock(File.class);
53         Mockito.when(mockFile.isDirectory()).thenReturn(false);
54         assertEquals(new TreeSet<>(), ClassUtils.processDir(mockFile, "Here"));
55         assertEquals(new TreeSet<>(), ClassUtils.processDir(null, "Test"));
56         Mockito.when(mockFile.isDirectory()).thenReturn(true);
57
58         File mockChildFile = Mockito.mock(File.class);
59         File[] files = {mockChildFile};
60         Mockito.when(mockFile.listFiles()).thenReturn(files);
61         Mockito.when(mockChildFile.getName()).thenReturn("test.class");
62         Mockito.when(mockChildFile.getAbsolutePath()).thenReturn("/test/");
63         assertEquals(Set.of(".test."), ClassUtils.processDir(mockFile, "Here"));
64         Mockito.when(mockChildFile.getName()).thenReturn("test.class");
65         assertEquals(Set.of(".test."), ClassUtils.processDir(mockFile, "Here"));
66         Mockito.when(mockChildFile.getName()).thenReturn("$test.class");
67         assertEquals(new TreeSet<>(), ClassUtils.processDir(mockFile, "Here"));
68     }
69
70 }