1 /*
2 * $Id: XMLFormatterTest.java,v 1.3 2011/07/29 20:20:17 oboehm Exp $
3 *
4 * Copyright (c) 2010 by Oliver Boehm
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * (c)reated 04.03.2010 by oliver (ob@oasd.de)
19 */
20
21 package patterntesting.tool.aspectj;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.io.*;
26 import java.util.Vector;
27
28 import org.apache.commons.io.IOUtils;
29 import org.junit.*;
30 import org.slf4j.LoggerFactory;
31
32 /**
33 * @author oliver
34 * @since 1.0 (04.03.2010)
35 */
36 public final class XMLFormatterTest {
37
38 private static org.slf4j.Logger log = LoggerFactory.getLogger(XMLFormatterTest.class);
39 private final XMLFormatter xmlFormatter = new XMLFormatter();
40 private static Vector<AjcFileResult> ajcFileResults = new Vector<AjcFileResult>();
41
42 /**
43 * We put one result element in the list for testing.
44 */
45 @BeforeClass
46 public static void setUpBeforeClass() {
47 AjcFileResult result = new AjcFileResult("test-report");
48 ajcFileResults.add(result);
49 }
50
51 /**
52 * Test method for {@link XMLFormatter#format(java.util.Enumeration)}.
53 * We want the XML file formatted. So look at the test-report.xml how it
54 * should look like.
55 *
56 * @throws IOException if test resource can't be read
57 */
58 @Test
59 public void testFormatEnumerationOfAjcFileResult() throws IOException {
60 String formatted = xmlFormatter.format(ajcFileResults.elements());
61 log.info(formatted);
62 checkXml("test-report.xml", formatted);
63 }
64
65 private static void checkXml(final String xmlResource, final String xmlString) throws IOException {
66 InputStream istream = XMLFormatterTest.class
67 .getResourceAsStream(xmlResource);
68 String expected = IOUtils.toString(istream);
69 istream.close();
70 assertEquals(expected, xmlString);
71 }
72
73 }
74