JAL-1264 unit test corrected
[jalview.git] / test / jalview / datamodel / AlignmentTest.java
1 package jalview.datamodel;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertTrue;
6 import jalview.io.AppletFormatAdapter;
7
8 import java.io.IOException;
9 import java.util.Iterator;
10
11 import org.junit.Before;
12 import org.junit.Test;
13
14 /**
15  * Unit tests for Alignment datamodel.
16  * 
17  * @author gmcarstairs
18  *
19  */
20 public class AlignmentTest
21 {
22   // @formatter:off
23   private static final String TEST_DATA = 
24           "# STOCKHOLM 1.0\n" +
25           "#=GS D.melanogaster.1 AC AY119185.1/838-902\n" +
26           "#=GS D.melanogaster.2 AC AC092237.1/57223-57161\n" +
27           "#=GS D.melanogaster.3 AC AY060611.1/560-627\n" +
28           "D.melanogaster.1          G.AGCC.CU...AUGAUCGA\n" +
29           "#=GR D.melanogaster.1 SS  ................((((\n" +
30           "D.melanogaster.2          C.AUUCAACU.UAUGAGGAU\n" +
31           "#=GR D.melanogaster.2 SS  ................((((\n" +
32           "D.melanogaster.3          G.UGGCGCU..UAUGACGCA\n" +
33           "#=GR D.melanogaster.3 SS  (.(((...(....(((((((\n" +
34           "//";
35   // @formatter:on
36
37
38   private Alignment al;
39
40   /*
41    * Read in Stockholm format test data including secondary structure
42    * annotations.
43    */
44   @Before
45   public void setUp() throws IOException
46   {
47     al = new jalview.io.FormatAdapter().readFile(TEST_DATA,
48             AppletFormatAdapter.PASTE, "STH");
49     for (int i = 0; i < al.getSequencesArray().length; ++i)
50     {
51       al.getSequenceAt(i).setDatasetSequence(
52               al.getSequenceAt(i).createDatasetSequence());
53       al.addAnnotation(al.getSequenceAt(i).getAnnotation()[0]);
54       al.getSequenceAt(i).getAnnotation()[0].setCalcId("CalcIdFor"
55               + al.getSequenceAt(i).getName());
56     }
57   }
58
59   /**
60    * Test method that returns annotations that match on calcId.
61    */
62   @Test
63   public void testFindAnnotation_byCalcId()
64   {
65     Iterable<AlignmentAnnotation> anns = al
66             .findAnnotation("CalcIdForD.melanogaster.2");
67     Iterator<AlignmentAnnotation> iter = anns.iterator();
68     assertTrue(iter.hasNext());
69     AlignmentAnnotation ann = iter.next();
70     assertEquals("D.melanogaster.2", ann.sequenceRef.getName());
71     assertFalse(iter.hasNext());
72   }
73 }