Skip to content

Commit

Permalink
Avoid printing *expected* stack traces during test runs
Browse files Browse the repository at this point in the history
  • Loading branch information
Francisco Borges committed Oct 2, 2012
1 parent 70748a1 commit 67ec04e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@

package org.hornetq.core.filter.impl;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.hornetq.api.core.HornetQException;
import org.hornetq.api.core.HornetQInvalidFilterExpressionException;
Expand All @@ -26,48 +22,27 @@
import org.hornetq.core.server.ServerMessage;
import org.hornetq.core.server.impl.ServerMessageImpl;
import org.hornetq.tests.util.RandomUtil;
import org.hornetq.tests.util.SilentTestCase;

/**
* Tests the compliance with the HornetQ Filter syntax.
*
* @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
*/
public class FilterTest extends TestCase
public class FilterTest extends SilentTestCase
{
private Filter filter;

private ServerMessage message;

private PrintStream origSysOut;

private PrintStream origSysErr;

private PrintStream sysOut;

private PrintStream sysErr;

@Override
protected void setUp() throws Exception
{
super.setUp();
origSysOut = System.out;
origSysErr = System.err;
sysOut = new PrintStream(new ByteArrayOutputStream());
System.setOut(sysOut);
sysErr = new PrintStream(new ByteArrayOutputStream());
System.setErr(sysErr);
message = new ServerMessageImpl(1, 1000);
}

@Override
public void tearDown() throws Exception
{
System.setOut(origSysOut);
System.setErr(origSysErr);
super.tearDown();
}

public void testFilterForgets() throws Exception
{
filter = FilterImpl.createFilter(new SimpleString("color = 'RED'"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.hornetq.tests.util;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import junit.framework.TestCase;

/**
* Test case that hijacks sys-out and sys-err.
* <p>
* It is meant to avoid cluttering either during test execution when the tested code (expectedly)
* writes to these.
*/
public abstract class SilentTestCase extends TestCase
{
private PrintStream origSysOut;
private PrintStream origSysErr;

private PrintStream sysOut;
private PrintStream sysErr;

@Override
protected void setUp() throws Exception
{
super.setUp();
origSysOut = System.out;
origSysErr = System.err;
sysOut = new PrintStream(new ByteArrayOutputStream());
System.setOut(sysOut);
sysErr = new PrintStream(new ByteArrayOutputStream());
System.setErr(sysErr);
}

@Override
public void tearDown() throws Exception
{
System.setOut(origSysOut);
System.setErr(origSysErr);
super.tearDown();
}
}
4 changes: 2 additions & 2 deletions hornetq-core/src/test/java/org/hornetq/util/XMLUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
package org.hornetq.util;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.hornetq.tests.util.SilentTestCase;
import org.hornetq.utils.XMLUtil;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
Expand All @@ -25,7 +25,7 @@
* @author <a href="mailto:ovidiu@feodorov.com">Ovidiu Feodorov</a>
* @version <tt>$Revision$</tt>
*/
public class XMLUtilTest extends TestCase
public class XMLUtilTest extends SilentTestCase
{
// Constructors --------------------------------------------------

Expand Down

0 comments on commit 67ec04e

Please sign in to comment.