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