Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CaptureOutputFeedParserListener |
|
| 1.0;1 | ||||
CapturePrintStream |
|
| 1.0;1 |
1 | /* | |
2 | * Copyright 1999,2004 The Apache Software Foundation. | |
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 | ||
17 | package org.apache.commons.feedparser.impl; | |
18 | ||
19 | import java.io.ByteArrayOutputStream; | |
20 | import java.io.OutputStream; | |
21 | import java.io.PrintStream; | |
22 | ||
23 | /** | |
24 | * Code which can run a parse but capture the output to a string to verify | |
25 | * certain methods were called via greping the output. This is ONLY for unit | |
26 | * tests. | |
27 | * | |
28 | * When done you can just call toString() to get the output of all the events | |
29 | * and then grep across it. | |
30 | * | |
31 | * @author <a href="mailto:burton@apache.org">Kevin A. Burton (burtonator)</a> | |
32 | * @version $Id: CaptureOutputFeedParserListener.java 373622 2006-01-30 22:53:00Z mvdb $ | |
33 | */ | |
34 | public class CaptureOutputFeedParserListener | |
35 | extends DebugFeedParserListener { | |
36 | ||
37 | public CaptureOutputFeedParserListener() { | |
38 | 0 | super( new CapturePrintStream() ); |
39 | 0 | } |
40 | ||
41 | public String toString() { | |
42 | ||
43 | 0 | CapturePrintStream cps = (CapturePrintStream)out; |
44 | 0 | ByteArrayOutputStream bos = (ByteArrayOutputStream)cps.getOutputStream(); |
45 | ||
46 | 0 | return bos.toString(); |
47 | ||
48 | } | |
49 | ||
50 | } | |
51 | ||
52 | class CapturePrintStream extends PrintStream { | |
53 | ||
54 | public CapturePrintStream() { | |
55 | 0 | super( new ByteArrayOutputStream() ); |
56 | 0 | } |
57 | ||
58 | public OutputStream getOutputStream() { | |
59 | 0 | return out; |
60 | } | |
61 | ||
62 | } |