EMMA Coverage Report (generated Thu Sep 14 09:32:01 MDT 2006)
[all classes][biz.xsoftware.manifest]

COVERAGE SUMMARY FOR SOURCE FILE [TestManifestInfo.java]

nameclass, %method, %block, %line, %
TestManifestInfo.java100% (2/2)100% (15/15)97%  (219/226)98%  (59/60)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TestManifestInfo100% (1/1)100% (11/11)97%  (203/210)98%  (52/53)
setUp (): void 100% (1/1)68%  (13/19)80%  (4/5)
testRunMainClass (): void 100% (1/1)97%  (29/30)99%  (6/6)
TestManifestInfo (String): void 100% (1/1)100% (4/4)100% (2/2)
main (String []): void 100% (1/1)100% (8/8)100% (3/3)
testClassNotFound (): void 100% (1/1)100% (13/13)100% (4/4)
testExceptionFromMainClass (): void 100% (1/1)100% (14/14)100% (4/4)
testGetFile (): void 100% (1/1)100% (39/39)100% (8/8)
testGetMainClass (): void 100% (1/1)100% (23/23)100% (6/6)
testManifestInfo (): void 100% (1/1)100% (34/34)100% (7/7)
testNullClassName (): void 100% (1/1)100% (13/13)100% (4/4)
testTOOLSJAVAMain (): void 100% (1/1)100% (13/13)100% (4/4)
     
class TestManifestInfo$FakeJarLocator100% (1/1)100% (4/4)100% (16/16)100% (7/7)
TestManifestInfo$FakeJarLocator (File, String): void 100% (1/1)100% (9/9)100% (4/4)
exit (int): void 100% (1/1)100% (1/1)100% (1/1)
getFile (URL): File 100% (1/1)100% (3/3)100% (1/1)
getMainClass (Manifest): String 100% (1/1)100% (3/3)100% (1/1)

1/*
2 * Created on Sep 11, 2004
3 *
4 */
5package biz.xsoftware.manifest;
6 
7import java.io.File;
8import java.net.URL;
9import java.util.jar.Manifest;
10 
11import junit.framework.TestCase;
12 
13/**
14 * This is purely so emma always always reports code coverage 
15 * numbers on everything
16 */
17public class TestManifestInfo extends TestCase {
18 
19        private static final String DUMMY = "dummy";
20        
21        private File jarFile;
22        
23        /**
24         * @param arg0
25         */
26        public TestManifestInfo(String arg0) {
27                super(arg0);
28        }
29        public void setUp() {
30                String jarLoc = System.getProperty("jar.name");
31                if(jarLoc != null) //for tests run from ant
32                        jarFile = new File(jarLoc);
33                else //for tests run from eclipse
34                        jarFile = new File("output/jardist/projectname.jar");
35        }
36        
37        public void testManifestInfo() throws Throwable {
38                FakeJarLocator mock = new FakeJarLocator(jarFile, "should.not.matter.class");
39                
40                ManifestInfo.setJarLocator(mock);
41                
42                ManifestInfo.main(new String[] {"-version"});
43                
44                ManifestInfo.main(new String[] {"-manifest"});
45                
46                String version = new ManifestInfo().getVersion();
47                assertEquals("version from build.xml should equal version in jar", 
48                                                        System.getProperty("version"), version);
49        }
50        
51        public void testRunMainClass() throws Throwable {
52                FakeJarLocator mock = new FakeJarLocator(jarFile, TestManifestInfo.class.getName());
53                ManifestInfo.setJarLocator(mock);
54                ManifestInfo.main(new String[] {DUMMY});
55                
56                assertTrue("should have one argument", argsLen == 1);
57                assertEquals("variable should have been passed through", DUMMY, dummyArg);                
58        }
59        
60        public void testExceptionFromMainClass() throws Throwable {
61                FakeJarLocator mock = new FakeJarLocator(jarFile, ManifestUtilImpl.class.getName());
62                ManifestInfo.setJarLocator(mock);
63                ManifestInfo.main(new String[0]);
64        }
65        
66        public void testClassNotFound() throws Throwable {
67                FakeJarLocator mock = new FakeJarLocator(jarFile, "this.class.is.not.found");
68                ManifestInfo.setJarLocator(mock);
69                ManifestInfo.main(new String[0]);
70        }
71        public void testTOOLSJAVAMain() throws Throwable {
72                FakeJarLocator mock = new FakeJarLocator(jarFile, " TOOLS.JAVA.Main ");
73                ManifestInfo.setJarLocator(mock);
74                ManifestInfo.main(new String[0]);                
75        }
76        public void testNullClassName() throws Throwable {
77                FakeJarLocator mock = new FakeJarLocator(jarFile, null);
78                ManifestInfo.setJarLocator(mock);
79                ManifestInfo.main(new String[0]);                
80        }        
81        
82        public void testGetMainClass() {
83                Manifest mf = new Manifest();
84                mf.getMainAttributes().putValue("SubMain-Class", "   xx   ");
85                ManifestUtilImpl util = new ManifestUtilImpl();
86                String s = util.getMainClass(mf);
87                assertEquals("should have trimmed the value", "xx", s);
88        }
89        
90        public void testGetFile() throws Exception {                
91                File f = jarFile;
92                assertTrue("file should exist before we test this", f.exists());
93                URL url = f.toURL();
94                URL urlToClassFile = new URL("file", null, -1, url+"!/biz/xsoftware/buildtemplate/Util.class");
95                File tmp = new ManifestUtilImpl().getFile(urlToClassFile);
96                
97                assertNotNull("Should return a real file", tmp);
98                assertTrue("file should still exist", tmp.exists());
99        }
100        
101        private static class FakeJarLocator implements ManifestInfo.ManifestUtil {
102                private File file;
103                private String mainClass;
104                public FakeJarLocator(File f, String mainClass) {
105                        this.file = f;
106                        this.mainClass = mainClass;
107                }
108                public File getFile(URL url) {
109                        return file;
110                }
111                public void exit(int code) {
112                        //do nothing!!!
113                }
114                public String getMainClass(Manifest manifest) {
115                        return mainClass;
116                }                
117        }
118        
119        //dummy main method for testing!!!
120        public static void main(String[] args) {
121                argsLen = args.length;
122                dummyArg = args[0];
123        }
124        private static int argsLen;
125        private static String dummyArg;
126}

[all classes][biz.xsoftware.manifest]
EMMA 2.0.4217 (C) Vladimir Roubtsov