Add canaries in order to avoid false positives

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

Branch: refs/heads/master
Commit: fc4fc40d7fe3b7c33010b4b64cf235710506ddd2
Parents: 6bde21e
Author: Gintas Grigelionis <gin...@apache.org>
Authored: Tue Apr 24 06:37:12 2018 +0200
Committer: Gintas Grigelionis <gin...@apache.org>
Committed: Tue Apr 24 07:08:44 2018 +0200

----------------------------------------------------------------------
 .../org/apache/tools/ant/AntClassLoaderTest.java   |  7 +++++++
 .../org/apache/tools/ant/taskdefs/SQLExecTest.java | 17 ++++++++++++-----
 2 files changed, 19 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/fc4fc40d/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java 
b/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java
index bd9144a..9adde4a 100644
--- a/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java
+++ b/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java
@@ -101,21 +101,28 @@ public class AntClassLoaderTest {
         thrown.expect(ClassNotFoundException.class);
         Path path = new Path(buildRule.getProject(), ".");
         loader = buildRule.getProject().createClassLoader(path);
+        boolean canary = false;
         try {
             // we don't expect to find this
             loader.findClass("fubar");
+            canary = true;
         } finally {
+            assertFalse("Nonexistent class found", canary);
             loader.cleanup();
             try {
                 // we don't expect to find this
                 loader.findClass("fubar");
+                canary = true;
             } finally {
+                assertFalse("Nonexistent class found", canary);
                 // tell the build it is finished
                 buildRule.getProject().fireBuildFinished(null);
                 try {
                     // we don't expect to find this
                     loader.findClass("fubar");
+                    canary = true;
                 } finally {
+                    assertFalse("Nonexistent class found", canary);
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/ant/blob/fc4fc40d/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java 
b/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java
index b0dc876..5067c65 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java
@@ -34,10 +34,12 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
+import static org.hamcrest.Matchers.hasKey;
+import static org.hamcrest.Matchers.not;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThat;
 
 /**
  * Simple testcase to test for driver caching.
@@ -77,23 +79,28 @@ public class SQLExecTest {
     public void testDriverCaching() {
         thrown.expect(BuildException.class);
         thrown.expectMessage("No suitable Driver");
+        boolean canary = false;
         SQLExec sql = createTask(getProperties(NULL));
-        assertFalse(SQLExec.getLoaderMap().containsKey(NULL_DRIVER));
+        assertThat(SQLExec.getLoaderMap(), not(hasKey(NULL_DRIVER)));
         try {
             sql.execute();
+            canary = true;
         } finally {
-            assertTrue(SQLExec.getLoaderMap().containsKey(NULL_DRIVER));
+            assertFalse("Found some Driver", canary);
+            assertThat(SQLExec.getLoaderMap(), hasKey(NULL_DRIVER));
             assertSame(sql.getLoader(), 
JDBCTask.getLoaderMap().get(NULL_DRIVER));
             ClassLoader loader1 = sql.getLoader();
 
             // 2nd run..
             sql = createTask(getProperties(NULL));
             // the driver must still be cached.
-            assertTrue(JDBCTask.getLoaderMap().containsKey(NULL_DRIVER));
+            assertThat(JDBCTask.getLoaderMap(), hasKey(NULL_DRIVER));
             try {
                 sql.execute();
+                canary = true;
             } finally {
-                assertTrue(JDBCTask.getLoaderMap().containsKey(NULL_DRIVER));
+                assertFalse("Found some Driver", canary);
+                assertThat(JDBCTask.getLoaderMap(), hasKey(NULL_DRIVER));
                 assertSame(sql.getLoader(), 
JDBCTask.getLoaderMap().get(NULL_DRIVER));
                 assertSame(loader1, sql.getLoader());
             }

Reply via email to