1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.qedeq.base.io; |
17 |
|
|
18 |
|
import java.io.File; |
19 |
|
import java.io.InputStream; |
20 |
|
import java.net.URL; |
21 |
|
|
22 |
|
import org.qedeq.base.test.QedeqTestCase; |
23 |
|
import org.qedeq.base.utility.StringUtility; |
24 |
|
|
25 |
|
|
26 |
|
@link |
27 |
|
|
28 |
|
@author |
29 |
|
|
|
|
| 93.9% |
Uncovered Elements: 2 (33) |
Complexity: 6 |
Complexity Density: 0.23 |
|
30 |
|
public class ResourceLoaderUtilityTest extends QedeqTestCase { |
31 |
|
|
32 |
|
private static final String ONCE_THE_COW_JUMPED_OVER_THE_MOON = "once=the cow jumped over the moon"; |
33 |
|
|
34 |
|
|
35 |
|
@see |
36 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
37 |
3
|
protected void setUp() throws Exception {... |
38 |
3
|
super.setUp(); |
39 |
|
} |
40 |
|
|
41 |
|
|
42 |
|
@see |
43 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
44 |
3
|
protected void tearDown() throws Exception {... |
45 |
3
|
super.tearDown(); |
46 |
|
} |
47 |
|
|
48 |
|
|
49 |
|
@link |
50 |
|
|
51 |
|
|
52 |
|
@throws |
53 |
|
|
|
|
| 88.9% |
Uncovered Elements: 2 (18) |
Complexity: 2 |
Complexity Density: 0.12 |
1
PASS
|
|
54 |
1
|
public void testGetResourceFile() throws Exception {... |
55 |
1
|
File file = new File("./ResourceLoaderUtilityTestFile.txt"); |
56 |
1
|
if (file.exists()) { |
57 |
0
|
assertTrue(file.delete()); |
58 |
|
} |
59 |
1
|
file.createNewFile(); |
60 |
1
|
IoUtility.saveFile(file, ONCE_THE_COW_JUMPED_OVER_THE_MOON, |
61 |
|
IoUtility.getDefaultEncoding()); |
62 |
1
|
assertEquals(ONCE_THE_COW_JUMPED_OVER_THE_MOON, IoUtility.loadFile( |
63 |
|
ResourceLoaderUtility.getResourceFile(new File("."), ".", |
64 |
|
"ResourceLoaderUtilityTestFile.txt").toString(), IoUtility.getDefaultEncoding())); |
65 |
1
|
String name = ResourceLoaderUtility.class.getName(); |
66 |
1
|
String shortName = StringUtility.getClassName(ResourceLoaderUtility.class); |
67 |
1
|
final String directory = name.substring(0, |
68 |
|
name.length() - shortName.length()).replace('.', '/'); |
69 |
1
|
file.delete(); |
70 |
1
|
file = ResourceLoaderUtility.getResourceFile(new File("."), directory, |
71 |
|
shortName + ".class"); |
72 |
|
|
73 |
|
|
74 |
1
|
IoUtility.saveFileBinary(file, IoUtility.loadFileBinary(file)); |
75 |
1
|
long lastModifiedAfter = file.lastModified(); |
76 |
|
|
77 |
1
|
file = ResourceLoaderUtility.getResourceFile(new File("."), directory, |
78 |
|
shortName + ".class"); |
79 |
1
|
assertEquals(lastModifiedAfter, file.lastModified()); |
80 |
|
|
81 |
1
|
IoUtility.deleteDir(new File("org"), true); |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
@link |
86 |
|
|
87 |
|
@throws |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1
PASS
|
|
89 |
1
|
public void testGetResourceUrl() throws Exception {... |
90 |
1
|
String name = ResourceLoaderUtilityTest.class.getName().replace('.', '/') + ".class"; |
91 |
|
|
92 |
1
|
final URL url = ResourceLoaderUtility.getResourceUrl(name); |
93 |
|
|
94 |
1
|
final StringBuffer buffer = new StringBuffer(); |
95 |
1
|
IoUtility.loadFile(url, buffer, IoUtility.getDefaultEncoding()); |
96 |
1
|
assertTrue(buffer.toString().indexOf(ONCE_THE_COW_JUMPED_OVER_THE_MOON) >= 0); |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
|
@link |
101 |
|
|
102 |
|
@throws |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
104 |
1
|
public void testGetResourceAsStream() throws Exception {... |
105 |
1
|
String name = ResourceLoaderUtilityTest.class.getName().replace('.', '/') + ".class"; |
106 |
|
|
107 |
1
|
final InputStream stream = ResourceLoaderUtility.getResourceAsStream(name); |
108 |
1
|
assertTrue(IoUtility.loadStreamWithoutException(stream, 30000).indexOf( |
109 |
|
ONCE_THE_COW_JUMPED_OVER_THE_MOON) >= 0); |
110 |
|
} |
111 |
|
|
112 |
|
} |