1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.io;
17
18 import static org.junit.jupiter.api.Assertions.assertNotNull;
19 import static org.junit.jupiter.api.Assertions.assertNull;
20
21 import org.apache.ibatis.BaseDataTest;
22 import org.junit.jupiter.api.Assertions;
23 import org.junit.jupiter.api.BeforeEach;
24 import org.junit.jupiter.api.Test;
25
26 class ClassLoaderWrapperTest extends BaseDataTest {
27
28 private ClassLoaderWrapper wrapper;
29 private ClassLoader loader;
30 private final String RESOURCE_NOT_FOUND = "some_resource_that_does_not_exist.properties";
31 private final String CLASS_NOT_FOUND = "some.random.class.that.does.not.Exist";
32 private final String CLASS_FOUND = "java.lang.Object";
33
34 @BeforeEach
35 void beforeClassLoaderWrapperTest() {
36 wrapper = new ClassLoaderWrapper();
37 loader = getClass().getClassLoader();
38 }
39
40 @Test
41 void classForName() throws ClassNotFoundException {
42 assertNotNull(wrapper.classForName(CLASS_FOUND));
43 }
44
45 @Test
46 void classForNameNotFound() {
47 Assertions.assertThrows(ClassNotFoundException.class, () -> assertNotNull(wrapper.classForName(CLASS_NOT_FOUND)));
48 }
49
50 @Test
51 void classForNameWithClassLoader() throws ClassNotFoundException {
52 assertNotNull(wrapper.classForName(CLASS_FOUND, loader));
53 }
54
55 @Test
56 void getResourceAsURL() {
57 assertNotNull(wrapper.getResourceAsURL(JPETSTORE_PROPERTIES));
58 }
59
60 @Test
61 void getResourceAsURLNotFound() {
62 assertNull(wrapper.getResourceAsURL(RESOURCE_NOT_FOUND));
63 }
64
65 @Test
66 void getResourceAsURLWithClassLoader() {
67 assertNotNull(wrapper.getResourceAsURL(JPETSTORE_PROPERTIES, loader));
68 }
69
70 @Test
71 void getResourceAsStream() {
72 assertNotNull(wrapper.getResourceAsStream(JPETSTORE_PROPERTIES));
73 }
74
75 @Test
76 void getResourceAsStreamNotFound() {
77 assertNull(wrapper.getResourceAsStream(RESOURCE_NOT_FOUND));
78 }
79
80 @Test
81 void getResourceAsStreamWithClassLoader() {
82 assertNotNull(wrapper.getResourceAsStream(JPETSTORE_PROPERTIES, loader));
83 }
84
85 }