From 0ef77af2bb4f71ab35c427a029590009af482953 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 19 Aug 2016 11:52:25 +0100 Subject: [PATCH] JAL-2154 testNG like assertAlignmentDatasetRefs static wrappers and allow a message to be passed to prefix any assert failed messages --- test/jalview/datamodel/AlignmentTest.java | 58 +++++++++++++++++++++-------- test/jalview/io/CrossRef2xmlTests.java | 24 +++++++----- 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/test/jalview/datamodel/AlignmentTest.java b/test/jalview/datamodel/AlignmentTest.java index 9434569..003f2aa 100644 --- a/test/jalview/datamodel/AlignmentTest.java +++ b/test/jalview/datamodel/AlignmentTest.java @@ -104,6 +104,29 @@ public class AlignmentTest } /** + * assert wrapper: tests all references in the given alignment are consistent + * + * @param alignment + */ + public static void assertAlignmentDatasetRefs(AlignmentI alignment) + { + verifyAlignmentDatasetRefs(alignment, true, null); + } + + /** + * assert wrapper: tests all references in the given alignment are consistent + * + * @param alignment + * @param message + * - prefixed to any assert failed messages + */ + public static void assertAlignmentDatasetRefs(AlignmentI alignment, + String message) + { + verifyAlignmentDatasetRefs(alignment, true, message); + } + + /** * verify sequence and dataset references are properly contained within * dataset * @@ -111,16 +134,19 @@ public class AlignmentTest * - the alignmentI object to verify (either alignment or dataset) * @param raiseAssert * - when set, testng assertions are raised. + * @param message + * - null or a string message to prepend to the assert failed messages. * @return true if alignment references were in order, otherwise false. */ public static boolean verifyAlignmentDatasetRefs(AlignmentI alignment, - boolean raiseAssert) + boolean raiseAssert, String message) { + if (message==null) { message = ""; } if (alignment == null) { if (raiseAssert) { - Assert.fail("Alignment for verification was null."); + Assert.fail(message+"Alignment for verification was null."); } return false; } @@ -135,7 +161,7 @@ public class AlignmentTest { if (raiseAssert) { - Assert.fail("Alignment contained a sequence who's dataset sequence has a second dataset reference."); + Assert.fail(message+" Alignment contained a sequence who's dataset sequence has a second dataset reference."); } return false; } @@ -143,12 +169,12 @@ public class AlignmentTest { if (raiseAssert) { - Assert.fail("Alignment contained a sequence who's dataset sequence was not in the dataset."); + Assert.fail(message+" Alignment contained a sequence who's dataset sequence was not in the dataset."); } return false; } } - return verifyAlignmentDatasetRefs(alignment.getDataset(), raiseAssert); + return verifyAlignmentDatasetRefs(alignment.getDataset(), raiseAssert, message); } else { @@ -159,7 +185,7 @@ public class AlignmentTest { if (raiseAssert) { - Assert.fail("Dataset contained a sequence with non-null dataset reference (ie not a dataset sequence!)"); + Assert.fail(message+" Dataset contained a sequence with non-null dataset reference (ie not a dataset sequence!)"); } return false; } @@ -176,7 +202,7 @@ public class AlignmentTest { if (raiseAssert) { - Assert.fail("DBRefEntry for sequence in alignment had map to sequence which was not a dataset sequence"); + Assert.fail(message+" DBRefEntry for sequence in alignment had map to sequence which was not a dataset sequence"); } return false; @@ -185,7 +211,7 @@ public class AlignmentTest { if (raiseAssert) { - Assert.fail("DBRefEntry for sequence in alignment had map to sequence not in dataset"); + Assert.fail(message+" DBRefEntry for sequence in alignment had map to sequence not in dataset"); } return false; } @@ -205,7 +231,7 @@ public class AlignmentTest { if (raiseAssert) { - Assert.fail("CodonFrame-SSM-FromSeq is not a dataset sequence"); + Assert.fail(message+" CodonFrame-SSM-FromSeq is not a dataset sequence"); } return false; } @@ -214,7 +240,7 @@ public class AlignmentTest if (raiseAssert) { - Assert.fail("CodonFrame-SSM-FromSeq is not contained in dataset"); + Assert.fail(message+" CodonFrame-SSM-FromSeq is not contained in dataset"); } return false; } @@ -222,7 +248,7 @@ public class AlignmentTest { if (raiseAssert) { - Assert.fail("CodonFrame-SSM-Mapping-ToSeq is not a dataset sequence"); + Assert.fail(message+" CodonFrame-SSM-Mapping-ToSeq is not a dataset sequence"); } return false; } @@ -231,7 +257,7 @@ public class AlignmentTest if (raiseAssert) { - Assert.fail("CodonFrame-SSM-Mapping-ToSeq is not contained in dataset"); + Assert.fail(message+" CodonFrame-SSM-Mapping-ToSeq is not contained in dataset"); } return false; } @@ -258,7 +284,7 @@ public class AlignmentTest try { - Assert.assertTrue(verifyAlignmentDatasetRefs(al, true), + Assert.assertTrue(verifyAlignmentDatasetRefs(al, true, null), "Valid test alignment failed when raiseAsserts enabled:" + msg); } catch (AssertionError ae) @@ -269,7 +295,7 @@ public class AlignmentTest + msg, ae); } // also check validation passes with asserts disabled - Assert.assertTrue(verifyAlignmentDatasetRefs(al, false), + Assert.assertTrue(verifyAlignmentDatasetRefs(al, false, null), "Valid test alignment failed when raiseAsserts disabled:" + msg); } @@ -277,7 +303,7 @@ public class AlignmentTest { try { - Assert.assertFalse(verifyAlignmentDatasetRefs(al, true)); + Assert.assertFalse(verifyAlignmentDatasetRefs(al, true, null)); Assert.fail("Invalid test alignment passed but no assertion raised when raiseAsserts enabled:" + msg); } catch (AssertionError ae) @@ -285,7 +311,7 @@ public class AlignmentTest // expected behaviour } // also check validation passes with asserts disabled - Assert.assertFalse(verifyAlignmentDatasetRefs(al, false), + Assert.assertFalse(verifyAlignmentDatasetRefs(al, false, null), "Invalid test alignment passed when raiseAsserts disabled:" + msg); } diff --git a/test/jalview/io/CrossRef2xmlTests.java b/test/jalview/io/CrossRef2xmlTests.java index 154abc0..d1821f1 100644 --- a/test/jalview/io/CrossRef2xmlTests.java +++ b/test/jalview/io/CrossRef2xmlTests.java @@ -99,8 +99,9 @@ public class CrossRef2xmlTests extends Jalview2xmlBase assertTrue("Didn't retrieve " + first, af != null); // verify references for retrieved data - AlignmentTest.verifyAlignmentDatasetRefs(af.getViewport() - .getAlignment(), true); + AlignmentTest.assertAlignmentDatasetRefs(af.getViewport() + .getAlignment(), "Pass (" + pass1 + "," + pass2 + "," + + pass3 + "): Fetch " + first + ":"); // store project to recover on next pass stringify(dbtoviewBit, savedProjects, first, af.alignPanel); @@ -113,8 +114,9 @@ public class CrossRef2xmlTests extends Jalview2xmlBase .get(first).toString(), FormatAdapter.FILE); // verify references for recovered data - AlignmentTest.verifyAlignmentDatasetRefs(af.getViewport() - .getAlignment(), true); + AlignmentTest.assertAlignmentDatasetRefs(af.getViewport() + .getAlignment(), "Pass (" + pass1 + "," + pass2 + "," + + pass3 + "): Recover " + first + ":"); } @@ -186,12 +188,14 @@ public class CrossRef2xmlTests extends Jalview2xmlBase } for (AlignmentViewPanel avp : cra_views) { + nextxref = first + " -> " + db + "{" + p++ + "}"; + // verify references for this panel - AlignmentTest.verifyAlignmentDatasetRefs(avp.getAlignment(), - true); + AlignmentTest.assertAlignmentDatasetRefs(avp.getAlignment(), + "" + "Pass (" + pass1 + "," + pass2 + "): For " + + nextxref + ":"); SequenceI[] xrseqs = avp.getAlignment().getSequencesArray(); - nextxref = first + " -> " + db + "{" + p++ + "}"; viewsourcedb.put(avp, nextxref); stringify(dbtoviewBit, savedProjects, nextxref, avp); @@ -263,8 +267,10 @@ public class CrossRef2xmlTests extends Jalview2xmlBase + xrefdb + "{" + q++ + "}"; // verify references for this panel - AlignmentTest.verifyAlignmentDatasetRefs( - nextavp.getAlignment(), true); + AlignmentTest.assertAlignmentDatasetRefs( + nextavp.getAlignment(), "" + "Pass (" + pass1 + + "," + pass2 + "): For " + + nextnextxref + ":"); viewsourcedb.put(nextavp, nextnextxref); stringify(dbtoviewBit, savedProjects, nextnextxref, -- 1.7.10.2