EMMA Coverage Report (generated Fri Jul 28 01:51:09 CEST 2006)
[all classes][org.jtiger.report.html]

COVERAGE SUMMARY FOR SOURCE FILE [FixtureHtmlFileWriterFactory.java]

nameclass, %method, %block, %line, %
FixtureHtmlFileWriterFactory.java100% (2/2)100% (4/4)75%  (153/204)80%  (35/44)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class FixtureHtmlFileWriterFactory100% (1/1)100% (2/2)100% (7/7)100% (3/3)
FixtureHtmlFileWriterFactory (): void 100% (1/1)100% (3/3)100% (2/2)
newFixtureHtmlFileWriter (): FixtureHtmlFileWriter 100% (1/1)100% (4/4)100% (1/1)
     
class FixtureHtmlFileWriterFactory$FixtureHtmlFileWriterImpl100% (1/1)100% (2/2)74%  (146/197)78%  (32/41)
FixtureHtmlFileWriterFactory$FixtureHtmlFileWriterImpl (): void 100% (1/1)100% (3/3)100% (2/2)
writeFixtureHtml (FixtureResults, File, FilenamePolicy, String): void 100% (1/1)74%  (143/194)77%  (30/39)

1/*
2 * JTiger Unit Testing Framework for J2SE 1.5
3 * Copyright (C) 2005 Tony Morris
4 *
5 * This software is licenced under the
6 * Common Public Licence version 1.0
7 * http://www.opensource.org/licenses/cpl1.0.php
8 *
9 * You received a copy of this licence with this software.
10 */
11package org.jtiger.report.html;
12 
13import java.beans.XMLEncoder;
14import java.io.ByteArrayInputStream;
15import java.io.ByteArrayOutputStream;
16import java.io.File;
17import java.io.FileNotFoundException;
18import java.io.FileOutputStream;
19import java.io.IOException;
20import java.io.InputStream;
21import java.io.OutputStream;
22import javax.xml.transform.Transformer;
23import javax.xml.transform.TransformerConfigurationException;
24import javax.xml.transform.TransformerException;
25import javax.xml.transform.TransformerFactory;
26import javax.xml.transform.stream.StreamResult;
27import javax.xml.transform.stream.StreamSource;
28import org.jtiger.framework.FixtureResultsHandlerException;
29 
30final class FixtureHtmlFileWriterFactory
31{
32    private static final String XSL_RESOURCE = "/org/jtiger/report/xsl/fixture.xsl";
33    private static final String PARAM_BUILD_TIME = "buildTime";
34    private static final String PARAM_FIXTURE_NAME = "fixtureName";
35    private static final String PARAM_FIXTURE_DESCRIPTION = "fixtureDescription";
36    private static final String PARAM_FIXTURE_CLASS = "fixtureClass";
37 
38    private FixtureHtmlFileWriterFactory()
39    {
40 
41    }
42 
43    static FixtureHtmlFileWriter newFixtureHtmlFileWriter()
44    {
45        return new FixtureHtmlFileWriterImpl();
46    }
47 
48    private static final class FixtureHtmlFileWriterImpl implements FixtureHtmlFileWriter
49    {
50        FixtureHtmlFileWriterImpl()
51        {
52 
53        }
54 
55        public void writeFixtureHtml(
56                final FixtureResults result,
57                final File destination,
58                final FilenamePolicy policy,
59                final String buildTime)
60                throws FixtureResultsHandlerException
61        {
62            final ByteArrayOutputStream out = new ByteArrayOutputStream();
63            final XMLEncoder encoder = new XMLEncoder(out);
64 
65            for(TestResult tr : result.getTestResults())
66            {
67                final Object bean = new TestResultBeanImpl(tr.getName(), tr.getException(), tr.getElapsedTime(),
68                        tr.getMessage(), tr.getMethodName(), tr.getDescription(), tr.getResult());
69 
70                encoder.writeObject(bean);
71            }
72 
73            encoder.close();
74 
75 
76            InputStream in = null;
77 
78            try
79            {
80                in = getClass().getResourceAsStream(XSL_RESOURCE);
81                final Transformer t = TransformerFactory.newInstance().newTransformer(new StreamSource(in));
82                t.setParameter(PARAM_BUILD_TIME, buildTime);
83                t.setParameter(PARAM_FIXTURE_NAME, result.getName());
84                t.setParameter(PARAM_FIXTURE_DESCRIPTION, result.getDescription());
85                t.setParameter(PARAM_FIXTURE_CLASS, result.getClassName());
86 
87                OutputStream o = null;
88 
89                try
90                {
91                    final File f = new File(destination, policy.nextFilename());
92                    f.getParentFile().mkdirs();
93                    o = new FileOutputStream(f);
94                    final StreamResult r = new StreamResult(o);
95                    t.transform(new StreamSource(new ByteArrayInputStream(out.toByteArray())), r);
96                }
97                catch(FileNotFoundException e)
98                {
99                    throw new FixtureResultsHandlerException(e.getMessage(), e);
100                }
101                finally
102                {
103                    if(o != null)
104                    {
105                        try
106                        {
107                            o.close();
108                        }
109                        catch(IOException e)
110                        {
111                            throw new FixtureResultsHandlerException(e.getMessage(), e);
112                        }
113                    }
114                }
115            }
116            catch(TransformerConfigurationException e)
117            {
118                throw new FixtureResultsHandlerException(e.getMessage(), e);
119            }
120            catch(TransformerException e)
121            {
122                throw new FixtureResultsHandlerException(e.getMessage(), e);
123            }
124            finally
125            {
126                if(in != null)
127                {
128                    try
129                    {
130                        in.close();
131                    }
132                    catch(IOException e)
133                    {
134                        throw new FixtureResultsHandlerException(e.getMessage(), e);
135                    }
136                }
137            }
138        }
139    }
140}

[all classes][org.jtiger.report.html]
EMMA 2.0.5312 (C) Vladimir Roubtsov