Clover Coverage Report
Coverage timestamp: Sat Sep 18 2010 04:09:52 UTC
25   113   6   5
2   54   0.24   5
5     1.2  
1    
 
  ResourceLoaderUtilityTest       Line # 33 25 6 93.8% 0.9375
 
  (3)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2010, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
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    * Test {@link ResourceLoaderUtility}.
29    *
30    * @version $Revision: 1.1 $
31    * @author Michael Meyling
32    */
 
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 TestCase#setUp()
39    */
 
40  3 toggle protected void setUp() throws Exception {
41  3 super.setUp();
42    }
43   
44    /*
45    * @see TestCase#tearDown()
46    */
 
47  3 toggle protected void tearDown() throws Exception {
48  3 super.tearDown();
49    }
50   
51    /**
52    * Test {@link ResourceLoaderUtility#getResourceFile(java.io.File, String, String)}.
53    * TODO mime 2009??????614: This test must be run against a jar file!
54    *
55    * @throws Exception Test failure.
56    */
 
57  1 toggle 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    // long lastModifiedBefore = file.lastModified();
76    // System.out.println(lastModifiedBefore);
77  1 IoUtility.saveFileBinary(file, IoUtility.loadFileBinary(file));
78  1 long lastModifiedAfter = file.lastModified();
79    // System.out.println(lastModifiedAfter);
80  1 file = ResourceLoaderUtility.getResourceFile(new File("."), directory,
81    shortName + ".class");
82  1 assertEquals(lastModifiedAfter, file.lastModified());
83    }
84   
85    /**
86    * Test {@link ResourceLoaderUtility#getResourceUrl(String)}.
87    *
88    * @throws Exception Test failure.
89    */
 
90  1 toggle public void testGetResourceUrl() throws Exception {
91  1 String name = ResourceLoaderUtilityTest.class.getName().replace('.', '/') + ".class";
92    // System.out.println(name);
93  1 final URL url = ResourceLoaderUtility.getResourceUrl(name);
94    // System.out.println(url);
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    * Test {@link ResourceLoaderUtility#getResourceAsStream(String)}.
102    *
103    * @throws Exception Test failure.
104    */
 
105  1 toggle public void testGetResourceAsStream() throws Exception {
106  1 String name = ResourceLoaderUtilityTest.class.getName().replace('.', '/') + ".class";
107    // System.out.println(name);
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    }