01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.runner;
04:
05: import java.io.*;
06: import fit.Counts;
07: import fitnesse.testutil.AbstractRegex;
08:
09: public class StandardResultHandlerTest extends AbstractRegex {
10: private StandardResultHandler handler;
11:
12: private ByteArrayOutputStream bytes;
13:
14: public void setUp() throws Exception {
15: bytes = new ByteArrayOutputStream();
16: handler = new StandardResultHandler(new PrintStream(bytes));
17: }
18:
19: public void testHandleResultPassing() throws Exception {
20: String output = getOutputForResultWithCount(new Counts(5, 0, 0,
21: 0));
22: assertSubString(".....", output);
23: }
24:
25: public void testHandleResultFailing() throws Exception {
26: String output = getOutputForResultWithCount(new Counts(0, 1, 0,
27: 0));
28: assertSubString("SomePage has failures", output);
29: }
30:
31: public void testHandleResultWithErrors() throws Exception {
32: String output = getOutputForResultWithCount(new Counts(0, 0, 0,
33: 1));
34: assertSubString("SomePage has errors", output);
35: }
36:
37: public void testHandleErrorWithBlankTitle() throws Exception {
38: String output = getOutputForResultWithCount("", new Counts(0,
39: 0, 0, 1));
40: assertSubString("The test has errors", output);
41: }
42:
43: public void testFinalCount() throws Exception {
44: Counts counts = new Counts(5, 4, 3, 2);
45: handler.acceptFinalCount(counts);
46:
47: assertSubString(counts.toString(), bytes.toString());
48: }
49:
50: private String getOutputForResultWithCount(Counts counts)
51: throws Exception {
52: return getOutputForResultWithCount("SomePage", counts);
53: }
54:
55: private String getOutputForResultWithCount(String title,
56: Counts counts) throws Exception {
57: PageResult result = new PageResult(title);
58: result.setCounts(counts);
59: handler.acceptResult(result);
60: String output = bytes.toString();
61: return output;
62: }
63:
64: }
|