1 /**
2  * Copyright 2006-2013 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.objenesis.tck;
17 
18 import java.io.ByteArrayOutputStream;
19 import java.io.PrintStream;
20 import java.util.Arrays;
21 
22 import junit.framework.TestCase;
23 
24 /**
25  * @author Joe Walnes
26  * @author Henri Tremblay
27  */
28 public class TextReporterTest extends TestCase {
29 
30    private TextReporter textReporter;
31    private ByteArrayOutputStream summaryBuffer;
32 
setUp()33    protected void setUp() throws Exception {
34       super.setUp();
35       summaryBuffer = new ByteArrayOutputStream();
36       ByteArrayOutputStream logBuffer = new ByteArrayOutputStream();
37       textReporter = new TextReporter(new PrintStream(summaryBuffer), new PrintStream(logBuffer));
38    }
39 
testReportsSuccessesInTabularFormat()40    public void testReportsSuccessesInTabularFormat() {
41       textReporter.startTests("Some platform", Arrays.asList(new String[] {"candidate A",
42          "candidate B", "candidate C"}), Arrays.asList(new String[] {"instantiator1",
43          "instantiator2", "instantiator3"}));
44 
45       textReporter.startTest("candidate A", "instantiator1");
46       textReporter.result(false);
47       textReporter.startTest("candidate A", "instantiator2");
48       textReporter.result(false);
49       textReporter.startTest("candidate A", "instantiator3");
50       textReporter.result(true);
51 
52       textReporter.startTest("candidate B", "instantiator1");
53       textReporter.result(true);
54       textReporter.startTest("candidate B", "instantiator2");
55       textReporter.result(false);
56       textReporter.startTest("candidate B", "instantiator3");
57       textReporter.result(true);
58 
59       textReporter.startTest("candidate C", "instantiator1");
60       textReporter.exception(new RuntimeException("Problem"));
61       textReporter.startTest("candidate C", "instantiator2");
62       textReporter.result(false);
63       textReporter.startTest("candidate C", "instantiator3");
64       textReporter.result(true);
65 
66       textReporter.endTests();
67 
68       textReporter.printResult(true);
69 
70       ByteArrayOutputStream expectedSummaryBuffer = new ByteArrayOutputStream();
71       PrintStream out = new PrintStream(expectedSummaryBuffer);
72       out.println("Running TCK on platform: Some platform");
73       out.println();
74       out.println("Not serializable parent constructor called: Y");
75       out.println();
76       out.println("            instantiator1 instantiator2 instantiator3 ");
77       out.println("candidate A n             n             Y             ");
78       out.println("candidate B Y             n             Y             ");
79       out.println("candidate C n             n             Y             ");
80       out.println();
81       out.println("--- FAILED: 5 error(s) occured ---");
82       out.println();
83 
84       assertEquals(expectedSummaryBuffer.toString(), summaryBuffer.toString());
85    }
86 
87 }
88