JAL-4134 JAL-2349 test & fixed implementation(ish) for getMappedPositionsFor(seq...
[jalview.git] / test / jalview / datamodel / AllRowsIteratorTest.java
index fd1d29d..9f4c65b 100644 (file)
@@ -34,9 +34,9 @@ public class AllRowsIteratorTest
 {
   AlignmentI al;
 
-  Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
+  Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<>();
 
-  @BeforeClass
+  @BeforeClass(alwaysRun = true)
   public void setup()
   {
     // create random alignment
@@ -69,8 +69,10 @@ public class AllRowsIteratorTest
    * Test iterator throws NoSuchElementException at end of iteration
    */
   @Test(
-    groups = { "Functional" },
-    expectedExceptions = { NoSuchElementException.class })
+    groups =
+    { "Functional" },
+    expectedExceptions =
+    { NoSuchElementException.class })
   public void testLastNext() throws NoSuchElementException
   {
     AllRowsIterator it = new AllRowsIterator(0, 3, al);
@@ -85,15 +87,16 @@ public class AllRowsIteratorTest
    * Test iterator throws UnsupportedOperationException on call to remove
    */
   @Test(
-    groups = { "Functional" },
-    expectedExceptions = { UnsupportedOperationException.class })
+    groups =
+    { "Functional" },
+    expectedExceptions =
+    { UnsupportedOperationException.class })
   public void testRemove() throws UnsupportedOperationException
   {
     AllRowsIterator it = new AllRowsIterator(0, 3, al);
     it.remove();
   }
 
-
   /*
    * Hide sequences between start and end
    */
@@ -110,4 +113,21 @@ public class AllRowsIteratorTest
 
     hiddenRepSequences.put(allseqs[start], theseSeqs);
   }
+
+  /*
+   * Test iterator behaves correctly when there is only one element in the collection
+   */
+  @Test(groups = { "Functional" })
+  public void testOneElement()
+  {
+    AllRowsIterator it = new AllRowsIterator(0, 0, al);
+    int count = 0;
+    while (it.hasNext())
+    {
+      it.next();
+      count++;
+    }
+    assertTrue(count == 1, "hasNext() is false after 1 iteration");
+  }
+
 }