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 cc1494761368e3ce632ba6638b10b0359dc39ef4..e17fc31255a34ed2963ff8b24cb60eeced3668ac 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 096b8e865f1439940018690b90376b41eddb8ef1..9f0e9e40452fc13d87239a15a5282143c2df1708 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 0e4b1f72fc28cd5c34c37ae7dcda3a4145128967..1b36eee63ebbf846cfd2ee40d4b3245ab4cacd99 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 d1fbb17e6a3256acf0b38813243002eb61c70c0b..d66ec7b54cbd0aa8186d25e3ff62afd4bce090b2 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 6896786a5c65403c806a8130c12ca4de1bce9963..7df915e29cfa1aab9a7f863eddbb405dc758366f 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 ea68f6e49043c8fb178c0d1fd0bdb7630bd1169a..606c59a705e1c0eb89f48efaa684584807748de4 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 845faba0f006142e8ae2de4314afad3f84c37c85..53c529a73ae8a02a07f9594eda4293a0109c9402 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 8c040babafe1c44ee15ff6c07d69f4ca5598cecc..b3449410a1be18a4c96b52b594962e85c8ee1d3d 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 eaf087458ac4cbc8970b6052b5ead59f3b7113d3..5334caee52dfe767f19a311a16fc97fbad08baf0 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 6d0788df83da16e12d2543646c6c58486d4f358e..79fd796459548aaf0984ce1d5643adea1d867336 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));