Repository: ant
Updated Branches:
  refs/heads/master febba1034 -> 6eefa0f43


More isEmpty(), less assertThat()

Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/6eefa0f4
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/6eefa0f4
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/6eefa0f4

Branch: refs/heads/master
Commit: 6eefa0f435cba1d9241cb53e2245bdca218a0748
Parents: febba10
Author: Gintas Grigelionis <[email protected]>
Authored: Mon Apr 16 07:10:44 2018 +0200
Committer: Gintas Grigelionis <[email protected]>
Committed: Mon Apr 16 07:10:44 2018 +0200

----------------------------------------------------------------------
 .../apache/tools/ant/filters/HeadTailTest.java  | 29 +++++++++++++-------
 .../org/apache/tools/ant/taskdefs/AntTest.java  |  6 ++--
 .../apache/tools/ant/taskdefs/BZip2Test.java    | 11 ++------
 .../apache/tools/ant/taskdefs/EchoXMLTest.java  | 26 +++++++-----------
 .../ant/types/optional/ScriptSelectorTest.java  | 18 +++++-------
 5 files changed, 41 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/6eefa0f4/src/tests/junit/org/apache/tools/ant/filters/HeadTailTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/filters/HeadTailTest.java 
b/src/tests/junit/org/apache/tools/ant/filters/HeadTailTest.java
index 21d25a1..31a84a3 100644
--- a/src/tests/junit/org/apache/tools/ant/filters/HeadTailTest.java
+++ b/src/tests/junit/org/apache/tools/ant/filters/HeadTailTest.java
@@ -49,7 +49,8 @@ public class HeadTailTest {
         buildRule.executeTarget("testHead");
         File expected = 
buildRule.getProject().resolveFile("expected/head-tail.head.test");
         File result = new File(buildRule.getProject().getProperty("output") + 
"/head-tail.head.test");
-        assertEquals("testHead: Result not like expected", 
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
+        assertEquals("testHead: Result not like expected",
+                FileUtilities.getFileContents(expected), 
FileUtilities.getFileContents(result));
     }
 
     @Test
@@ -57,7 +58,8 @@ public class HeadTailTest {
         buildRule.executeTarget("testHeadLines");
         File expected = 
buildRule.getProject().resolveFile("expected/head-tail.headLines.test");
         File result = new File(buildRule.getProject().getProperty("output") + 
"/head-tail.headLines.test");
-        assertEquals("testHeadLines: Result not like expected", 
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
+        assertEquals("testHeadLines: Result not like expected",
+                FileUtilities.getFileContents(expected), 
FileUtilities.getFileContents(result));
     }
 
     @Test
@@ -65,7 +67,8 @@ public class HeadTailTest {
         buildRule.executeTarget("testHeadSkip");
         File expected = 
buildRule.getProject().resolveFile("expected/head-tail.headSkip.test");
         File result = new File(buildRule.getProject().getProperty("output") + 
"/head-tail.headSkip.test");
-        assertEquals("testHeadSkip: Result not like expected", 
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
+        assertEquals("testHeadSkip: Result not like expected",
+                FileUtilities.getFileContents(expected), 
FileUtilities.getFileContents(result));
     }
 
     @Test
@@ -73,7 +76,8 @@ public class HeadTailTest {
         buildRule.executeTarget("testHeadLinesSkip");
         File expected = 
buildRule.getProject().resolveFile("expected/head-tail.headLinesSkip.test");
         File result = new File(buildRule.getProject().getProperty("output") + 
"/head-tail.headLinesSkip.test");
-        assertEquals("testHeadLinesSkip: Result not like expected", 
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
+        assertEquals("testHeadLinesSkip: Result not like expected",
+                FileUtilities.getFileContents(expected), 
FileUtilities.getFileContents(result));
     }
 
     @Test
@@ -88,9 +92,10 @@ public class HeadTailTest {
     @Test
     public void testTail() throws IOException {
         buildRule.executeTarget("testTail");
-        File expected 
=buildRule.getProject().resolveFile("expected/head-tail.tail.test");
+        File expected = 
buildRule.getProject().resolveFile("expected/head-tail.tail.test");
         File result = new File(buildRule.getProject().getProperty("output") + 
"/head-tail.tail.test");
-        assertEquals("testTail: Result not like expected", 
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
+        assertEquals("testTail: Result not like expected",
+                FileUtilities.getFileContents(expected), 
FileUtilities.getFileContents(result));
     }
 
     @Test
@@ -98,7 +103,8 @@ public class HeadTailTest {
         buildRule.executeTarget("testTailLines");
         File expected = 
buildRule.getProject().resolveFile("expected/head-tail.tailLines.test");
         File result = new File(buildRule.getProject().getProperty("output") + 
"/head-tail.tailLines.test");
-        assertEquals("testTailLines: Result not like expected", 
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
+        assertEquals("testTailLines: Result not like expected",
+                FileUtilities.getFileContents(expected), 
FileUtilities.getFileContents(result));
     }
 
     @Test
@@ -106,7 +112,8 @@ public class HeadTailTest {
         buildRule.executeTarget("testTailSkip");
         File expected = 
buildRule.getProject().resolveFile("expected/head-tail.tailSkip.test");
         File result = new File(buildRule.getProject().getProperty("output") + 
"/head-tail.tailSkip.test");
-        assertEquals("testTailSkip: Result not like expected", 
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
+        assertEquals("testTailSkip: Result not like expected",
+                FileUtilities.getFileContents(expected), 
FileUtilities.getFileContents(result));
     }
 
     @Test
@@ -114,7 +121,8 @@ public class HeadTailTest {
         buildRule.executeTarget("testTailLinesSkip");
         File expected = 
buildRule.getProject().resolveFile("expected/head-tail.tailLinesSkip.test");
         File result = new File(buildRule.getProject().getProperty("output") + 
"/head-tail.tailLinesSkip.test");
-        assertEquals("testTailLinesSkip: Result not like expected", 
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
+        assertEquals("testTailLinesSkip: Result not like expected",
+                FileUtilities.getFileContents(expected), 
FileUtilities.getFileContents(result));
     }
 
     @Test
@@ -131,7 +139,8 @@ public class HeadTailTest {
         buildRule.executeTarget("testHeadTail");
         File expected = 
buildRule.getProject().resolveFile("expected/head-tail.headtail.test");
         File result = new File(buildRule.getProject().getProperty("output") + 
"/head-tail.headtail.test");
-        assertEquals("testHeadTail: Result not like expected", 
FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result));
+        assertEquals("testHeadTail: Result not like expected",
+                FileUtilities.getFileContents(expected), 
FileUtilities.getFileContents(result));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/6eefa0f4/src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java 
b/src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java
index 778fba7..0cb2674 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java
@@ -425,7 +425,7 @@ public class AntTest {
         }
 
         public void targetStarted(BuildEvent event) {
-            if (event.getTarget().getName().equals("")) {
+            if (event.getTarget().getName().isEmpty()) {
                 return;
             }
             if (error == null) {
@@ -476,7 +476,7 @@ public class AntTest {
         }
 
         public void targetStarted(BuildEvent event) {
-            if (event.getTarget().getName().equals("")) {
+            if (event.getTarget().getName().isEmpty()) {
                 return;
             }
             if (error == null) {
@@ -602,7 +602,7 @@ public class AntTest {
         }
 
         public void targetStarted(BuildEvent event) {
-            if (event.getTarget().getName().equals("")) {
+            if (event.getTarget().getName().isEmpty()) {
                 return;
             }
             if (calls >= expectedValues.length) {

http://git-wip-us.apache.org/repos/asf/ant/blob/6eefa0f4/src/tests/junit/org/apache/tools/ant/taskdefs/BZip2Test.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/BZip2Test.java 
b/src/tests/junit/org/apache/tools/ant/taskdefs/BZip2Test.java
index d080fae..9b5ce0b 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/BZip2Test.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/BZip2Test.java
@@ -32,7 +32,6 @@ import java.io.InputStream;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 /**
  */
@@ -83,14 +82,8 @@ public class BZip2Test {
         while (true) {
             int expected = originalIn.read();
             int actual   = actualIn.read();
-            if (expected >= 0) {
-                if (expected != actual) {
-                    fail("File content mismatch");
-                }
-            } else {
-                if (actual >= 0) {
-                    fail("File content mismatch");
-                }
+            assertEquals("File content mismatch", expected, actual);
+            if (expected < 0) {
                 break;
             }
         }

http://git-wip-us.apache.org/repos/asf/ant/blob/6eefa0f4/src/tests/junit/org/apache/tools/ant/taskdefs/EchoXMLTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/EchoXMLTest.java 
b/src/tests/junit/org/apache/tools/ant/taskdefs/EchoXMLTest.java
index 5d83a8f..48689b1 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/EchoXMLTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/EchoXMLTest.java
@@ -24,16 +24,16 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
-
-import static org.hamcrest.Matchers.containsString;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
+import org.junit.rules.ExpectedException;
 
 public class EchoXMLTest {
 
     @Rule
     public final BuildFileRule buildRule = new BuildFileRule();
 
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
     @Before
     public void setUp() {
         buildRule.configureProject("src/etc/testcases/taskdefs/echoxml.xml");
@@ -51,22 +51,16 @@ public class EchoXMLTest {
 
     @Test
     public void testFail() {
-        try {
-            buildRule.executeTarget("testFail");
-            fail("BuildException expected: must fail");
-        } catch (BuildException ex) {
-            assertThat(ex.getMessage(), containsString("${foo}=bar"));
-        }
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("${foo}=bar");
+        buildRule.executeTarget("testFail");
     }
 
     @Test
     public void testEmpty() {
-        try {
-            buildRule.executeTarget("testEmpty");
-            fail("BuildException expected: must fail");
-        } catch (BuildException ex) {
-            assertThat(ex.getMessage(), containsString("No nested XML 
specified"));
-        }
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("No nested XML specified");
+        buildRule.executeTarget("testEmpty");
     }
 
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/6eefa0f4/src/tests/junit/org/apache/tools/ant/types/optional/ScriptSelectorTest.java
----------------------------------------------------------------------
diff --git 
a/src/tests/junit/org/apache/tools/ant/types/optional/ScriptSelectorTest.java 
b/src/tests/junit/org/apache/tools/ant/types/optional/ScriptSelectorTest.java
index d1a8fe1..2b8e5bd 100644
--- 
a/src/tests/junit/org/apache/tools/ant/types/optional/ScriptSelectorTest.java
+++ 
b/src/tests/junit/org/apache/tools/ant/types/optional/ScriptSelectorTest.java
@@ -22,10 +22,7 @@ import org.apache.tools.ant.BuildFileRule;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
-
-import static org.hamcrest.Matchers.containsString;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
+import org.junit.rules.ExpectedException;
 
 /**
  * Test that scripting selection works. Needs scripting support to work
@@ -35,6 +32,9 @@ public class ScriptSelectorTest {
     @Rule
     public BuildFileRule buildRule = new BuildFileRule();
 
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
     @Before
     public void setUp() {
         
buildRule.configureProject("src/etc/testcases/types/selectors/scriptselector.xml");
@@ -42,13 +42,9 @@ public class ScriptSelectorTest {
 
     @Test
     public void testNolanguage() {
-        try {
-            buildRule.executeTarget("testNolanguage");
-            fail("Absence of language attribute not detected");
-        } catch (BuildException ex) {
-            assertThat(ex.getMessage(), containsString("script language must 
be specified"));
-
-        }
+        thrown.expect(BuildException.class);
+        thrown.expectMessage("script language must be specified");
+        buildRule.executeTarget("testNolanguage");
     }
 
     @Test

Reply via email to