http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/BatchTestTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/BatchTestTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/BatchTestTest.java index a969499..aa483f6 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/BatchTestTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/BatchTestTest.java @@ -1,121 +1,121 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.ant.taskdefs.optional.junit; - - -import static org.junit.Assert.fail; -import static org.junit.Assert.assertArrayEquals; - -import org.junit.Test; - -/** - * - * @author Marian Petras - */ -public class BatchTestTest { - - @Test - public void testParseTestMethodNamesList() { - try { - JUnitTest.parseTestMethodNamesList(null); - fail("IllegalArgumentException expected when the param is <null>"); - } catch (IllegalArgumentException ex) { - //this is an expected exception - } - - assertArrayEquals(new String[0], JUnitTest.parseTestMethodNamesList("")); - assertArrayEquals(new String[0], JUnitTest.parseTestMethodNamesList(" ")); - assertArrayEquals(new String[0], JUnitTest.parseTestMethodNamesList(" ")); - - checkParseCausesIAE(","); - checkParseCausesIAE(" ,"); - checkParseCausesIAE(", "); - checkParseCausesIAE(" , "); - checkParseCausesIAE(",a"); - checkParseCausesIAE(" ,a"); - checkParseCausesIAE(" ,a"); - checkParseCausesIAE(" , a"); - checkParseCausesIAE(" ,a "); - checkParseCausesIAE(" ,a ,"); - checkParseCausesIAE("ab,,cd"); - checkParseCausesIAE("ab, ,cd"); - checkParseCausesIAE("ab, ,cd"); - checkParseCausesIAE("ab, ,cd,"); - checkParseCausesIAE(",ab, ,cd,"); - - assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc")); - assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc ")); - assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList(" abc")); - assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList(" abc ")); - assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc ")); - assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc,")); - assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc, ")); - assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc ,")); - assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc , ")); - assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList(" abc ,")); - - /* legal Java identifiers: */ - assertArrayEquals(new String[] {"a"}, JUnitTest.parseTestMethodNamesList("a")); - assertArrayEquals(new String[] {"a1"}, JUnitTest.parseTestMethodNamesList("a1")); - assertArrayEquals(new String[] {"a$"}, JUnitTest.parseTestMethodNamesList("a$")); - assertArrayEquals(new String[] {"a$1"}, JUnitTest.parseTestMethodNamesList("a$1")); - assertArrayEquals(new String[] {"_bc"}, JUnitTest.parseTestMethodNamesList("_bc")); - assertArrayEquals(new String[] {"___"}, JUnitTest.parseTestMethodNamesList("___")); - - /* illegal Java identifiers: */ - checkParseCausesIAE("1"); - checkParseCausesIAE("1a"); - checkParseCausesIAE("1ab"); - checkParseCausesIAE("1abc"); - checkParseCausesIAE("1abc d"); - checkParseCausesIAE("1abc de"); - checkParseCausesIAE("1abc def"); - checkParseCausesIAE("1abc def,"); - checkParseCausesIAE(",1abc def"); - - assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc,def")); - assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc,def,")); - assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc,def ")); - assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc, def")); - assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc, def ")); - assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc ,def")); - assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc ,def ")); - assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc , def")); - assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc , def ")); - assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc,def")); - assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc,def ")); - assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc, def")); - assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc, def ")); - assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc ,def")); - assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc ,def ")); - assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc , def")); - assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc , def ")); - assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc , def ,")); - } - - private static void checkParseCausesIAE(String param) { - try { - JUnitTest.parseTestMethodNamesList(param); - fail("IllegalArgumentException expected when the param is \"" + param + '"'); - } catch (IllegalArgumentException ex) { - //this is an expected exception - } - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.taskdefs.optional.junit; + + +import static org.junit.Assert.fail; +import static org.junit.Assert.assertArrayEquals; + +import org.junit.Test; + +/** + * + * @author Marian Petras + */ +public class BatchTestTest { + + @Test + public void testParseTestMethodNamesList() { + try { + JUnitTest.parseTestMethodNamesList(null); + fail("IllegalArgumentException expected when the param is <null>"); + } catch (IllegalArgumentException ex) { + //this is an expected exception + } + + assertArrayEquals(new String[0], JUnitTest.parseTestMethodNamesList("")); + assertArrayEquals(new String[0], JUnitTest.parseTestMethodNamesList(" ")); + assertArrayEquals(new String[0], JUnitTest.parseTestMethodNamesList(" ")); + + checkParseCausesIAE(","); + checkParseCausesIAE(" ,"); + checkParseCausesIAE(", "); + checkParseCausesIAE(" , "); + checkParseCausesIAE(",a"); + checkParseCausesIAE(" ,a"); + checkParseCausesIAE(" ,a"); + checkParseCausesIAE(" , a"); + checkParseCausesIAE(" ,a "); + checkParseCausesIAE(" ,a ,"); + checkParseCausesIAE("ab,,cd"); + checkParseCausesIAE("ab, ,cd"); + checkParseCausesIAE("ab, ,cd"); + checkParseCausesIAE("ab, ,cd,"); + checkParseCausesIAE(",ab, ,cd,"); + + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc ")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList(" abc")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList(" abc ")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc ")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc,")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc, ")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc ,")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc , ")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList(" abc ,")); + + /* legal Java identifiers: */ + assertArrayEquals(new String[] {"a"}, JUnitTest.parseTestMethodNamesList("a")); + assertArrayEquals(new String[] {"a1"}, JUnitTest.parseTestMethodNamesList("a1")); + assertArrayEquals(new String[] {"a$"}, JUnitTest.parseTestMethodNamesList("a$")); + assertArrayEquals(new String[] {"a$1"}, JUnitTest.parseTestMethodNamesList("a$1")); + assertArrayEquals(new String[] {"_bc"}, JUnitTest.parseTestMethodNamesList("_bc")); + assertArrayEquals(new String[] {"___"}, JUnitTest.parseTestMethodNamesList("___")); + + /* illegal Java identifiers: */ + checkParseCausesIAE("1"); + checkParseCausesIAE("1a"); + checkParseCausesIAE("1ab"); + checkParseCausesIAE("1abc"); + checkParseCausesIAE("1abc d"); + checkParseCausesIAE("1abc de"); + checkParseCausesIAE("1abc def"); + checkParseCausesIAE("1abc def,"); + checkParseCausesIAE(",1abc def"); + + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc,def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc,def,")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc,def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc, def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc, def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc ,def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc ,def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc , def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc , def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc,def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc,def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc, def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc, def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc ,def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc ,def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc , def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc , def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc , def ,")); + } + + private static void checkParseCausesIAE(String param) { + try { + JUnitTest.parseTestMethodNamesList(param); + fail("IllegalArgumentException expected when the param is \"" + param + '"'); + } catch (IllegalArgumentException ex) { + //this is an expected exception + } + } + +}
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/DOMUtilTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/DOMUtilTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/DOMUtilTest.java index 7591ada..c322401 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/DOMUtilTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/DOMUtilTest.java @@ -1,53 +1,53 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.apache.tools.ant.taskdefs.optional.junit; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.io.InputStream; - -import javax.xml.parsers.DocumentBuilder; - -import org.apache.tools.ant.util.JAXPUtils; -import org.junit.Test; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; - -public class DOMUtilTest { - - @Test - public void testListChildNodes() throws SAXException, IOException { - DocumentBuilder db = JAXPUtils.getDocumentBuilder(); - InputStream is = this.getClass().getClassLoader().getResourceAsStream("taskdefs/optional/junit/matches.xml"); - Document doc = db.parse(is); - NodeList nl = DOMUtil.listChildNodes(doc.getDocumentElement(), new FooNodeFilter(), true); - assertEquals("expecting 3", 3, nl.getLength()); - } - - public class FooNodeFilter implements DOMUtil.NodeFilter { - public boolean accept(Node node) { - if (node.getNodeName().equals("foo")) { - return true; - } - return false; - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.taskdefs.optional.junit; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.io.InputStream; + +import javax.xml.parsers.DocumentBuilder; + +import org.apache.tools.ant.util.JAXPUtils; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +public class DOMUtilTest { + + @Test + public void testListChildNodes() throws SAXException, IOException { + DocumentBuilder db = JAXPUtils.getDocumentBuilder(); + InputStream is = this.getClass().getClassLoader().getResourceAsStream("taskdefs/optional/junit/matches.xml"); + Document doc = db.parse(is); + NodeList nl = DOMUtil.listChildNodes(doc.getDocumentElement(), new FooNodeFilter(), true); + assertEquals("expecting 3", 3, nl.getLength()); + } + + public class FooNodeFilter implements DOMUtil.NodeFilter { + public boolean accept(Node node) { + if (node.getNodeName().equals("foo")) { + return true; + } + return false; + } + } +} http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitClassLoaderTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitClassLoaderTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitClassLoaderTest.java index 0c303c1..4baf741 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitClassLoaderTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitClassLoaderTest.java @@ -1,37 +1,37 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.apache.tools.ant.taskdefs.optional.junit; - -import static org.junit.Assert.assertSame; - -import org.junit.Test; - -/** - * Test to ensure that the classloader loading JUnit testcase - * is also the context classloader. - * - */ -public class JUnitClassLoaderTest { - - @Test - public void testContextClassLoader(){ - ClassLoader context = Thread.currentThread().getContextClassLoader(); - ClassLoader caller = getClass().getClassLoader(); - assertSame(context, caller); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.taskdefs.optional.junit; + +import static org.junit.Assert.assertSame; + +import org.junit.Test; + +/** + * Test to ensure that the classloader loading JUnit testcase + * is also the context classloader. + * + */ +public class JUnitClassLoaderTest { + + @Test + public void testContextClassLoader(){ + ClassLoader context = Thread.currentThread().getContextClassLoader(); + ClassLoader caller = getClass().getClassLoader(); + assertSame(context, caller); + } +} http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java index 8a36452..de75404 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java @@ -63,39 +63,39 @@ import org.w3c.dom.Node; public class JUnitTaskTest { - @Rule - public BuildFileRule buildRule = new BuildFileRule(); - + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + /** * The JUnit setup method. */ - @Before + @Before public void setUp() { buildRule.configureProject("src/etc/testcases/taskdefs/optional/junit.xml"); } - @Test + @Test public void testCrash() { - buildRule.executeTarget("crash"); - assertEquals("true", buildRule.getProject().getProperty("crashed")); + buildRule.executeTarget("crash"); + assertEquals("true", buildRule.getProject().getProperty("crashed")); } - @Test + @Test public void testNoCrash() { - buildRule.executeTarget("nocrash"); - assertNull(buildRule.getProject().getProperty("crashed")); + buildRule.executeTarget("nocrash"); + assertNull(buildRule.getProject().getProperty("crashed")); } - @Test + @Test public void testTimeout() { - buildRule.executeTarget("timeout"); - assertEquals("true", buildRule.getProject().getProperty("timeout")); + buildRule.executeTarget("timeout"); + assertEquals("true", buildRule.getProject().getProperty("timeout")); } @Test public void testNoTimeout() { buildRule.executeTarget("notimeout"); - assertNull(buildRule.getProject().getProperty("timeout")); + assertNull(buildRule.getProject().getProperty("timeout")); } @Test @@ -141,7 +141,7 @@ public class JUnitTaskTest { public void testFailureRecorder() { if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_1_5)) { try { - Class<?> clazz =Class.forName("junit.framework.JUnit4TestAdapter"); + Class<?> clazz =Class.forName("junit.framework.JUnit4TestAdapter"); Assume.assumeFalse("Skipping test since it fails with JUnit 4", clazz != null); } catch (ClassNotFoundException e) { // OK, this is JUnit3, can run test @@ -154,14 +154,14 @@ public class JUnitTaskTest { // ensure that there is a clean test environment assertFalse("Test directory '" + testDir.getAbsolutePath() - + "' must not exist before the test preparation.", + + "' must not exist before the test preparation.", testDir.exists()); assertFalse("The collector file '" + collectorFile.getAbsolutePath() - + "'must not exist before the test preparation.", + + "'must not exist before the test preparation.", collectorFile.exists()); - + // prepare the test environment buildRule.executeTarget("failureRecorder.prepare"); assertTrue("Test directory '" + testDir.getAbsolutePath() @@ -169,14 +169,14 @@ public class JUnitTaskTest { assertTrue("There should be one class.", (new File(testDir, "A.class")).exists()); assertFalse("The collector file '" - + collectorFile.getAbsolutePath() + + collectorFile.getAbsolutePath() + "' should not exist before the 1st run.", collectorFile.exists()); - - + + // 1st junit run: should do all tests - failing and not failing tests buildRule.executeTarget("failureRecorder.runtest"); - assertTrue("The collector file '" + collectorFile.getAbsolutePath() + assertTrue("The collector file '" + collectorFile.getAbsolutePath() + "' should exist after the 1st run.", collectorFile.exists()); // the passing test cases @@ -202,10 +202,10 @@ public class JUnitTaskTest { buildRule.executeTarget("D.test10"); assertContains("1st run: should run D.test10", buildRule.getOutput()); - + // 2nd junit run: should do only failing tests buildRule.executeTarget("failureRecorder.runtest"); - assertTrue("The collector file '" + collectorFile.getAbsolutePath() + assertTrue("The collector file '" + collectorFile.getAbsolutePath() + "' should exist after the 2nd run.", collectorFile.exists()); // the passing test cases @@ -230,14 +230,14 @@ public class JUnitTaskTest { assertContains("2nd run: should run B.test04", buildRule.getOutput()); buildRule.executeTarget("D.test10"); assertContains("2nd run: should run D.test10", buildRule.getOutput()); - - + + // "fix" errors in class A buildRule.executeTarget("failureRecorder.fixing"); - + // 3rd run: four running tests with two errors buildRule.executeTarget("failureRecorder.runtest"); - assertTrue("The collector file '" + collectorFile.getAbsolutePath() + assertTrue("The collector file '" + collectorFile.getAbsolutePath() + "' should exist after the 3rd run.", collectorFile.exists()); buildRule.executeTarget("A.test02"); @@ -248,11 +248,11 @@ public class JUnitTaskTest { assertContains("3rd run: should run B.test04", buildRule.getOutput()); buildRule.executeTarget("D.test10"); assertContains("3rd run: should run D.test10", buildRule.getOutput()); - - + + // 4rd run: two running tests with errors buildRule.executeTarget("failureRecorder.runtest"); - assertTrue("The collector file '" + collectorFile.getAbsolutePath() + assertTrue("The collector file '" + collectorFile.getAbsolutePath() + "' should exist after the 4th run.", collectorFile.exists()); //TODO: these two statements fail http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java index 2b7acd4..49c1fb4 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java @@ -1,111 +1,111 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.ant.taskdefs.optional.junit; - -import static org.apache.tools.ant.AntAssert.assertContains; -import static org.apache.tools.ant.AntAssert.assertNotContains; - -import org.apache.tools.ant.BuildFileRule; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - -public class JUnitTestListenerTest{ - - @Rule - public BuildFileRule buildRule = new BuildFileRule(); - - // The captureToSummary test writes to stdout and stderr, good for - // verifying that the TestListener support doesn't break anything. - private static final String PASS_TEST_TARGET = "captureToSummary"; - - // testNoCrash is the test invoked by the captureToSummary's junit task - private static final String PASS_TEST = "testNoCrash"; - - @Before - public void setUp() { - buildRule.configureProject("src/etc/testcases/taskdefs/optional/junit.xml"); - } - - - @Test - public void testFullLogOutput() { - buildRule.getProject().setProperty("enableEvents", "true"); - buildRule.executeTarget(PASS_TEST_TARGET); - assertContains("expecting full log to have BuildListener events", - JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog()); - } - - @Test - public void testNoLogOutput() { - buildRule.getProject().setProperty("enableEvents", "true"); - buildRule.executeTarget(PASS_TEST_TARGET); - assertNotContains("expecting log to not have BuildListener events", - JUnitTask.TESTLISTENER_PREFIX, buildRule.getLog()); - } - - @Test - public void testTestCountFired() { - buildRule.getProject().setProperty("enableEvents", "true"); - buildRule.executeTarget(PASS_TEST_TARGET); - assertContains("expecting test count message", JUnitTask.TESTLISTENER_PREFIX + - "tests to run: ", buildRule.getFullLog()); - } - - @Test - public void testStartTestFired() { - buildRule.getProject().setProperty("enableEvents", "true"); - buildRule.executeTarget(PASS_TEST_TARGET); - assertContains("expecting test started message", JUnitTask.TESTLISTENER_PREFIX + - "startTest(" + PASS_TEST + ")", buildRule.getFullLog()); - } - - @Test - public void testEndTestFired() { - buildRule.getProject().setProperty("enableEvents", "true"); - buildRule.executeTarget(PASS_TEST_TARGET); - assertContains("expecting test ended message", JUnitTask.TESTLISTENER_PREFIX + - "endTest(" + PASS_TEST + ")", buildRule.getFullLog()); - } - - @Test - public void testNoFullLogOutputByDefault() { - buildRule.executeTarget(PASS_TEST_TARGET); - assertNotContains("expecting full log to not have BuildListener events", - JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog()); - } - - @Test - public void testFullLogOutputMagicProperty() { - buildRule.getProject().setProperty(JUnitTask.ENABLE_TESTLISTENER_EVENTS, "true"); - buildRule.executeTarget(PASS_TEST_TARGET); - assertContains("expecting full log to have BuildListener events", - JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog()); - } - - @Test - public void testNoFullLogOutputMagicPropertyWins() { - buildRule.getProject().setProperty(JUnitTask.ENABLE_TESTLISTENER_EVENTS, "false"); - buildRule.getProject().setProperty("enableEvents", "true"); - buildRule.executeTarget(PASS_TEST_TARGET); - assertNotContains("expecting full log to not have BuildListener events", - JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog()); - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.taskdefs.optional.junit; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.apache.tools.ant.AntAssert.assertNotContains; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +public class JUnitTestListenerTest{ + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + // The captureToSummary test writes to stdout and stderr, good for + // verifying that the TestListener support doesn't break anything. + private static final String PASS_TEST_TARGET = "captureToSummary"; + + // testNoCrash is the test invoked by the captureToSummary's junit task + private static final String PASS_TEST = "testNoCrash"; + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/junit.xml"); + } + + + @Test + public void testFullLogOutput() { + buildRule.getProject().setProperty("enableEvents", "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertContains("expecting full log to have BuildListener events", + JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog()); + } + + @Test + public void testNoLogOutput() { + buildRule.getProject().setProperty("enableEvents", "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertNotContains("expecting log to not have BuildListener events", + JUnitTask.TESTLISTENER_PREFIX, buildRule.getLog()); + } + + @Test + public void testTestCountFired() { + buildRule.getProject().setProperty("enableEvents", "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertContains("expecting test count message", JUnitTask.TESTLISTENER_PREFIX + + "tests to run: ", buildRule.getFullLog()); + } + + @Test + public void testStartTestFired() { + buildRule.getProject().setProperty("enableEvents", "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertContains("expecting test started message", JUnitTask.TESTLISTENER_PREFIX + + "startTest(" + PASS_TEST + ")", buildRule.getFullLog()); + } + + @Test + public void testEndTestFired() { + buildRule.getProject().setProperty("enableEvents", "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertContains("expecting test ended message", JUnitTask.TESTLISTENER_PREFIX + + "endTest(" + PASS_TEST + ")", buildRule.getFullLog()); + } + + @Test + public void testNoFullLogOutputByDefault() { + buildRule.executeTarget(PASS_TEST_TARGET); + assertNotContains("expecting full log to not have BuildListener events", + JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog()); + } + + @Test + public void testFullLogOutputMagicProperty() { + buildRule.getProject().setProperty(JUnitTask.ENABLE_TESTLISTENER_EVENTS, "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertContains("expecting full log to have BuildListener events", + JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog()); + } + + @Test + public void testNoFullLogOutputMagicPropertyWins() { + buildRule.getProject().setProperty(JUnitTask.ENABLE_TESTLISTENER_EVENTS, "false"); + buildRule.getProject().setProperty("enableEvents", "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertNotContains("expecting full log to not have BuildListener events", + JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog()); + } + +} http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java index e5092fe..7c0fa16 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java @@ -38,7 +38,7 @@ import org.junit.Test; */ public class JUnitTestRunnerTest{ - + // check that a valid method name generates no errors @Test @@ -56,8 +56,8 @@ public class JUnitTestRunnerTest{ String error = runner.getFormatter().getError(); // might be FAILURES or ERRORS depending on JUnit version? assertTrue(error, runner.getRetCode() != JUnitTestRunner.SUCCESS); - } - + } + // check that having no suite generates no errors @Test public void testNoSuite(){ @@ -92,7 +92,7 @@ public class JUnitTestRunnerTest{ runner.run(); // On junit3 this is a FAILURE, on junit4 this is an ERROR int ret = runner.getRetCode(); - + if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) { fail("Unexpected result " + ret + " from junit runner"); } @@ -131,21 +131,21 @@ public class JUnitTestRunnerTest{ } protected TestRunner createRunner(Class<?> clazz){ - return new TestRunner(new JUnitTest(clazz.getName()), null, + return new TestRunner(new JUnitTest(clazz.getName()), null, true, true, true); } protected TestRunner createRunnerForTestMethod(Class<?> clazz, String method){ return new TestRunner(new JUnitTest(clazz.getName()), new String[] {method}, true, true, true); - } - + } + // the test runner that wrap the dummy formatter that interests us private final static class TestRunner extends JUnitTestRunner { private ResultFormatter formatter = new ResultFormatter(); TestRunner(JUnitTest test, String[] methods, boolean haltonerror, boolean filtertrace, boolean haltonfailure){ - super(test, methods, haltonerror, filtertrace, haltonfailure, + super(test, methods, haltonerror, filtertrace, haltonfailure, false, false, TestRunner.class.getClassLoader()); // use the classloader that loaded this class otherwise // it will not be able to run inner classes if this test @@ -206,8 +206,8 @@ public class JUnitTestRunnerTest{ // should not be executed throw new NullPointerException("thrown on purpose"); } - } - + } + public static class InvalidTestCase extends TestCase { public InvalidTestCase(String name){ super(name); @@ -242,4 +242,3 @@ public class JUnitTestRunnerTest{ } } } - http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java index b00bfde..2f3fdb7 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java @@ -1,102 +1,102 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.apache.tools.ant.taskdefs.optional.junit; - -import static org.junit.Assert.assertEquals; -import junit.framework.JUnit4TestAdapterCache; -import junit.framework.TestCase; -import junit.framework.TestResult; - -import org.junit.Test; -import org.junit.runner.Description; - -/** - */ -public class JUnitVersionHelperTest { - - @Test - public void testMyOwnName() { - assertEquals("testMyOwnName", - JUnitVersionHelper.getTestCaseName( - JUnit4TestAdapterCache.getDefault().asTest( - Description.createTestDescription(JUnitVersionHelperTest.class, "testMyOwnName") - ) - ) - ); - } - - @Test - public void testNonTestCaseName() { - assertEquals("I'm a foo", - JUnitVersionHelper.getTestCaseName(new Foo1())); - } - - @Test - public void testNoStringReturn() { - assertEquals("unknown", - JUnitVersionHelper.getTestCaseName(new Foo2())); - } - - @Test - public void testNoGetName() { - assertEquals("unknown", - JUnitVersionHelper.getTestCaseName(new Foo3())); - } - - @Test - public void testNameNotGetName() { - assertEquals("I'm a foo, too", - JUnitVersionHelper.getTestCaseName(new Foo4())); - } - - @Test - public void testNull() { - assertEquals("unknown", JUnitVersionHelper.getTestCaseName(null)); - } - - @Test - public void testTestCaseSubClass() { - assertEquals("overridden getName", - JUnitVersionHelper.getTestCaseName(new Foo5())); - } - - public static class Foo implements junit.framework.Test { - public int countTestCases() {return 0;} - public void run(TestResult result) {} - } - - public static class Foo1 extends Foo { - public String getName() {return "I'm a foo";} - } - - public static class Foo2 extends Foo { - public int getName() {return 1;} - } - - public static class Foo3 extends Foo { - } - - public static class Foo4 extends Foo { - public String name() {return "I'm a foo, too";} - } - - public static class Foo5 extends TestCase { - public String getName() {return "overridden getName";} - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.taskdefs.optional.junit; + +import static org.junit.Assert.assertEquals; +import junit.framework.JUnit4TestAdapterCache; +import junit.framework.TestCase; +import junit.framework.TestResult; + +import org.junit.Test; +import org.junit.runner.Description; + +/** + */ +public class JUnitVersionHelperTest { + + @Test + public void testMyOwnName() { + assertEquals("testMyOwnName", + JUnitVersionHelper.getTestCaseName( + JUnit4TestAdapterCache.getDefault().asTest( + Description.createTestDescription(JUnitVersionHelperTest.class, "testMyOwnName") + ) + ) + ); + } + + @Test + public void testNonTestCaseName() { + assertEquals("I'm a foo", + JUnitVersionHelper.getTestCaseName(new Foo1())); + } + + @Test + public void testNoStringReturn() { + assertEquals("unknown", + JUnitVersionHelper.getTestCaseName(new Foo2())); + } + + @Test + public void testNoGetName() { + assertEquals("unknown", + JUnitVersionHelper.getTestCaseName(new Foo3())); + } + + @Test + public void testNameNotGetName() { + assertEquals("I'm a foo, too", + JUnitVersionHelper.getTestCaseName(new Foo4())); + } + + @Test + public void testNull() { + assertEquals("unknown", JUnitVersionHelper.getTestCaseName(null)); + } + + @Test + public void testTestCaseSubClass() { + assertEquals("overridden getName", + JUnitVersionHelper.getTestCaseName(new Foo5())); + } + + public static class Foo implements junit.framework.Test { + public int countTestCases() {return 0;} + public void run(TestResult result) {} + } + + public static class Foo1 extends Foo { + public String getName() {return "I'm a foo";} + } + + public static class Foo2 extends Foo { + public int getName() {return 1;} + } + + public static class Foo3 extends Foo { + } + + public static class Foo4 extends Foo { + public String name() {return "I'm a foo, too";} + } + + public static class Foo5 extends TestCase { + public String getName() {return "overridden getName";} + } + +} http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/NoVmCrash.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/NoVmCrash.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/NoVmCrash.java index 85fbee7..392a92e 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/NoVmCrash.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/NoVmCrash.java @@ -1,30 +1,30 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.apache.tools.ant.taskdefs.optional.junit; - -import org.junit.Test; - -/** - */ -public class NoVmCrash { - - @Test - public void testNoCrash() { - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.taskdefs.optional.junit; + +import org.junit.Test; + +/** + */ +public class NoVmCrash { + + @Test + public void testNoCrash() { + } + +} http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Printer.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Printer.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Printer.java index c290772..0200648 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Printer.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Printer.java @@ -1,42 +1,42 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.apache.tools.ant.taskdefs.optional.junit; - -import org.junit.Test; - -/** - */ -public class Printer { - - public Printer() { - System.err.println("constructor print to System.err"); - System.out.println("constructor print to System.out"); - } - - static { - System.err.println("static print to System.err"); - System.out.println("static print to System.out"); - } - - @Test - public void testNoCrash() { - System.err.println("method print to System.err"); - System.out.println("method print to System.out"); - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.taskdefs.optional.junit; + +import org.junit.Test; + +/** + */ +public class Printer { + + public Printer() { + System.err.println("constructor print to System.err"); + System.out.println("constructor print to System.out"); + } + + static { + System.err.println("static print to System.err"); + System.out.println("static print to System.out"); + } + + @Test + public void testNoCrash() { + System.err.println("method print to System.err"); + System.out.println("method print to System.out"); + } + +} http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Sleeper.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Sleeper.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Sleeper.java index 0d0cb67..1509894 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Sleeper.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Sleeper.java @@ -1,30 +1,30 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.apache.tools.ant.taskdefs.optional.junit; - - -import org.junit.Test; - -public class Sleeper { - - @Test - public void testSleep() throws InterruptedException { - Thread.sleep(5 * 1000); - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.taskdefs.optional.junit; + + +import org.junit.Test; + +public class Sleeper { + + @Test + public void testSleep() throws InterruptedException { + Thread.sleep(5 * 1000); + } + +} http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/SuiteMethodTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/SuiteMethodTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/SuiteMethodTest.java index 207dda6..14a0966 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/SuiteMethodTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/SuiteMethodTest.java @@ -1,42 +1,42 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.apache.tools.ant.taskdefs.optional.junit; - -import junit.framework.Test; -import junit.framework.TestCase; - -/** - * validates that the suite() method works in classes that don't - * implement Test. - */ -public class SuiteMethodTest { - - public static Test suite() { - return new Nested("testMethod"); - } - - public static class Nested extends TestCase { - public Nested(String name) { - super(name); - } - - public void testMethod() { - assertTrue(true); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.taskdefs.optional.junit; + +import junit.framework.Test; +import junit.framework.TestCase; + +/** + * validates that the suite() method works in classes that don't + * implement Test. + */ +public class SuiteMethodTest { + + public static Test suite() { + return new Nested("testMethod"); + } + + public static class Nested extends TestCase { + public Nested(String name) { + super(name); + } + + public void testMethod() { + assertTrue(true); + } + } +} http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TearDownOnVmCrashTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TearDownOnVmCrashTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TearDownOnVmCrashTest.java index bfc6d31..eb20284 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TearDownOnVmCrashTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TearDownOnVmCrashTest.java @@ -1,53 +1,53 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.ant.taskdefs.optional.junit; - -import static org.apache.tools.ant.AntAssert.assertContains; -import static org.apache.tools.ant.AntAssert.assertNotContains; -import static org.junit.Assert.assertEquals; - -import org.apache.tools.ant.BuildFileRule; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; - -public class TearDownOnVmCrashTest { - - @Rule - public BuildFileRule buildRule = new BuildFileRule(); - - @Before - public void setUp() { - buildRule.configureProject("src/etc/testcases/taskdefs/optional/junit/teardownlistener.xml"); - } - - @Test - public void testNoTeardown() { - buildRule.executeTarget("testNoTeardown"); - assertEquals("true", buildRule.getProject().getProperty("error")); - assertNotContains("tearDown called on Timeout", buildRule.getOutput()); - } - - @Test - public void testTeardown() { - buildRule.executeTarget("testTeardown"); - assertEquals("true", buildRule.getProject().getProperty("error")); - assertContains("tearDown called on Timeout", buildRule.getOutput()); - } -} \ No newline at end of file +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.taskdefs.optional.junit; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.apache.tools.ant.AntAssert.assertNotContains; +import static org.junit.Assert.assertEquals; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +public class TearDownOnVmCrashTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/junit/teardownlistener.xml"); + } + + @Test + public void testNoTeardown() { + buildRule.executeTarget("testNoTeardown"); + assertEquals("true", buildRule.getProject().getProperty("error")); + assertNotContains("tearDown called on Timeout", buildRule.getOutput()); + } + + @Test + public void testTeardown() { + buildRule.executeTarget("testTeardown"); + assertEquals("true", buildRule.getProject().getProperty("error")); + assertContains("tearDown called on Timeout", buildRule.getOutput()); + } +} http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TestFormatter.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TestFormatter.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TestFormatter.java index d40da0b..27420d6 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TestFormatter.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TestFormatter.java @@ -1,112 +1,112 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.ant.taskdefs.optional.junit; - -import java.io.IOException; -import java.io.OutputStream; - -import junit.framework.AssertionFailedError; -import junit.framework.Test; - -import org.apache.tools.ant.BuildException; - -public class TestFormatter implements JUnitResultFormatter { - - private static final byte[] grafitto = new byte[] { - (byte) 'T', (byte) 'e', (byte) 's', (byte) 't', (byte) 'F', (byte) 'o', - (byte) 'r', (byte) 'm', (byte) 'a', (byte) 't', (byte) 't', (byte) 'e', - (byte) 'r', (byte) ' ', (byte) 'w', (byte) 'a', (byte) 's', (byte) ' ', - (byte) 'h', (byte) 'e', (byte) 'r', (byte) 'e', 10 - }; - - /** - * Where to write the log to. - */ - private OutputStream out; - - /** - * Empty - */ - public TestFormatter() { - } - - /** - * Empty - */ - public void startTestSuite(JUnitTest suite) { - } - /** - * Empty - */ - public void startTest(Test t) { - } - /** - * Empty - */ - public void endTest(Test test) { - } - /** - * Empty - */ - public void addFailure(Test test, Throwable t) { - } - /** - * Empty - */ - public void addFailure(Test test, AssertionFailedError t) { - } - /** - * Empty - */ - public void addError(Test test, Throwable t) { - } - /** - * Empty - */ - public void setSystemOutput(String out) { - } - /** - * Empty - */ - public void setSystemError(String err) { - } - - public void setOutput(OutputStream out) { - this.out = out; - } - - public void endTestSuite(JUnitTest suite) throws BuildException { - if (out != null) { - try { - out.write(grafitto); - out.flush(); - } catch (IOException ioex) { - throw new BuildException("Unable to write output", ioex); - } finally { - if (out != System.out && out != System.err) { - try { - out.close(); - } catch (IOException e) { - // ignore - } - } - } - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.taskdefs.optional.junit; + +import java.io.IOException; +import java.io.OutputStream; + +import junit.framework.AssertionFailedError; +import junit.framework.Test; + +import org.apache.tools.ant.BuildException; + +public class TestFormatter implements JUnitResultFormatter { + + private static final byte[] grafitto = new byte[] { + (byte) 'T', (byte) 'e', (byte) 's', (byte) 't', (byte) 'F', (byte) 'o', + (byte) 'r', (byte) 'm', (byte) 'a', (byte) 't', (byte) 't', (byte) 'e', + (byte) 'r', (byte) ' ', (byte) 'w', (byte) 'a', (byte) 's', (byte) ' ', + (byte) 'h', (byte) 'e', (byte) 'r', (byte) 'e', 10 + }; + + /** + * Where to write the log to. + */ + private OutputStream out; + + /** + * Empty + */ + public TestFormatter() { + } + + /** + * Empty + */ + public void startTestSuite(JUnitTest suite) { + } + /** + * Empty + */ + public void startTest(Test t) { + } + /** + * Empty + */ + public void endTest(Test test) { + } + /** + * Empty + */ + public void addFailure(Test test, Throwable t) { + } + /** + * Empty + */ + public void addFailure(Test test, AssertionFailedError t) { + } + /** + * Empty + */ + public void addError(Test test, Throwable t) { + } + /** + * Empty + */ + public void setSystemOutput(String out) { + } + /** + * Empty + */ + public void setSystemError(String err) { + } + + public void setOutput(OutputStream out) { + this.out = out; + } + + public void endTestSuite(JUnitTest suite) throws BuildException { + if (out != null) { + try { + out.write(grafitto); + out.flush(); + } catch (IOException ioex) { + throw new BuildException("Unable to write output", ioex); + } finally { + if (out != System.out && out != System.err) { + try { + out.close(); + } catch (IOException e) { + // ignore + } + } + } + } + } +} http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/VmCrash.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/VmCrash.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/VmCrash.java index 9c5e589..92d21b6 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/VmCrash.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/VmCrash.java @@ -1,31 +1,31 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.apache.tools.ant.taskdefs.optional.junit; - -import org.junit.Test; - -/** - */ -public class VmCrash { - - @Test - public void testCrash() { - System.exit(0); - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.taskdefs.optional.junit; + +import org.junit.Test; + +/** + */ +public class VmCrash { + + @Test + public void testCrash() { + System.exit(0); + } + +} http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLFormatterWithCDATAOnSystemOut.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLFormatterWithCDATAOnSystemOut.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLFormatterWithCDATAOnSystemOut.java index f28bf72..3f464d8 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLFormatterWithCDATAOnSystemOut.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLFormatterWithCDATAOnSystemOut.java @@ -1,83 +1,83 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package org.apache.tools.ant.taskdefs.optional.junit; - -import java.io.File; -import java.io.FileReader; -import java.io.IOException; - -import org.apache.tools.ant.BuildFileRule; -import org.apache.tools.ant.util.FileUtils; -import org.junit.Rule; -import org.junit.Test; - -import static org.junit.Assert.assertTrue; - -public class XMLFormatterWithCDATAOnSystemOut { - - private static final String DIR = "src/etc/testcases/taskdefs/optional/junit"; - private static final String REPORT = - "TEST-" + XMLFormatterWithCDATAOnSystemOut.class.getName() + ".xml"; - - private static final String TESTDATA = - "<ERROR>" + - "<![CDATA[<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + - " <RESPONSE>" + - " <GDS/>" + - " <ERROR>" + - " <ID/>" + - " <MESSAGE/>" + - " <REQUEST_TYPE/>" + - " <RESEND/>" + - " <RAW_RESPONSE/>" + - " </ERROR>" + - " </RESPONSE>" + - "]]>" + - "</ERROR>"; - - @Rule - public BuildFileRule buildRule = new BuildFileRule(); - - @Test - public void testOutput() { - System.out.println(TESTDATA); - } - - @Test - public void testBuildfile() throws IOException { - buildRule.configureProject(DIR + "/cdataoutput.xml"); - if (buildRule.getProject().getProperty("cdata.inner") == null) { - // avoid endless loop - buildRule.executeTarget("run-junit"); - File f = buildRule.getProject().resolveFile(REPORT); - FileReader reader = null; - try { - reader = new FileReader(f); - String content = FileUtils.readFully(reader); - assertTrue(content.indexOf("</RESPONSE>]]>" - + "</ERROR>") > 0); - } finally { - if (reader != null) { - reader.close(); - } - f.delete(); - } - } - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.taskdefs.optional.junit; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class XMLFormatterWithCDATAOnSystemOut { + + private static final String DIR = "src/etc/testcases/taskdefs/optional/junit"; + private static final String REPORT = + "TEST-" + XMLFormatterWithCDATAOnSystemOut.class.getName() + ".xml"; + + private static final String TESTDATA = + "<ERROR>" + + "<![CDATA[<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + + " <RESPONSE>" + + " <GDS/>" + + " <ERROR>" + + " <ID/>" + + " <MESSAGE/>" + + " <REQUEST_TYPE/>" + + " <RESEND/>" + + " <RAW_RESPONSE/>" + + " </ERROR>" + + " </RESPONSE>" + + "]]>" + + "</ERROR>"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Test + public void testOutput() { + System.out.println(TESTDATA); + } + + @Test + public void testBuildfile() throws IOException { + buildRule.configureProject(DIR + "/cdataoutput.xml"); + if (buildRule.getProject().getProperty("cdata.inner") == null) { + // avoid endless loop + buildRule.executeTarget("run-junit"); + File f = buildRule.getProject().resolveFile(REPORT); + FileReader reader = null; + try { + reader = new FileReader(f); + String content = FileUtils.readFully(reader); + assertTrue(content.indexOf("</RESPONSE>]]>" + + "</ERROR>") > 0); + } finally { + if (reader != null) { + reader.close(); + } + f.delete(); + } + } + } + +} http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java index 095a2f0..c8636b0 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java @@ -1,93 +1,93 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.ant.taskdefs.optional.junit; - -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.PrintWriter; -import java.security.Permission; - -import org.apache.tools.ant.DefaultLogger; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; -import org.apache.tools.ant.types.FileSet; -import org.junit.Assume; -import org.junit.Test; - -public class XMLResultAggregatorTest { - - @Test - public void testFrames() throws Exception { - // For now, skip this test on JDK 6 (and below); see below for why: - try { - Class.forName("java.nio.file.Files"); - } catch (ClassNotFoundException x) { - Assume.assumeNoException("Skip test on JDK 6 and below", x); - } - final File d = new File(System.getProperty("java.io.tmpdir"), "XMLResultAggregatorTest"); - if (d.exists()) { - new Delete() {{removeDir(d);}}; // is there no utility method for this? - } - assertTrue(d.getAbsolutePath(), d.mkdir()); - File xml = new File(d, "x.xml"); - PrintWriter pw = new PrintWriter(new FileOutputStream(xml)); - try { - pw.println("<testsuite errors='0' failures='0' name='my.UnitTest' tests='1'>"); - pw.println(" <testcase classname='my.UnitTest' name='testSomething'/>"); - pw.println("</testsuite>"); - pw.flush(); - } finally { - pw.close(); - } - XMLResultAggregator task = new XMLResultAggregator(); - task.setTodir(d); - Project project = new Project(); - DefaultLogger logger = new DefaultLogger(); - logger.setOutputPrintStream(System.out); - logger.setErrorPrintStream(System.err); - logger.setMessageOutputLevel(Project.MSG_INFO); - project.addBuildListener(logger); - project.init(); - task.setProject(project); - AggregateTransformer report = task.createReport(); - report.setTodir(d); - FileSet fs = new FileSet(); - fs.setFile(xml); - task.addFileSet(fs); - /* getResourceAsStream override unnecessary on JDK 7. Ought to work around JAXP #6723276 in JDK 6, but causes a TypeCheckError in FunctionCall for reasons TBD: - Thread.currentThread().setContextClassLoader(new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) { - public InputStream getResourceAsStream(String name) { - if (name.startsWith("META-INF/services/")) { - return new ByteArrayInputStream(new byte[0]); - } - return super.getResourceAsStream(name); - } - }); - */ - // Use the JRE's Xerces, not lib/optional/xerces.jar: - Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader().getParent()); - // Tickle #51668: - System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}}); - task.execute(); - assertTrue(new File(d, "index.html").isFile()); - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.taskdefs.optional.junit; + +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.security.Permission; + +import org.apache.tools.ant.DefaultLogger; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; +import org.apache.tools.ant.types.FileSet; +import org.junit.Assume; +import org.junit.Test; + +public class XMLResultAggregatorTest { + + @Test + public void testFrames() throws Exception { + // For now, skip this test on JDK 6 (and below); see below for why: + try { + Class.forName("java.nio.file.Files"); + } catch (ClassNotFoundException x) { + Assume.assumeNoException("Skip test on JDK 6 and below", x); + } + final File d = new File(System.getProperty("java.io.tmpdir"), "XMLResultAggregatorTest"); + if (d.exists()) { + new Delete() {{removeDir(d);}}; // is there no utility method for this? + } + assertTrue(d.getAbsolutePath(), d.mkdir()); + File xml = new File(d, "x.xml"); + PrintWriter pw = new PrintWriter(new FileOutputStream(xml)); + try { + pw.println("<testsuite errors='0' failures='0' name='my.UnitTest' tests='1'>"); + pw.println(" <testcase classname='my.UnitTest' name='testSomething'/>"); + pw.println("</testsuite>"); + pw.flush(); + } finally { + pw.close(); + } + XMLResultAggregator task = new XMLResultAggregator(); + task.setTodir(d); + Project project = new Project(); + DefaultLogger logger = new DefaultLogger(); + logger.setOutputPrintStream(System.out); + logger.setErrorPrintStream(System.err); + logger.setMessageOutputLevel(Project.MSG_INFO); + project.addBuildListener(logger); + project.init(); + task.setProject(project); + AggregateTransformer report = task.createReport(); + report.setTodir(d); + FileSet fs = new FileSet(); + fs.setFile(xml); + task.addFileSet(fs); + /* getResourceAsStream override unnecessary on JDK 7. Ought to work around JAXP #6723276 in JDK 6, but causes a TypeCheckError in FunctionCall for reasons TBD: + Thread.currentThread().setContextClassLoader(new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) { + public InputStream getResourceAsStream(String name) { + if (name.startsWith("META-INF/services/")) { + return new ByteArrayInputStream(new byte[0]); + } + return super.getResourceAsStream(name); + } + }); + */ + // Use the JRE's Xerces, not lib/optional/xerces.jar: + Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader().getParent()); + // Tickle #51668: + System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}}); + task.execute(); + assertTrue(new File(d, "index.html").isFile()); + } + +}
