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

COVERAGE SUMMARY FOR SOURCE FILE [XmlFixtureResultsHandler.java]

nameclass, %method, %block, %line, %
XmlFixtureResultsHandler.java100% (2/2)100% (4/4)83%  (93/112)80%  (17,5/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class XmlFixtureResultsHandler100% (1/1)100% (2/2)77%  (51/66)79%  (13,5/17)
XmlFixtureResultsHandler (): void 100% (1/1)100% (3/3)100% (2/2)
handleResult (FixtureResults, ReadOnlyArray): void 100% (1/1)76%  (48/63)77%  (11,5/15)
     
class XmlFixtureResultsHandler$1100% (1/1)100% (2/2)91%  (42/46)80%  (4/5)
XmlFixtureResultsHandler$1 (XmlFixtureResultsHandler): void 100% (1/1)100% (6/6)100% (1/1)
instantiate (Object, Encoder): Expression 100% (1/1)90%  (36/40)75%  (3/4)

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.xml;
12 
13import java.beans.Encoder;
14import java.beans.Expression;
15import java.beans.PersistenceDelegate;
16import java.beans.XMLEncoder;
17import java.io.FileNotFoundException;
18import java.io.FileOutputStream;
19import java.io.File;
20import org.jtiger.framework.FixtureResults;
21import org.jtiger.framework.FixtureResultsHandler;
22import org.jtiger.framework.FixtureResultsHandlerException;
23import org.jtiger.framework.ReadOnlyArray;
24 
25/**
26 * A result handler that produces a XML report of test run results.
27 * The report is written to a file which is passed in the parameters to
28 * {@link #handleResult(org.jtiger.framework.FixtureResults, org.jtiger.framework.ReadOnlyArray) the handleResult method}.
29 *
30 * @author %javadoc.author.tag%
31 * @version %version%<br/>
32 *          <i>Build Number %build.number%</i><br/>
33 *          <i>Build Time %build.time% CET (GMT + 1)</i>
34 */
35public final class XmlFixtureResultsHandler implements FixtureResultsHandler
36{
37    /**
38     * Create a default <tt>XmlFixtureResultsHandler</tt>.
39     */
40    public XmlFixtureResultsHandler()
41    {
42 
43    }
44 
45    /**
46     * Write a XML report of the given test run results to a file which is passed in the parameters.
47     * If the <tt>params</tt> are empty, the current directory is used to write the report to in a file called
48     * 'result.xml'.
49     *
50     * @param results The test run results to produce the XML report of.
51     * @param params The parameters that contain at least one parameter which is the file to write the XML report to
52     * otherwise the current directory is used.
53     * @throws FixtureResultsHandlerException If an error occurs while writing the XML report.
54     */
55    public void handleResult(final FixtureResults results, final ReadOnlyArray<String> params) throws FixtureResultsHandlerException
56    {
57        final File destination;
58 
59        if(params == null || params.length() == 0)
60        {
61            destination = new File("result.xml");
62        }
63        else
64        {
65            destination = new File(params.get(0));
66        }
67 
68        XMLEncoder encoder = null;
69 
70        try
71        {
72            encoder = new XMLEncoder(new FileOutputStream(destination));
73            encoder.setPersistenceDelegate(StackTraceElement.class, new PersistenceDelegate()
74            {
75                public Expression instantiate(final Object oldInstance, final Encoder out)
76                {
77                    if(!(oldInstance instanceof StackTraceElement))
78                    {
79                        throw new IllegalStateException();
80                    }
81 
82                    final StackTraceElement e = (StackTraceElement)oldInstance;
83 
84                    return new Expression(oldInstance, StackTraceElement.class, "new",
85                            new Object[]{e.getClassName(), e.getMethodName(), e.getFileName(), e.getLineNumber()});
86                }                            
87            });
88 
89            encoder.writeObject(new FixtureResultsBeanImpl(results));
90        }
91        catch(FileNotFoundException e)
92        {
93            throw new FixtureResultsHandlerException(e.getMessage(), e);
94        }
95        finally
96        {
97            if(encoder != null)
98            {
99                encoder.close();
100            }
101        }
102    }
103}

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