JAL-1782 JAL-1780 JAL-653 JAL-1892 update patched refactored test suite with TestNG
authorJim Procter <jprocter@issues.jalview.org>
Tue, 23 Jun 2015 08:48:13 +0000 (09:48 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Tue, 23 Jun 2015 08:48:13 +0000 (09:48 +0100)
1  2 
test/jalview/analysis/AlignmentUtilsTests.java
test/jalview/datamodel/AlignmentTest.java
test/jalview/io/JSONFileTest.java
test/jalview/io/PhylipFileTests.java
test/jalview/io/RNAMLfileTest.java
test/jalview/io/StockholmFileTest.java
test/jalview/util/MappingUtilsTest.java

   */
  package jalview.analysis;
  
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertFalse;
- import static org.junit.Assert.assertNull;
- import static org.junit.Assert.assertSame;
- import static org.junit.Assert.assertTrue;
++
+ import static org.testng.AssertJUnit.assertEquals;
+ import static org.testng.AssertJUnit.assertFalse;
+ import static org.testng.AssertJUnit.assertNull;
+ import static org.testng.AssertJUnit.assertSame;
+ import static org.testng.AssertJUnit.assertTrue;
  import jalview.datamodel.AlignedCodonFrame;
  import jalview.datamodel.Alignment;
  import jalview.datamodel.AlignmentAnnotation;
@@@ -52,9 -53,9 +54,9 @@@ import java.util.List
  import java.util.Map;
  import java.util.Set;
  
- import org.junit.Test;
+ import org.testng.annotations.Test;
  
- public class AlignmentUtilsTests 
+ public class AlignmentUtilsTests
  {
    // @formatter:off
    private static final String TEST_DATA = 
     */
    protected AlignmentI loadAlignment(final String data, String format) throws IOException
    {
 -    Alignment a = new FormatAdapter().readFile(data,
 +    AlignmentI a = new FormatAdapter().readFile(data,
              AppletFormatAdapter.PASTE, format);
      a.setDataset(null);
      return a;
@@@ -1,8 -1,9 +1,9 @@@
  package jalview.datamodel;
  
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertFalse;
- import static org.junit.Assert.assertTrue;
+ import static org.testng.AssertJUnit.assertEquals;
+ import static org.testng.AssertJUnit.assertFalse;
+ import static org.testng.AssertJUnit.assertTrue;
  import jalview.io.AppletFormatAdapter;
  import jalview.io.FormatAdapter;
  import jalview.util.MapList;
@@@ -10,8 -11,8 +11,8 @@@
  import java.io.IOException;
  import java.util.Iterator;
  
- import org.junit.Before;
- import org.junit.Test;
+ import org.testng.annotations.BeforeMethod;
+ import org.testng.annotations.Test;
  
  /**
   * Unit tests for Alignment datamodel.
@@@ -68,7 -69,7 +69,7 @@@ public class AlignmentTes
    protected AlignmentI loadAlignment(final String data, String format)
            throws IOException
    {
 -    Alignment a = new FormatAdapter().readFile(data,
 +    AlignmentI a = new FormatAdapter().readFile(data,
              AppletFormatAdapter.PASTE, format);
      a.setDataset(null);
      return a;
@@@ -78,7 -79,7 +79,7 @@@
     * Read in Stockholm format test data including secondary structure
     * annotations.
     */
-   @Before
+   @BeforeMethod
    public void setUp() throws IOException
    {
      al = loadAlignment(TEST_DATA, "STH");
@@@ -1,7 -1,9 +1,8 @@@
  package jalview.io;
  
  
- import static org.junit.Assert.assertNotNull;
+ import static org.testng.AssertJUnit.assertNotNull;
 -import jalview.datamodel.Alignment;
  import jalview.datamodel.AlignmentAnnotation;
  import jalview.datamodel.AlignmentI;
  import jalview.datamodel.Annotation;
@@@ -18,10 -20,10 +19,10 @@@ import java.io.IOException
  import java.util.ArrayList;
  import java.util.HashMap;
  
- import org.junit.After;
- import org.junit.Assert;
- import org.junit.Before;
- import org.junit.Test;
+ import org.testng.AssertJUnit;
+ import org.testng.annotations.AfterMethod;
+ import org.testng.annotations.BeforeMethod;
+ import org.testng.annotations.Test;
  
  public class JSONFileTest
  {
@@@ -42,7 -44,7 +43,7 @@@
    HashMap<String, AlignmentAnnotation> testAnnots = new HashMap<String, AlignmentAnnotation>();
    HashMap<String, SequenceGroup> testGrps = new HashMap<String, SequenceGroup>();
  
-   @Before
+   @BeforeMethod
    public void setup() throws Exception
    {
      // create and add sequences
      TEST_ANOT_HEIGHT = testAnnots.size();
    }
  
-   @After
+   @AfterMethod
    public void tearDown() throws Exception
    {
    }
    {
      String jsonFile = "examples/example.json";
      AppletFormatAdapter rf = new AppletFormatAdapter();
 -    Alignment al = null;
 +    AlignmentI al = null;
      try
      {
        al = rf.readFile(jsonFile, AppletFormatAdapter.FILE,
      for (SequenceI seq : al.getSequences())
      {
        SequenceI expectedSeq = testSeqs.get(seq.getName());
-       Assert.assertTrue("Failed Sequence Test  for >>> " + seq.getName(),
+       AssertJUnit.assertTrue("Failed Sequence Test  for >>> " + seq.getName(),
                isSeqMatched(expectedSeq, seq));
        passedCount++;
      }
-     Assert.assertEquals("Some Sequences did not pass the test",
+     AssertJUnit.assertEquals("Some Sequences did not pass the test",
              TEST_SEQ_HEIGHT, passedCount);
  
      passedCount = 0;
      for (SequenceGroup seqGrp : al.getGroups())
      {
        SequenceGroup expectedGrp = testGrps.get(seqGrp.getName());
-       Assert.assertTrue(
+       AssertJUnit.assertTrue(
                "Failed SequenceGroup Test for >>> " + seqGrp.getName(),
                isGroupMatched(expectedGrp, seqGrp));
        passedCount++;
      }
-     Assert.assertEquals("Some SequenceGroups did not pass the test",
+     AssertJUnit.assertEquals("Some SequenceGroups did not pass the test",
              TEST_GRP_HEIGHT, passedCount);
  
      passedCount = 0;
      for (AlignmentAnnotation annot : al.getAlignmentAnnotation())
      {
        AlignmentAnnotation expectedAnnot = testAnnots.get(annot.label);
-       Assert.assertTrue("Failed AlignmentAnnotation Test for >>> "
+       AssertJUnit.assertTrue("Failed AlignmentAnnotation Test for >>> "
                + annot.label, isAnnotationMatched(expectedAnnot, annot));
        passedCount++;
      }
-     Assert.assertEquals("Some Sequences did not pass the test",
+     AssertJUnit.assertEquals("Some Sequences did not pass the test",
              TEST_ANOT_HEIGHT, passedCount);
  
      // af = new AlignFrame(al, 700, 500);
@@@ -1,15 -1,16 +1,16 @@@
  package jalview.io;
  
- import static org.junit.Assert.assertNotNull;
- import static org.junit.Assert.assertTrue;
+ import static org.testng.AssertJUnit.assertNotNull;
+ import static org.testng.AssertJUnit.assertTrue;
 -import jalview.datamodel.Alignment;
 +import jalview.datamodel.AlignmentI;
  import jalview.datamodel.SequenceI;
  
  import java.io.IOException;
  import java.util.HashMap;
  import java.util.Map;
  
- import org.junit.Test;
+ import org.testng.annotations.Test;
  
  /**
   * Test file for {@link PhylipFile}.
@@@ -105,7 -106,7 +106,7 @@@ public class PhylipFileTest
    private void testDataExtraction(String file) throws IOException
    {
      AppletFormatAdapter rf = new AppletFormatAdapter();
 -    Alignment al = rf.readFile(file, AppletFormatAdapter.FILE,
 +    AlignmentI al = rf.readFile(file, AppletFormatAdapter.FILE,
              PhylipFile.FILE_DESC);
      assertNotNull("Couldn't read supplied alignment data.", al);
  
    public void testIO(String file) throws IOException
    {
      AppletFormatAdapter rf = new AppletFormatAdapter();
 -    Alignment al = rf.readFile(file, AppletFormatAdapter.FILE,
 +    AlignmentI al = rf.readFile(file, AppletFormatAdapter.FILE,
              PhylipFile.FILE_DESC);
      assertNotNull("Couldn't read supplied alignment data.", al);
  
      String outputfile = rf.formatSequences(PhylipFile.FILE_DESC, al, true);
  
 -    Alignment al_input = new AppletFormatAdapter().readFile(outputfile,
 +    AlignmentI al_input = new AppletFormatAdapter().readFile(outputfile,
              AppletFormatAdapter.PASTE, PhylipFile.FILE_DESC);
      assertNotNull("Couldn't parse reimported alignment data.", al_input);
  
@@@ -22,9 -22,9 +22,9 @@@ package jalview.io
  
  import java.io.File;
  
- import org.junit.AfterClass;
- import org.junit.BeforeClass;
- import org.junit.Test;
+ import org.testng.annotations.AfterClass;
+ import org.testng.annotations.BeforeClass;
+ import org.testng.annotations.Test;
  
  public class RNAMLfileTest
  {
@@@ -43,7 -43,7 +43,7 @@@
    public void testRnamlToStockholmIO()
    {
      StockholmFileTest.testFileIOwithFormat(new File(
 -            "examples/rna-alignment.xml"), "STH", -1, -1);
 +            "examples/testdata/rna-alignment.xml"), "STH", -1, -1);
  
    }
  
   */
  package jalview.io;
  
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertNotNull;
- import static org.junit.Assert.assertTrue;
+ import static org.testng.AssertJUnit.assertEquals;
+ import static org.testng.AssertJUnit.assertNotNull;
+ import static org.testng.AssertJUnit.assertTrue;
 -import jalview.datamodel.Alignment;
  import jalview.datamodel.AlignmentAnnotation;
  import jalview.datamodel.AlignmentI;
  import jalview.datamodel.Annotation;
@@@ -34,7 -36,7 +35,7 @@@ import java.util.BitSet
  import java.util.HashMap;
  import java.util.Map;
  
- import org.junit.Test;
+ import org.testng.annotations.Test;
  
  public class StockholmFileTest
  {
@@@ -83,6 -85,7 +84,7 @@@
     *          - label for IO class used to write and read back in the data from
     *          f
     */
    public static void testFileIOwithFormat(File f, String ioformat,
            int naliannot, int nminseqann)
    {
@@@ -92,7 -95,7 +94,7 @@@
      {
        AppletFormatAdapter rf = new AppletFormatAdapter();
  
 -      Alignment al = rf.readFile(ff, AppletFormatAdapter.FILE,
 +      AlignmentI al = rf.readFile(ff, AppletFormatAdapter.FILE,
                new IdentifyFile().Identify(ff, AppletFormatAdapter.FILE));
  
        assertNotNull("Couldn't read supplied alignment data.", al);
        System.out.println("Output file in '" + ioformat + "':\n"
                + outputfile + "\n<<EOF\n");
        // test for consistency in io
 -      Alignment al_input = new AppletFormatAdapter().readFile(outputfile,
 +      AlignmentI al_input = new AppletFormatAdapter().readFile(outputfile,
                AppletFormatAdapter.PASTE, ioformat);
        assertNotNull("Couldn't parse reimported alignment data.", al_input);
  
                  an_new.displayCharacter.trim())
                  || !("" + an_or.secondaryStructure).trim().equals(
                          ("" + an_new.secondaryStructure).trim())
 -                || (an_or.description != an_new.description && (an_or.description == null
 -                        || an_new.description == null || !an_or.description
 -                          .equals(an_new.description))))
 +                || (an_or.description != an_new.description && !((an_or.description == null && an_new.description
 +                        .trim().length() == 0)
 +                        || (an_new.description == null && an_or.description
 +                                .trim().length() == 0) || an_or.description
 +                        .trim().equals(an_new.description.trim()))))
          {
            System.err.println("Annotation Element Mismatch\nElement " + i
                    + " in original: " + annot_or.annotations[i].toString()
@@@ -1,10 -1,12 +1,12 @@@
  package jalview.util;
  
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertSame;
- import static org.junit.Assert.assertTrue;
++
+ import static org.testng.AssertJUnit.assertEquals;
+ import static org.testng.AssertJUnit.assertSame;
+ import static org.testng.AssertJUnit.assertTrue;
  import jalview.api.AlignViewportI;
  import jalview.datamodel.AlignedCodonFrame;
 -import jalview.datamodel.Alignment;
  import jalview.datamodel.AlignmentI;
  import jalview.datamodel.ColumnSelection;
  import jalview.datamodel.SearchResults;
@@@ -24,7 -26,7 +26,7 @@@ import java.util.HashSet
  import java.util.List;
  import java.util.Set;
  
- import org.junit.Test;
+ import org.testng.annotations.Test;
  
  public class MappingUtilsTest
  {
    protected AlignmentI loadAlignment(final String data, String format)
            throws IOException
    {
 -    Alignment a = new FormatAdapter().readFile(data,
 +    AlignmentI a = new FormatAdapter().readFile(data,
              AppletFormatAdapter.PASTE, format);
      a.setDataset(null);
      return a;