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


More string matcher assertions

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

Branch: refs/heads/master
Commit: 761f8e60bc203d830c25afb2136cd1d435817024
Parents: 6eefa0f
Author: Gintas Grigelionis <gin...@apache.org>
Authored: Mon Apr 16 09:00:15 2018 +0200
Committer: Gintas Grigelionis <gin...@apache.org>
Committed: Mon Apr 16 09:00:15 2018 +0200

----------------------------------------------------------------------
 .../tools/ant/filters/ConcatFilterTest.java     | 13 ++--
 .../tools/ant/filters/TokenFilterTest.java      | 25 ++++---
 .../apache/tools/ant/taskdefs/BZip2Test.java    |  8 +--
 .../org/apache/tools/ant/taskdefs/GzipTest.java | 73 ++++++++++----------
 .../apache/tools/ant/taskdefs/ManifestTest.java |  3 +-
 .../ant/taskdefs/optional/TraXLiaisonTest.java  |  9 +--
 .../taskdefs/optional/junit/JUnitTaskTest.java  | 37 ++++------
 .../ant/types/resources/JavaResourceTest.java   |  7 +-
 .../types/selectors/ModifiedSelectorTest.java   |  5 +-
 .../apache/tools/ant/util/FileUtilsTest.java    | 23 +++---
 .../apache/tools/ant/util/JAXPUtilsTest.java    |  9 +--
 .../apache/tools/ant/util/JavaEnvUtilsTest.java | 33 +++++----
 .../util/LayoutPreservingPropertiesTest.java    |  6 +-
 .../apache/tools/ant/util/StringUtilsTest.java  | 14 ++--
 14 files changed, 134 insertions(+), 131 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/761f8e60/src/tests/junit/org/apache/tools/ant/filters/ConcatFilterTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/filters/ConcatFilterTest.java 
b/src/tests/junit/org/apache/tools/ant/filters/ConcatFilterTest.java
index 06cd2f8..a7857b2 100644
--- a/src/tests/junit/org/apache/tools/ant/filters/ConcatFilterTest.java
+++ b/src/tests/junit/org/apache/tools/ant/filters/ConcatFilterTest.java
@@ -28,8 +28,10 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import static org.hamcrest.Matchers.endsWith;
+import static org.hamcrest.Matchers.startsWith;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThat;
 
 /**
  * JUnit Testcases for ConcatReader
@@ -79,8 +81,8 @@ public class ConcatFilterTest {
         buildRule.executeTarget("testFilterReaderNoArgs");
         File expected = new File(buildRule.getProject().getProperty("output"), 
"concatfilter.test");
         File result = new File(buildRule.getProject().getProperty("output"),  
"concat.FilterReaderNoArgs.test");
-        assertEquals("testFilterReaderNoArgs: Result not like expected", 
FileUtilities.getFileContents(expected),
-                FileUtilities.getFileContents(result));
+        assertEquals("testFilterReaderNoArgs: Result not like expected",
+                FileUtilities.getFileContents(expected), 
FileUtilities.getFileContents(result));
     }
 
     @Test
@@ -131,9 +133,8 @@ public class ConcatFilterTest {
         buildRule.executeTarget(target);
         String resultContent = FileUtilities.getFileContents(
                 new File(buildRule.getProject().getProperty("output") + 
"/concat." + target.substring(4) + ".test"));
-        assertTrue("First 5 lines differs.", 
resultContent.startsWith(expectedStart));
-        assertTrue("Last 5 lines differs.", 
resultContent.endsWith(expectedEnd));
+        assertThat("First 5 lines differs.", resultContent, 
startsWith(expectedStart));
+        assertThat("Last 5 lines differs.", resultContent, 
endsWith(expectedEnd));
     }
 
-
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/761f8e60/src/tests/junit/org/apache/tools/ant/filters/TokenFilterTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/filters/TokenFilterTest.java 
b/src/tests/junit/org/apache/tools/ant/filters/TokenFilterTest.java
index fb60f2c..30f5bc0 100644
--- a/src/tests/junit/org/apache/tools/ant/filters/TokenFilterTest.java
+++ b/src/tests/junit/org/apache/tools/ant/filters/TokenFilterTest.java
@@ -18,11 +18,12 @@
 
 package org.apache.tools.ant.filters;
 
+import static org.hamcrest.Matchers.both;
 import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.endsWith;
 import static org.hamcrest.Matchers.not;
-import static org.junit.Assert.assertFalse;
+import static org.hamcrest.Matchers.startsWith;
 import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assume.assumeTrue;
 
 import java.io.FileReader;
@@ -77,7 +78,6 @@ public class TokenFilterTest {
 
     @Test
     public void testDosLineOutput() throws IOException {
-
         buildRule.executeTarget("doslineoutput");
         assertThat(getFileString(buildRule.getProject().getProperty("output") 
+ "/doslineoutput"),
                 
containsString("\r\nThis\r\nis\r\na\r\nnumber\r\nof\r\nwords\r\n"));
@@ -86,9 +86,8 @@ public class TokenFilterTest {
     @Test
     public void testFileTokenizer() throws IOException {
         buildRule.executeTarget("filetokenizer");
-        String contents = 
getFileString(buildRule.getProject().getProperty("output") + "/filetokenizer");
-        assertThat(contents, containsString("   of words"));
-        assertThat(contents, not(containsString(" This is")));
+        assertThat(getFileString(buildRule.getProject().getProperty("output") 
+ "/filetokenizer"),
+                both(containsString("   of words")).and(not(containsString(" 
This is"))));
     }
 
     @Test
@@ -107,9 +106,9 @@ public class TokenFilterTest {
     @Test
     public void testContainsString() throws IOException {
         buildRule.executeTarget("containsstring");
-        String contents = 
getFileString(buildRule.getProject().getProperty("output") + "/containsstring");
-        assertThat(contents, containsString("this is a line contains foo"));
-        assertThat(contents, not(containsString("this line does not")));
+        assertThat(getFileString(buildRule.getProject().getProperty("output") 
+ "/containsstring"),
+                both(containsString("this is a line contains foo"))
+                        .and(not(containsString("this line does not"))));
     }
 
     @Test
@@ -154,8 +153,8 @@ public class TokenFilterTest {
     public void testTrimFile() throws IOException {
         buildRule.executeTarget("trimfile");
         String contents = 
getFileString(buildRule.getProject().getProperty("output") + "/trimfile");
-        assertTrue("no ws at start", contents.startsWith("This is th"));
-        assertTrue("no ws at end", contents.endsWith("second line."));
+        assertThat("no ws at start", contents, startsWith("This is th"));
+        assertThat("no ws at end", contents, endsWith("second line."));
         assertThat(contents, containsString("  This is the second"));
     }
 
@@ -163,8 +162,8 @@ public class TokenFilterTest {
     public void testTrimFileByLine() throws IOException {
         buildRule.executeTarget("trimfilebyline");
         String contents = 
getFileString(buildRule.getProject().getProperty("output") + "/trimfilebyline");
-        assertFalse("no ws at start", contents.startsWith("This is th"));
-        assertFalse("no ws at end", contents.endsWith("second line."));
+        assertThat("no ws at start", contents, not(startsWith("This is th")));
+        assertThat("no ws at end", contents, not(endsWith("second line.")));
         assertThat(contents, not(containsString("  This is the second")));
         assertThat(contents, containsString("file.\nThis is the second"));
     }

http://git-wip-us.apache.org/repos/asf/ant/blob/761f8e60/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 9b5ce0b..5620afd 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/BZip2Test.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/BZip2Test.java
@@ -30,8 +30,9 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
+import static org.hamcrest.Matchers.endsWith;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThat;
 
 /**
  */
@@ -101,9 +102,8 @@ public class BZip2Test {
     public void testDateCheck() {
         buildRule.executeTarget("testDateCheck");
         String log = buildRule.getLog();
-        assertTrue(
-            "Expecting message ending with 'asf-logo.gif.bz2 is up to date.' 
but got '" + log + "'",
-            log.endsWith("asf-logo.gif.bz2 is up to date."));
+        assertThat("Expecting message ending with 'asf-logo.gif.bz2 is up to 
date.' but got '"
+                        + log + "'", log, endsWith("asf-logo.gif.bz2 is up to 
date."));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/761f8e60/src/tests/junit/org/apache/tools/ant/taskdefs/GzipTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/GzipTest.java 
b/src/tests/junit/org/apache/tools/ant/taskdefs/GzipTest.java
index 76342b8..f2862e3 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/GzipTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/GzipTest.java
@@ -24,9 +24,11 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.hamcrest.Matchers.endsWith;
+import static org.hamcrest.Matchers.startsWith;
+import static org.junit.Assert.assertThat;
 
 /**
  */
@@ -35,60 +37,58 @@ public class GzipTest {
     @Rule
     public final BuildFileRule buildRule = new BuildFileRule();
 
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
 
     @Before
     public void setUp() {
         buildRule.configureProject("src/etc/testcases/taskdefs/gzip.xml");
     }
 
-    @Test
+    /**
+     * Fail due to missing required argument
+     */
+    @Test(expected = BuildException.class)
     public void test1() {
-        try {
-            buildRule.executeTarget("test1");
-            fail("BuildException expected: required argument missing");
-        } catch (BuildException ex) {
-            //TODO assert value
-        }
+        buildRule.executeTarget("test1");
+        // TODO assert value
     }
 
-    @Test
+    /**
+     * Fail due to missing required argument
+     */
+    @Test(expected = BuildException.class)
     public void test2() {
-        try {
-            buildRule.executeTarget("test2");
-            fail("BuildException expected: required argument missing");
-        } catch (BuildException ex) {
-            //TODO assert value
-        }
+        buildRule.executeTarget("test2");
+        // TODO assert value
     }
 
-    @Test
+    /**
+     * Fail due to missing required argument
+     */
+    @Test(expected = BuildException.class)
     public void test3() {
-        try {
-            buildRule.executeTarget("test3");
-            fail("BuildException expected: required argument missing");
-        } catch (BuildException ex) {
-            //TODO assert value
-        }
+        buildRule.executeTarget("test3");
+        // TODO assert value
     }
 
-    @Test
+    /**
+     * Fail due to zipfile pointing to a directory
+     */
+    @Test(expected = BuildException.class)
     public void test4() {
-        try {
-            buildRule.executeTarget("test4");
-            fail("BuildException expected: zipfile must not point to a 
directory");
-        } catch (BuildException ex) {
-            //TODO assert value
-        }
+        buildRule.executeTarget("test4");
+        // TODO assert value
     }
 
     @Test
     public void testGZip() {
         buildRule.executeTarget("realTest");
         String log = buildRule.getLog();
-        assertTrue("Expecting message starting with 'Building:' but got '"
-            + log + "'", log.startsWith("Building:"));
-        assertTrue("Expecting message ending with 'asf-logo.gif.gz' but got '"
-            + log + "'", log.endsWith("asf-logo.gif.gz"));
+        assertThat("Expecting message starting with 'Building:' but got '"
+                + log + "'", log, startsWith("Building:"));
+        assertThat("Expecting message ending with 'asf-logo.gif.gz' but got '"
+                + log + "'", log, endsWith("asf-logo.gif.gz"));
     }
 
     @Test
@@ -100,9 +100,8 @@ public class GzipTest {
     public void testDateCheck() {
         buildRule.executeTarget("testDateCheck");
         String log = buildRule.getLog();
-        assertTrue(
-            "Expecting message ending with 'asf-logo.gif.gz is up to date.' 
but got '" + log + "'",
-            log.endsWith("asf-logo.gif.gz is up to date."));
+        assertThat("Expecting message ending with 'asf-logo.gif.gz is up to 
date.' but got '"
+                + log + "'", log, endsWith("asf-logo.gif.gz is up to date."));
     }
 
     @After

http://git-wip-us.apache.org/repos/asf/ant/blob/761f8e60/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java 
b/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java
index 283181e..7a72fd3 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java
@@ -37,6 +37,7 @@ import org.junit.rules.ExpectedException;
 
 import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.startsWith;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
@@ -370,7 +371,7 @@ public class ManifestTest {
         assertNotEquals(Manifest.getDefaultManifest(), mf);
         String mfAsString = mf.toString();
         assertNotNull(mfAsString);
-        assertTrue(mfAsString.startsWith("Manifest-Version: 2.0"));
+        assertThat(mfAsString, startsWith("Manifest-Version: 2.0"));
         assertThat(mfAsString, containsString("Foo: Bar"));
 
         mf = getManifest(new File(outDir, "mftest2.mf"));

http://git-wip-us.apache.org/repos/asf/ant/blob/761f8e60/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java
----------------------------------------------------------------------
diff --git 
a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java 
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java
index 196b38c..704a4c0 100644
--- 
a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java
+++ 
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java
@@ -18,8 +18,9 @@
 
 package org.apache.tools.ant.taskdefs.optional;
 
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.startsWith;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assume.assumeFalse;
 import static org.junit.Assume.assumeNoException;
 import static org.junit.Assume.assumeTrue;
@@ -162,8 +163,8 @@ public class TraXLiaisonTest extends 
AbstractXSLTLiaisonTest implements XSLTLogg
             file = new File("/user/local/bin");
         }
         String systemid = JAXPUtils.getSystemId(file);
-        assertTrue("SystemIDs should start by file:/", 
systemid.startsWith("file:/"));
-        assertFalse("SystemIDs should not start with file:////", 
systemid.startsWith("file:////"));
+        assertThat("SystemIDs should start by file:/", systemid, 
startsWith("file:/"));
+        assertThat("SystemIDs should not start with file:////", systemid, 
not(startsWith("file:////")));
     }
 
     public void log(String message) {

http://git-wip-us.apache.org/repos/asf/ant/blob/761f8e60/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 5df984b..0eeb833 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
@@ -19,6 +19,7 @@ package org.apache.tools.ant.taskdefs.optional.junit;
 
 import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.startsWith;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -27,7 +28,6 @@ import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assume.assumeTrue;
 
-
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -254,9 +254,11 @@ public class JUnitTaskTest {
         assertTrue("The collector file '" + collectorFile.getAbsolutePath()
                    + "' should exist after the 4th run.",
                    collectorFile.exists());
-        //TODO: these two statements fail
-        
//buildRule.executeTarget("A.test02");assertThat(buildRule.getOutput(), 
not(containsString("4th run: should not run A.test02")));
-        
//buildRule.executeTarget("A.test03");assertThat(buildRule.getOutput(), 
not(containsString("4th run: should not run A.test03")));
+        //TODO: these statements fail
+        //buildRule.executeTarget("A.test02");
+        //assertThat(buildRule.getOutput(), not(containsString("4th run: 
should not run A.test02")));
+        //buildRule.executeTarget("A.test03");
+        //assertThat(buildRule.getOutput(), not(containsString("4th run: 
should not run A.test03")));
         buildRule.executeTarget("B.test04");
         assertThat(buildRule.getOutput(), containsString("4th run: should run 
B.test04"));
         buildRule.executeTarget("D.test10");
@@ -307,41 +309,32 @@ public class JUnitTaskTest {
     }
 
     private void assertOutput() throws IOException {
-        FileReader inner = new FileReader(new File(buildRule.getOutputDir(),
-                                          "testlog.txt"));
-        BufferedReader reader = new BufferedReader(inner);
-        try {
+        FileReader inner = new FileReader(new File(buildRule.getOutputDir(), 
"testlog.txt"));
+        try (BufferedReader reader = new BufferedReader(inner)) {
             String line = reader.readLine();
-            assertEquals("Testsuite: 
org.apache.tools.ant.taskdefs.optional.junit.Printer",
-                         line);
+            assertEquals("Testsuite: 
org.apache.tools.ant.taskdefs.optional.junit.Printer", line);
             line = reader.readLine();
             assertNotNull(line);
-            assertTrue(line.startsWith("Tests run: 1, Failures: 0, Errors: 0, 
Skipped: 0, Time elapsed:"));
+            assertThat(line, startsWith("Tests run: 1, Failures: 0, Errors: 0, 
Skipped: 0, Time elapsed:"));
             line = reader.readLine();
-            assertEquals("------------- Standard Output ---------------",
-                         line);
+            assertEquals("------------- Standard Output ---------------", 
line);
             assertPrint(reader.readLine(), "static", "out");
             assertPrint(reader.readLine(), "constructor", "out");
             assertPrint(reader.readLine(), "method", "out");
             line = reader.readLine();
-            assertEquals("------------- ---------------- ---------------",
-                         line);
+            assertEquals("------------- ---------------- ---------------", 
line);
             line = reader.readLine();
-            assertEquals("------------- Standard Error -----------------",
-                         line);
+            assertEquals("------------- Standard Error -----------------", 
line);
             assertPrint(reader.readLine(), "static", "err");
             assertPrint(reader.readLine(), "constructor", "err");
             assertPrint(reader.readLine(), "method", "err");
             line = reader.readLine();
-            assertEquals("------------- ---------------- ---------------",
-                         line);
+            assertEquals("------------- ---------------- ---------------", 
line);
             line = reader.readLine();
             assertEquals("", line);
             line = reader.readLine();
             assertNotNull(line);
-            assertTrue(line.startsWith("Testcase: testNoCrash took "));
-        } finally {
-            inner.close();
+            assertThat(line, startsWith("Testcase: testNoCrash took "));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ant/blob/761f8e60/src/tests/junit/org/apache/tools/ant/types/resources/JavaResourceTest.java
----------------------------------------------------------------------
diff --git 
a/src/tests/junit/org/apache/tools/ant/types/resources/JavaResourceTest.java 
b/src/tests/junit/org/apache/tools/ant/types/resources/JavaResourceTest.java
index a67db39..8325ed0 100644
--- a/src/tests/junit/org/apache/tools/ant/types/resources/JavaResourceTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/resources/JavaResourceTest.java
@@ -22,9 +22,10 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import static org.hamcrest.Matchers.startsWith;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThat;
 
 public class JavaResourceTest {
 
@@ -43,8 +44,8 @@ public class JavaResourceTest {
 
         // this actually relies on the first manifest being found on
         // the classpath (probably rt.jar's) being valid
-        assertTrue(buildRule.getProject().getProperty("manifest")
-                   .startsWith("Manifest-Version:"));
+        assertThat(buildRule.getProject().getProperty("manifest"),
+                   startsWith("Manifest-Version:"));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/ant/blob/761f8e60/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
----------------------------------------------------------------------
diff --git 
a/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
 
b/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
index 7d7b00e..cd71434 100644
--- 
a/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
+++ 
b/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
@@ -47,6 +47,7 @@ import org.junit.Rule;
 import org.junit.Test;
 
 import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.startsWith;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
@@ -161,13 +162,13 @@ public class ModifiedSelectorTest {
     @Test
     public void testCustomAlgorithm() {
         String algo = 
getAlgoName("org.apache.tools.ant.types.selectors.modifiedselector.HashvalueAlgorithm");
-        assertTrue("Wrong algorithm used: " + algo, 
algo.startsWith("HashvalueAlgorithm"));
+        assertThat("Wrong algorithm used: " + algo, algo, 
startsWith("HashvalueAlgorithm"));
     }
 
     @Test
     public void testCustomAlgorithm2() {
         String algo = 
getAlgoName("org.apache.tools.ant.types.selectors.MockAlgorithm");
-        assertTrue("Wrong algorithm used: " + algo, 
algo.startsWith("MockAlgorithm"));
+        assertThat("Wrong algorithm used: " + algo, algo, 
startsWith("MockAlgorithm"));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/ant/blob/761f8e60/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java 
b/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java
index c44c8f9..43520ad 100644
--- a/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java
@@ -28,9 +28,12 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import static org.hamcrest.Matchers.endsWith;
+import static org.hamcrest.Matchers.startsWith;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.junit.Assume.assumeTrue;
@@ -344,8 +347,8 @@ public class FileUtilsTest {
         File tmp1 = FILE_UTILS.createTempFile("pre", ".suf", null, false, 
true);
         String tmploc = System.getProperty("java.io.tmpdir");
         String name = tmp1.getName();
-        assertTrue("starts with pre", name.startsWith("pre"));
-        assertTrue("ends with .suf", name.endsWith(".suf"));
+        assertThat("starts with pre", name, startsWith("pre"));
+        assertThat("ends with .suf", name, endsWith(".suf"));
         assertTrue("File was created", tmp1.exists());
         assertEquals((new File(tmploc, tmp1.getName())).getAbsolutePath(),
                 tmp1.getAbsolutePath());
@@ -357,8 +360,8 @@ public class FileUtilsTest {
 
         File tmp2 = FILE_UTILS.createTempFile("pre", ".suf", dir2, true, true);
         String name2 = tmp2.getName();
-        assertTrue("starts with pre", name2.startsWith("pre"));
-        assertTrue("ends with .suf", name2.endsWith(".suf"));
+        assertThat("starts with pre", name2, startsWith("pre"));
+        assertThat("ends with .suf", name2, endsWith(".suf"));
         assertTrue("File was created", tmp2.exists());
         assertEquals((new File(dir2, tmp2.getName())).getAbsolutePath(),
                 tmp2.getAbsolutePath());
@@ -370,8 +373,8 @@ public class FileUtilsTest {
         assertFalse("new file", tmp1.exists());
 
         name = tmp1.getName();
-        assertTrue("starts with pre", name.startsWith("pre"));
-        assertTrue("ends with .suf", name.endsWith(".suf"));
+        assertThat("starts with pre", name, startsWith("pre"));
+        assertThat("ends with .suf", name, endsWith(".suf"));
         assertEquals("is inside parent dir", parent.getAbsolutePath(), tmp1
                 .getParent());
 
@@ -485,14 +488,14 @@ public class FileUtilsTest {
         }
         if (File.pathSeparatorChar == '/') {
             assertEquals("file:/foo", 
removeExtraneousAuthority(FILE_UTILS.toURI("/foo")));
-            assertTrue("file: URIs must name absolute paths", 
FILE_UTILS.toURI("./foo").startsWith("file:/"));
-            assertTrue(FILE_UTILS.toURI("./foo").endsWith("/foo"));
+            assertThat("file: URIs must name absolute paths", 
FILE_UTILS.toURI("./foo"), startsWith("file:/"));
+            assertThat(FILE_UTILS.toURI("./foo"), endsWith("/foo"));
             assertEquals("file:/" + dosRoot + "foo%20bar", 
removeExtraneousAuthority(FILE_UTILS.toURI("/foo bar")));
             assertEquals("file:/" + dosRoot + "foo%23bar", 
removeExtraneousAuthority(FILE_UTILS.toURI("/foo#bar")));
         } else if (File.pathSeparatorChar == '\\') {
             assertEquals("file:/" + dosRoot + "foo", 
removeExtraneousAuthority(FILE_UTILS.toURI("\\foo")));
-            assertTrue("file: URIs must name absolute paths", 
FILE_UTILS.toURI(".\\foo").startsWith("file:/"));
-            assertTrue(FILE_UTILS.toURI(".\\foo").endsWith("/foo"));
+            assertThat("file: URIs must name absolute paths", 
FILE_UTILS.toURI(".\\foo"), startsWith("file:/"));
+            assertThat(FILE_UTILS.toURI(".\\foo"), endsWith("/foo"));
             assertEquals("file:/" + dosRoot + "foo%20bar", 
removeExtraneousAuthority(FILE_UTILS.toURI("\\foo bar")));
             assertEquals("file:/" + dosRoot + "foo%23bar", 
removeExtraneousAuthority(FILE_UTILS.toURI("\\foo#bar")));
         }

http://git-wip-us.apache.org/repos/asf/ant/blob/761f8e60/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java 
b/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java
index 924de6e..c6ef5de 100644
--- a/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java
@@ -21,8 +21,9 @@ import org.junit.Test;
 
 import java.io.File;
 
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.startsWith;
+import static org.junit.Assert.assertThat;
 
 /**
  * JAXPUtils test case
@@ -38,7 +39,7 @@ public class JAXPUtilsTest {
             file = new File("/user/local/bin");
         }
         String systemid = JAXPUtils.getSystemId(file);
-        assertTrue("SystemIDs should start by file:/", 
systemid.startsWith("file:/"));
-        assertFalse("SystemIDs should not start with file:////", 
systemid.startsWith("file:////"));
+        assertThat("SystemIDs should start by file:/", systemid, 
startsWith("file:/"));
+        assertThat("SystemIDs should not start with file:////", systemid, 
not(startsWith("file:////")));
     }
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/761f8e60/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java 
b/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java
index fcffdce..2717746 100644
--- a/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java
@@ -22,8 +22,11 @@ import java.io.File;
 import org.apache.tools.ant.taskdefs.condition.Os;
 import org.junit.Test;
 
+import static org.hamcrest.Matchers.endsWith;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.startsWith;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assume.assumeFalse;
 import static org.junit.Assume.assumeTrue;
@@ -52,26 +55,26 @@ public class JavaEnvUtilsTest {
             .getAbsolutePath();
 
         String j = JavaEnvUtils.getJreExecutable("java");
-        assertTrue(j.endsWith(".exe"));
+        assertThat(j, endsWith(".exe"));
         assertTrue(j + " is absolute", (new File(j)).isAbsolute());
         try {
-            assertTrue(j + " is normalized and in the JRE dir", 
j.startsWith(javaHome));
+            assertThat(j + " is normalized and in the JRE dir", j, 
startsWith(javaHome));
         } catch (AssertionError e) {
             // java.home is bogus
             assertEquals("java.exe", j);
         }
 
         j = JavaEnvUtils.getJdkExecutable("javac");
-        assertTrue(j.endsWith(".exe"));
+        assertThat(j, endsWith(".exe"));
 
         try {
             assertTrue(j + " is absolute", (new File(j)).isAbsolute());
             String javaHomeParent = FILE_UTILS.normalize(javaHome + 
"/..").getAbsolutePath();
-            assertTrue(j + " is normalized and in the JDK dir", 
j.startsWith(javaHomeParent));
+            assertThat(j + " is normalized and in the JDK dir", j, 
startsWith(javaHomeParent));
             if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)) {
-                assertTrue(j + " is normalized and not in the JRE dir", 
j.startsWith(javaHome));
+                assertThat(j + " is normalized and not in the JRE dir", j, 
startsWith(javaHome));
             } else {
-                assertFalse(j + " is normalized and not in the JRE dir", 
j.startsWith(javaHome));
+                assertThat(j + " is normalized and not in the JRE dir", j, 
not(startsWith(javaHome)));
             }
         } catch (AssertionError e) {
             // java.home is bogus
@@ -92,25 +95,25 @@ public class JavaEnvUtilsTest {
         String extension = Os.isFamily("dos") ? ".exe" : "";
 
         String j = JavaEnvUtils.getJreExecutable("java");
-        if (!extension.equals("")) {
-            assertTrue(j.endsWith(extension));
+        if (extension.isEmpty()) {
+            assertThat(j, endsWith(extension));
         }
         assertTrue(j + " is absolute", (new File(j)).isAbsolute());
-        assertTrue(j + " is normalized and in the JRE dir", 
j.startsWith(javaHome));
+        assertThat(j + " is normalized and in the JRE dir", j, 
startsWith(javaHome));
 
         j = JavaEnvUtils.getJdkExecutable("javac");
-        if (!extension.equals("")) {
-            assertTrue(j.endsWith(extension));
+        if (extension.isEmpty()) {
+            assertThat(j, endsWith(extension));
         }
         assertTrue(j + " is absolute", (new File(j)).isAbsolute());
 
         String javaHomeParent = FILE_UTILS.normalize(javaHome + 
"/..").getAbsolutePath();
-        assertTrue(j + " is normalized and in the JDK dir", 
j.startsWith(javaHomeParent));
+        assertThat(j + " is normalized and in the JDK dir", j, 
startsWith(javaHomeParent));
 
         if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)) {
-            assertTrue(j + " is normalized and in the JRE dir", 
j.startsWith(javaHome));
+            assertThat(j + " is normalized and in the JRE dir", j, 
startsWith(javaHome));
         } else {
-            assertFalse(j + " is normalized and not in the JRE dir", 
j.startsWith(javaHome));
+            assertThat(j + " is normalized and not in the JRE dir", j, 
not(startsWith(javaHome)));
         }
 
         assertEquals("foo" + extension, JavaEnvUtils.getJreExecutable("foo"));

http://git-wip-us.apache.org/repos/asf/ant/blob/761f8e60/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java
----------------------------------------------------------------------
diff --git 
a/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java 
b/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java
index 3aa8559..30c8791 100644
--- 
a/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java
+++ 
b/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java
@@ -28,9 +28,9 @@ import org.junit.Test;
 
 import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.startsWith;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
 
 public class LayoutPreservingPropertiesTest {
 
@@ -150,9 +150,7 @@ public class LayoutPreservingPropertiesTest {
         fos.close();
 
         // and check that the resulting file looks okay
-        String s = readFile(tmp);
-
-        assertTrue("should have had header ", s.startsWith("#file-header"));
+        assertThat("should have had header ", readFile(tmp), 
startsWith("#file-header"));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/ant/blob/761f8e60/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java 
b/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java
index d3f64d8..7b49d6b 100644
--- a/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java
@@ -17,17 +17,19 @@
  */
 package org.apache.tools.ant.util;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Vector;
 
 import org.junit.Test;
 
+import static org.hamcrest.Matchers.endsWith;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
 /**
  * Test for StringUtils
  */
@@ -103,7 +105,7 @@ public class StringUtilsTest {
     public void testEndsWithJDKPerf() {
         StringBuffer buf = getFilledBuffer(1024 * 300, 'a');
         for (int i = 0; i < 1000; i++) {
-            assertTrue(buf.toString().endsWith("aa"));
+            assertThat(buf.toString(), endsWith("aa"));
         }
     }
 

Reply via email to