From 6bfc71d83bb93a9fb59340beb65fd2f8b3ec407f Mon Sep 17 00:00:00 2001
From: izabel <izabel>
Date: Thu, 24 Apr 2008 16:00:18 +0000
Subject: [PATCH] test fixes

SVN: 5795
---
 .../collections/CollectionUtilsTest.java      | 26 ++++++++++------
 .../collections/CompositeValidatorTest.java   | 13 +++++---
 .../common/collections/FilteredListTest.java  | 15 ++++++---
 .../collections/ValidatorUtilsTest.java       |  7 +++--
 .../common/converter/ConverterPoolTest.java   | 31 +++++++++++++------
 .../cisd/common/db/SqlUnitTestRunnerTest.java | 12 ++++---
 .../common/parser/ParserUtilitiesTest.java    | 15 ++++++---
 .../common/process/ProcessRunnerTest.java     | 11 +++----
 .../common/utilities/FileUtilitiesTest.java   | 29 +++++++++++------
 .../common/utilities/StringUtilitiesTest.java | 13 ++++----
 10 files changed, 110 insertions(+), 62 deletions(-)

diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/collections/CollectionUtilsTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/collections/CollectionUtilsTest.java
index cc149476136..e17fc31255a 100644
--- a/common/sourceTest/java/ch/systemsx/cisd/common/collections/CollectionUtilsTest.java
+++ b/common/sourceTest/java/ch/systemsx/cisd/common/collections/CollectionUtilsTest.java
@@ -17,7 +17,7 @@
 package ch.systemsx.cisd.common.collections;
 
 import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.fail;
+import static org.testng.AssertJUnit.assertTrue;
 
 import java.util.Collection;
 
@@ -74,38 +74,46 @@ public final class CollectionUtilsTest
     public final void testAbbreviateWithError()
     {
         final Object[] objects = new Object[0];
+
+        boolean exceptionThrown = false;
         try
         {
             CollectionUtils.abbreviate((Collection<?>) null, 0, false);
-            fail("Given list can not be null.");
         } catch (AssertionError e)
         {
-            // Nothing to do here
+            exceptionThrown = true;
         }
+        assertTrue("Given list can not be null.", exceptionThrown);
+
+        exceptionThrown = false;
         try
         {
             CollectionUtils.abbreviate(objects, 0, false, ToStringDefaultConverter.getInstance(),
                     null);
-            fail("Given CollectionStyle can not be null.");
         } catch (AssertionError e)
         {
-            // Nothing to do here
+            exceptionThrown = true;
         }
+        assertTrue("Given CollectionStyle can not be null.", exceptionThrown);
+
+        exceptionThrown = false;
         try
         {
             CollectionUtils.abbreviate(objects, 0, null);
-            fail("Given CollectionStyle can not be null.");
         } catch (AssertionError e)
         {
-            // Nothing to do here
+            exceptionThrown = true;
         }
+        assertTrue("Given CollectionStyle can not be null.", exceptionThrown);
+
+        exceptionThrown = false;
         try
         {
             CollectionUtils.abbreviate((Collection<?>) null, 0, false, null);
-            fail("IToStringConverter can not be null.");
         } catch (AssertionError e)
         {
-            // Nothing to do here
+            exceptionThrown = true;
         }
+        assertTrue("IToStringConverter can not be null.", exceptionThrown);
     }
 }
diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/collections/CompositeValidatorTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/collections/CompositeValidatorTest.java
index 096b8e865f1..9f0e9e40452 100644
--- a/common/sourceTest/java/ch/systemsx/cisd/common/collections/CompositeValidatorTest.java
+++ b/common/sourceTest/java/ch/systemsx/cisd/common/collections/CompositeValidatorTest.java
@@ -17,7 +17,7 @@
 package ch.systemsx.cisd.common.collections;
 
 import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.fail;
+import static org.testng.AssertJUnit.assertTrue;
 
 import org.testng.annotations.Test;
 
@@ -32,23 +32,26 @@ public final class CompositeValidatorTest
     @Test
     public final void testNonNullConvention()
     {
+        boolean exceptionThrown = false;
         final CompositeValidator<Object> validator = new CompositeValidator<Object>();
         try
         {
             validator.addValidator(null);
-            fail("Null validator not allowed.");
         } catch (final AssertionError e)
         {
-            // Nothing to do here.
+            exceptionThrown = true;
         }
+        assertTrue("Null validator not allowed.", exceptionThrown);
+
+        exceptionThrown = false;
         try
         {
             validator.removeValidator(null);
-            fail("Null validator not allowed.");
         } catch (final AssertionError e)
         {
-            // Nothing to do here.
+            exceptionThrown = true;
         }
+        assertTrue("Null validator not allowed.", exceptionThrown);
     }
 
     @Test
diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/collections/FilteredListTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/collections/FilteredListTest.java
index 0e4b1f72fc2..1b36eee63eb 100644
--- a/common/sourceTest/java/ch/systemsx/cisd/common/collections/FilteredListTest.java
+++ b/common/sourceTest/java/ch/systemsx/cisd/common/collections/FilteredListTest.java
@@ -16,11 +16,14 @@
 
 package ch.systemsx.cisd.common.collections;
 
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.AssertJUnit.fail;
+
 import java.util.ArrayList;
 import java.util.List;
 
 import org.testng.annotations.Test;
-import static org.testng.AssertJUnit.*;
 
 /**
  * Tests for {@link FilteredList}.
@@ -33,22 +36,24 @@ public final class FilteredListTest
     @Test
     public final void testDecorate()
     {
+        boolean exceptionThrown = false;
         try
         {
             FilteredList.decorate(new ArrayList<String>(), null);
-            fail("Neither list nor validator can be null");
         } catch (AssertionError e)
         {
-            // Nothing to do here.
+            exceptionThrown = true;
         }
+        assertTrue("Neither list nor validator can be null", exceptionThrown);
+        exceptionThrown = false;
         try
         {
             FilteredList.decorate(null, ValidatorUtils.getNotNullValidator());
-            fail("Neither list nor validator can be null");
         } catch (AssertionError e)
         {
-            // Nothing to do here.
+            exceptionThrown = true;
         }
+        assertTrue("Neither list nor validator can be null", exceptionThrown);
     }
 
     private final static List<String> createList()
diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/collections/ValidatorUtilsTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/collections/ValidatorUtilsTest.java
index d1fbb17e6a3..d66ec7b54cb 100644
--- a/common/sourceTest/java/ch/systemsx/cisd/common/collections/ValidatorUtilsTest.java
+++ b/common/sourceTest/java/ch/systemsx/cisd/common/collections/ValidatorUtilsTest.java
@@ -18,7 +18,7 @@ package ch.systemsx.cisd.common.collections;
 
 import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.fail;
+import static org.testng.AssertJUnit.assertTrue;
 
 import java.util.regex.Pattern;
 
@@ -36,14 +36,15 @@ public final class ValidatorUtilsTest
     public final void testConvertToRegEx()
     {
         String s = null;
+        boolean exceptionThrown = false;
         try
         {
             ValidatorUtils.convertToRegEx(s);
-            fail("Pattern can not be null.");
         } catch (AssertionError e)
         {
-            // Nothing to do here.
+            exceptionThrown = true;
         }
+        assertTrue("Pattern can not be null.", exceptionThrown);
 
         s = "hello";
         String regEx = ValidatorUtils.convertToRegEx(s);
diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/converter/ConverterPoolTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/converter/ConverterPoolTest.java
index 6896786a5c6..7df915e29cf 100644
--- a/common/sourceTest/java/ch/systemsx/cisd/common/converter/ConverterPoolTest.java
+++ b/common/sourceTest/java/ch/systemsx/cisd/common/converter/ConverterPoolTest.java
@@ -16,10 +16,15 @@
 
 package ch.systemsx.cisd.common.converter;
 
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertNull;
+import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.AssertJUnit.fail;
+
 import java.util.Date;
 
 import org.testng.annotations.Test;
-import static org.testng.AssertJUnit.*;
 
 /**
  * Test cases for the {@link ConverterPool}.
@@ -34,22 +39,26 @@ public final class ConverterPoolTest
     @Test
     public final void testRegisterConverter()
     {
+        boolean exceptionThrown = false;
         try
         {
             ConverterPool.getInstance().registerConverter(null, null);
-            fail("Null type is not allowed.");
         } catch (AssertionError ex)
         {
-            // Nothing to do here.
+            exceptionThrown = true;
         }
+        assertTrue("Null type is not allowed.", exceptionThrown);
+
+        exceptionThrown = false;
         try
         {
             ConverterPool.getInstance().registerConverter(String.class, null);
-            fail("Null converter is not allowed.");
         } catch (AssertionError ex)
         {
-            // Nothing to do here.
+            exceptionThrown = true;
         }
+        assertTrue("Null converter is not allowed.", exceptionThrown);
+
         assertNull(ConverterPool.getInstance().getConverter(String.class));
         assertNull(ConverterPool.getInstance().getConverter(Date.class));
         ConverterPool.getInstance().registerConverter(Date.class, new DateConverter("dd.MM.yyyy"));
@@ -61,14 +70,16 @@ public final class ConverterPoolTest
     public final void testUnRegisterConverter()
     {
         assertNotNull(ConverterPool.getInstance().getConverter(Date.class));
+        boolean exceptionThrown = false;
         try
         {
             ConverterPool.getInstance().unregisterConverter(null);
-            fail("Null type is not allowed.");
+
         } catch (AssertionError ex)
         {
-            // Nothing to do here.
+            exceptionThrown = true;
         }
+        assertTrue("Null type is not allowed.", exceptionThrown);
         ConverterPool.getInstance().unregisterConverter(Date.class);
         assertNull(ConverterPool.getInstance().getConverter(Date.class));
     }
@@ -76,14 +87,16 @@ public final class ConverterPoolTest
     @Test
     public final void testConvert()
     {
+        boolean exceptionThrown = false;
         try
         {
             ConverterPool.getInstance().convert(null, null);
-            fail("Null type is not allowed.");
+
         } catch (AssertionError ex)
         {
-            // Nothing to do here.
+            exceptionThrown = true;
         }
+        assertTrue("Null type is not allowed.", exceptionThrown);
         ConverterPool pool = ConverterPool.getInstance();
         // String
         assertNull(pool.convert(null, String.class));
diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/db/SqlUnitTestRunnerTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/db/SqlUnitTestRunnerTest.java
index ea68f6e4904..606c59a705e 100644
--- a/common/sourceTest/java/ch/systemsx/cisd/common/db/SqlUnitTestRunnerTest.java
+++ b/common/sourceTest/java/ch/systemsx/cisd/common/db/SqlUnitTestRunnerTest.java
@@ -17,7 +17,7 @@
 package ch.systemsx.cisd.common.db;
 
 import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.fail;
+import static org.testng.AssertJUnit.assertTrue;
 
 import java.io.File;
 import java.io.IOException;
@@ -164,16 +164,18 @@ public class SqlUnitTestRunnerTest
         createScriptPrepareExecutor(new File(testCaseFolder, "buildup.sql"), "-- build up\n",
                 runtimeException);
 
+        boolean exceptionThrown = false;
         try
         {
             testRunner.run(TEST_SCRIPTS_FOLDER);
-            fail("AssertionError expected");
         } catch (AssertionError e)
         {
+            exceptionThrown = true;
             final String message = StringUtils.split(e.getMessage(), "\n")[0];
             assertEquals("Script 'buildup.sql' of test case 'my test case' failed because of "
                     + runtimeException, message.trim());
         }
+        assertTrue("AssertionError expected", exceptionThrown);
         assertEquals("====== Test case: my test case ======" + OSUtilities.LINE_SEPARATOR
                 + "     execute script buildup.sql" + OSUtilities.LINE_SEPARATOR
                 + "       script failed: skip test scripts and teardown script."
@@ -193,18 +195,20 @@ public class SqlUnitTestRunnerTest
         FileUtils.writeStringToFile(new File(testCaseFolder, "abc=abc.sql"), "Select abc\n");
         createScriptPrepareExecutor(new File(testCaseFolder, "10=c.sql"), "Select 10\n", null);
         createScriptPrepareExecutor(new File(testCaseFolder, "1=a.sql"), "Select 1\n", null);
-
+        boolean exceptionThrown = false;
         try
         {
             testRunner.run(TEST_SCRIPTS_FOLDER);
-            fail("AssertionError expected");
+
         } catch (AssertionError e)
         {
+            exceptionThrown = true;
             // Strip away stack trace
             final String message = StringUtils.split(e.getMessage(), "\n")[0];
             assertEquals("Script '9=b.sql' of test case 'my test case' failed because of "
                     + runtimeException, message.trim());
         }
+        assertTrue("AssertionError expected", exceptionThrown);
         assertEquals("====== Test case: my test case ======" + OSUtilities.LINE_SEPARATOR
                 + "     execute script 1=a.sql" + OSUtilities.LINE_SEPARATOR
                 + "     execute script 9=b.sql" + OSUtilities.LINE_SEPARATOR
diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/parser/ParserUtilitiesTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/parser/ParserUtilitiesTest.java
index 845faba0f00..53c529a73ae 100644
--- a/common/sourceTest/java/ch/systemsx/cisd/common/parser/ParserUtilitiesTest.java
+++ b/common/sourceTest/java/ch/systemsx/cisd/common/parser/ParserUtilitiesTest.java
@@ -17,7 +17,7 @@
 package ch.systemsx.cisd.common.parser;
 
 import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.fail;
+import static org.testng.AssertJUnit.assertTrue;
 
 import java.io.File;
 import java.io.IOException;
@@ -65,23 +65,28 @@ public final class ParserUtilitiesTest
     public final void testGetFirstAcceptedLineWithProblematicValues()
     {
         File file = new File(workingDirectory, "doesNotExist");
+        boolean exceptionThrown = false;
         try
         {
             ParserUtilities.getFirstAcceptedLine(null, null);
-            fail("Given file can not be null.");
+
         } catch (AssertionError e)
         {
-            // Nothing to do here.
+            exceptionThrown = true;
         }
+        assertTrue("Given file can not be null.", exceptionThrown);
+
+        exceptionThrown = false;
         assert file.exists() == false;
         try
         {
             ParserUtilities.getFirstAcceptedLine(file, null);
-            fail("Given file must exist.");
+
         } catch (AssertionError e)
         {
-            // Nothing to do here.
+            exceptionThrown = true;
         }
+        assertTrue("Given file must exist.", exceptionThrown);
     }
 
     @Test
diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/process/ProcessRunnerTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/process/ProcessRunnerTest.java
index 8c040babafe..b3449410a1b 100644
--- a/common/sourceTest/java/ch/systemsx/cisd/common/process/ProcessRunnerTest.java
+++ b/common/sourceTest/java/ch/systemsx/cisd/common/process/ProcessRunnerTest.java
@@ -16,7 +16,7 @@
 
 package ch.systemsx.cisd.common.process;
 
-import static org.testng.AssertJUnit.fail;
+import static org.testng.AssertJUnit.assertTrue;
 
 import org.jmock.Expectations;
 import org.jmock.Mockery;
@@ -24,9 +24,6 @@ import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import ch.systemsx.cisd.common.process.IProcess;
-import ch.systemsx.cisd.common.process.ProcessRunner;
-
 /**
  * Test cases for the {@link ProcessRunner}.
  * 
@@ -112,14 +109,16 @@ public class ProcessRunnerTest
                     will(returnValue(-1));
                 }
             });
+        boolean exceptionThrown = false;
         try
         {
             new ProcessRunner(process);
-            fail("Negative value for millis to sleep on failure not allowed");
+
         } catch (AssertionError ex)
         {
-            // Nothing to do here
+            exceptionThrown = true;
         }
+        assertTrue("Negative value for millis to sleep on failure not allowed", exceptionThrown);
         context.checking(new Expectations()
             {
                 {
diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/FileUtilitiesTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/FileUtilitiesTest.java
index eaf087458ac..5334caee52d 100644
--- a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/FileUtilitiesTest.java
+++ b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/FileUtilitiesTest.java
@@ -252,14 +252,16 @@ public final class FileUtilitiesTest extends AbstractFileSystemTestCase
     public final void testRemovePrefixFromFileName()
     {
         File file = new File("/tmp/dir/x.txt");
+        boolean exceptionThrown = false;
         try
         {
             FileUtilities.removePrefixFromFileName(null, Constants.IS_FINISHED_PREFIX);
-            fail("Given file can not be null.");
+
         } catch (AssertionError e)
         {
-            // Nothing to do here
+            exceptionThrown = true;
         }
+        assertTrue("Given file can not be null.", exceptionThrown);
         assertEquals(file, FileUtilities.removePrefixFromFileName(file, null));
         assertEquals(file, FileUtilities.removePrefixFromFileName(file,
                 Constants.IS_FINISHED_PREFIX));
@@ -291,24 +293,28 @@ public final class FileUtilitiesTest extends AbstractFileSystemTestCase
         assert file.exists();
         newFile = FileUtilities.createNextNumberedFile(file, pattern, null);
         assertEquals(new File(workingDirectory, "abc1"), newFile);
+        boolean exceptionThrown = false;
         try
         {
             FileUtilities.createNextNumberedFile(null, pattern, null);
-            fail("Null value for file not allowed.");
+
         } catch (AssertionError e)
         {
-            // Nothing to do here
+            exceptionThrown = true;
         }
+        assertTrue("Null value for file not allowed.", exceptionThrown);
         String defaultFileName = "abc_[1]";
+        exceptionThrown = false;
         try
         {
             FileUtilities.createNextNumberedFile(file, Pattern.compile("dummyPattern"),
                     defaultFileName);
-            fail("Must contain either '(\\d+)' or ([0-9]+).");
+
         } catch (AssertionError e)
         {
-            // Nothing to do here
+            exceptionThrown = true;
         }
+        assertTrue("Must contain either '(\\d+)' or ([0-9]+).", exceptionThrown);
         // File already exists but default one does not
         assertEquals(file.getName(), "abc");
         assert file.exists();
@@ -342,14 +348,16 @@ public final class FileUtilitiesTest extends AbstractFileSystemTestCase
     @Test
     public final void testGetRelativeFile()
     {
+        boolean exceptionThrown = false;
         try
         {
             FileUtilities.getRelativeFile(null, null);
-            fail("Given root and file can not be null.");
+
         } catch (AssertionError e)
         {
-            // Nothing to do here
+            exceptionThrown = true;
         }
+        assertTrue("Given root and file can not be null.", exceptionThrown);
         File file = new File(workingDirectory, "hello");
         assertEquals(workingDirectory.getAbsolutePath() + File.separator + "hello", file
                 .getAbsolutePath());
@@ -477,14 +485,15 @@ public final class FileUtilitiesTest extends AbstractFileSystemTestCase
     @Test
     public final void testNormalizeFile() throws IOException
     {
+        boolean exceptionThrown = false;
         try
         {
             FileUtilities.normalizeFile(null);
-            fail("Given file can not be null.");
         } catch (AssertionError ex)
         {
-            // Nothing to do here.
+            exceptionThrown = true;
         }
+        assertTrue("Given file can not be null.", exceptionThrown);
         final File file = new File(workingDirectory, "../dir");
         final String canonicalPath = file.getCanonicalPath();
         assertFalse(canonicalPath.equals(file.getAbsolutePath()));
diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/StringUtilitiesTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/StringUtilitiesTest.java
index 6d0788df83d..79fd7964595 100644
--- a/common/sourceTest/java/ch/systemsx/cisd/common/utilities/StringUtilitiesTest.java
+++ b/common/sourceTest/java/ch/systemsx/cisd/common/utilities/StringUtilitiesTest.java
@@ -16,15 +16,14 @@
 
 package ch.systemsx.cisd.common.utilities;
 
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
+
 import java.util.Arrays;
 import java.util.List;
 
 import org.testng.annotations.Test;
 
-import ch.systemsx.cisd.common.utilities.StringUtilities;
-
-import static org.testng.AssertJUnit.*;
-
 /**
  * Test cases for the {@link StringUtilities}.
  * 
@@ -69,14 +68,16 @@ public class StringUtilitiesTest
     @Test
     public final void testGetOrdinal()
     {
+        boolean exceptionThrown = false;
         try
         {
             StringUtilities.getOrdinal(-1);
-            fail("Ordinal of negative number not possible.");
+
         } catch (AssertionError e)
         {
-            // Nothing to do here.
+            exceptionThrown = true;
         }
+        assertTrue("Ordinal of negative number not possible.", exceptionThrown);
         assertEquals("0th", StringUtilities.getOrdinal(0));
         assertEquals("1st", StringUtilities.getOrdinal(1));
         assertEquals("2nd", StringUtilities.getOrdinal(2));
-- 
GitLab