From 21344dacfc87e76f15a08f4db5c188dec3771020 Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Wed, 9 Apr 2014 06:34:57 -0400 Subject: [PATCH] redirected standard error to hide expected [fatal] message from being displayed during tests Former-commit-id: ecbc294640ca1e1a3c418af871dd71a31bbcccdb --- .../data/nuget/XPathNuspecParserTest.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/nuget/XPathNuspecParserTest.java b/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/nuget/XPathNuspecParserTest.java index 9993bae73..60cac552b 100644 --- a/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/nuget/XPathNuspecParserTest.java +++ b/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/nuget/XPathNuspecParserTest.java @@ -17,21 +17,22 @@ */ package org.owasp.dependencycheck.data.nuget; +import java.io.ByteArrayOutputStream; import java.io.InputStream; - +import java.io.PrintStream; +import static org.junit.Assert.assertEquals; import org.junit.Test; -import static org.junit.Assert.*; - /** - * + * * @author colezlaw * */ public class XPathNuspecParserTest { + /** * Test all the valid components. - * + * * @throws Exception if anything goes sideways. */ @Test @@ -46,25 +47,30 @@ public class XPathNuspecParserTest { assertEquals("Apache Software Foundation", np.getOwners()); assertEquals("http://logging.apache.org/log4net/license.html", np.getLicenseUrl()); } - + /** * Expect a NuspecParseException when what we pass isn't even XML. - * + * * @throws Exception we expect this. */ - @Test(expected=NuspecParseException.class) + @Test(expected = NuspecParseException.class) public void testMissingDocument() throws Exception { NuspecParser parser = new XPathNuspecParser(); InputStream is = XPathNuspecParserTest.class.getClassLoader().getResourceAsStream("dependencycheck.properties"); + + //hide the fatal message from the core parser + final ByteArrayOutputStream myOut = new ByteArrayOutputStream(); + System.setErr(new PrintStream(myOut)); + NugetPackage np = parser.parse(is); } - + /** * Expect a NuspecParseException when it's valid XML, but not a Nuspec. - * + * * @throws Exception we expect this. */ - @Test(expected=NuspecParseException.class) + @Test(expected = NuspecParseException.class) public void testNotNuspec() throws Exception { NuspecParser parser = new XPathNuspecParser(); InputStream is = XPathNuspecParserTest.class.getClassLoader().getResourceAsStream("suppressions.xml");