001 /*
002 * Copyright 1999,2004 The Apache Software Foundation.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package org.apache.commons.feedparser.impl;
018
019 import java.io.ByteArrayOutputStream;
020 import java.io.OutputStream;
021 import java.io.PrintStream;
022
023 /**
024 * Code which can run a parse but capture the output to a string to verify
025 * certain methods were called via greping the output. This is ONLY for unit
026 * tests.
027 *
028 * When done you can just call toString() to get the output of all the events
029 * and then grep across it.
030 *
031 * @author <a href="mailto:burton@apache.org">Kevin A. Burton (burtonator)</a>
032 * @version $Id: CaptureOutputFeedParserListener.java 373622 2006-01-30 22:53:00Z mvdb $
033 */
034 public class CaptureOutputFeedParserListener
035 extends DebugFeedParserListener {
036
037 public CaptureOutputFeedParserListener() {
038 super( new CapturePrintStream() );
039 }
040
041 public String toString() {
042
043 CapturePrintStream cps = (CapturePrintStream)out;
044 ByteArrayOutputStream bos = (ByteArrayOutputStream)cps.getOutputStream();
045
046 return bos.toString();
047
048 }
049
050 }
051
052 class CapturePrintStream extends PrintStream {
053
054 public CapturePrintStream() {
055 super( new ByteArrayOutputStream() );
056 }
057
058 public OutputStream getOutputStream() {
059 return out;
060 }
061
062 }