JAL-2864 more generous wait for gc() to complete in test
[jalview.git] / test / jalview / datamodel / VisibleColsIteratorTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.datamodel;
22
23 import static org.testng.Assert.assertTrue;
24
25 import java.util.NoSuchElementException;
26
27 import org.testng.annotations.BeforeClass;
28 import org.testng.annotations.Test;
29
30 public class VisibleColsIteratorTest
31 {
32   HiddenColumns hiddenCols;
33
34   HiddenColumns hiddenColsAtStart;
35
36   @BeforeClass(groups = { "Functional" })
37   public void setup()
38   {
39     hiddenCols = new HiddenColumns();
40     hiddenCols.hideColumns(2, 4);
41
42     hiddenColsAtStart = new HiddenColumns();
43     hiddenColsAtStart.hideColumns(0, 2);
44   }
45
46   /*
47    * Test iterator iterates correctly through the columns
48    * when alignment has hidden cols
49    */
50   @Test(groups = { "Functional" })
51   public void testHasNextAndNextWithHidden()
52   {
53     VisibleColsIterator it = new VisibleColsIterator(0, 6, hiddenCols);
54     int count = 0;
55     while (it.hasNext())
56     {
57       it.next();
58       count++;
59     }
60     assertTrue(count == 4, "hasNext() is false after 4 iterations");
61   }
62
63   /*
64    * Test iterator iterates correctly through the columns
65    * when alignment has no hidden cols
66    */
67   @Test(groups = { "Functional" })
68   public void testHasNextAndNextNoHidden()
69   {
70     VisibleColsIterator it2 = new VisibleColsIterator(0, 3,
71             new HiddenColumns());
72     int count = 0;
73     while (it2.hasNext())
74     {
75       it2.next();
76       count++;
77     }
78     assertTrue(count == 4, "hasNext() is false after 4 iterations");
79   }
80
81   /*
82    * Test iterator iterates correctly through the columns
83    * when alignment has hidden cols at start
84    */
85   @Test(groups = { "Functional" })
86   public void testHasNextAndNextStartHidden()
87   {
88     VisibleColsIterator it3 = new VisibleColsIterator(0, 6,
89             hiddenColsAtStart);
90     int count = 0;
91     while (it3.hasNext())
92     {
93       it3.next();
94       count++;
95     }
96     assertTrue(count == 4, "hasNext() is false after 4 iterations");
97   }
98
99   /*
100    * Test iterator iterates correctly through the columns
101    * when alignment has hidden cols at end
102    */
103   @Test(groups = { "Functional" })
104   public void testHasNextAndNextEndHidden()
105   {
106     VisibleColsIterator it4 = new VisibleColsIterator(0, 4, hiddenCols);
107     int count = 0;
108     while (it4.hasNext())
109     {
110       it4.next();
111       count++;
112     }
113     assertTrue(count == 2, "hasNext() is false after 2 iterations");
114
115   }
116
117   /*
118    * Test iterator always throws NoSuchElementException at end of iteration
119    * when alignment has hidden cols
120    */
121   @Test(
122     groups = { "Functional" },
123     expectedExceptions = { NoSuchElementException.class })
124   public void testLastNextWithHidden() throws NoSuchElementException
125   {
126     VisibleColsIterator it = new VisibleColsIterator(0, 3, hiddenCols);
127     while (it.hasNext())
128     {
129       it.next();
130     }
131     it.next();
132   }
133
134   /*
135    * Test iterator always throws NoSuchElementException at end of iteration
136    * when alignment has no hidden cols
137    */
138   @Test(
139     groups = { "Functional" },
140     expectedExceptions = { NoSuchElementException.class })
141   public void testLastNextNoHidden() throws NoSuchElementException
142   {
143     VisibleColsIterator it2 = new VisibleColsIterator(0, 3,
144             new HiddenColumns());
145     while (it2.hasNext())
146     {
147       it2.next();
148     }
149     it2.next();
150   }
151
152   /*
153    * Test iterator always throws NoSuchElementException at end of iteration
154    * when alignment has hidden cols at start
155    */
156   @Test(
157     groups = { "Functional" },
158     expectedExceptions = { NoSuchElementException.class })
159   public void testLastNextStartHidden() throws NoSuchElementException
160   {
161     VisibleColsIterator it3 = new VisibleColsIterator(0, 6,
162             hiddenColsAtStart);
163     while (it3.hasNext())
164     {
165       it3.next();
166     }
167     it3.next();
168   }
169
170   /*
171    * Test iterator always throws NoSuchElementException at end of iteration
172    * when alignment has hidden cols at end
173    */
174   @Test(
175     groups = { "Functional" },
176     expectedExceptions = { NoSuchElementException.class })
177   public void testLastNextEndHidden() throws NoSuchElementException
178   {
179     VisibleColsIterator it4 = new VisibleColsIterator(0, 4, hiddenCols);
180     while (it4.hasNext())
181     {
182       it4.next();
183     }
184     it4.next();
185   }
186
187   /*
188    * Test calls to remove throw UnsupportedOperationException
189    */
190   @Test(
191     groups = { "Functional" },
192     expectedExceptions = { UnsupportedOperationException.class })
193   public void testRemove() throws UnsupportedOperationException
194   {
195     VisibleColsIterator it = new VisibleColsIterator(0, 3, hiddenCols);
196     it.remove();
197   }
198 }