JAL-1988 JAL-3130 New jlinked JRE in jalview_java2 with modules. Still needs jaxws...
[jalview.git] / test / jalview / analysis / SequenceIdMatcherTest.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.analysis;
22
23 import static org.testng.AssertJUnit.assertFalse;
24 import static org.testng.AssertJUnit.assertTrue;
25
26 import jalview.analysis.SequenceIdMatcher.SeqIdName;
27 import jalview.datamodel.SequenceI;
28 import jalview.gui.JvOptionPane;
29
30 import org.testng.annotations.BeforeClass;
31 import org.testng.annotations.Test;
32
33 public class SequenceIdMatcherTest
34 {
35
36   @BeforeClass(alwaysRun = true)
37   public void setUpJvOptionPane()
38   {
39     JvOptionPane.setInteractiveMode(false);
40     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
41   }
42
43
44   /**
45    * Test the method that checks for one sequence id starting with the other,
46    * followed by an 'allowed' separator character
47    */
48   @Test(groups = "Functional")
49   public void test_seqIdNameEquals()
50   {
51     SequenceIdMatcher sequenceIdMatcher = new SequenceIdMatcher(
52             new SequenceI[] {});
53
54     /*
55      * target name = matcher name + word separator...
56      */
57     SeqIdName testee = sequenceIdMatcher.new SeqIdName("A12345");
58     assertTrue(testee.equals("A12345"));
59     assertTrue(testee.equals("A12345~"));
60     assertTrue(testee.equals("A12345."));
61     assertTrue(testee.equals("A12345 "));
62     assertTrue(testee.equals("A12345|"));
63     assertTrue(testee.equals("A12345#"));
64     assertTrue(testee.equals("A12345\\"));
65     assertTrue(testee.equals("A12345/"));
66     assertTrue(testee.equals("A12345<"));
67     assertTrue(testee.equals("A12345>"));
68     assertTrue(testee.equals("A12345!"));
69     assertTrue(testee.equals("A12345\""));
70     assertTrue(testee.equals("A12345" + String.valueOf((char) 0x00A4)));
71     assertTrue(testee.equals("A12345$a"));
72     assertTrue(testee.equals("A12345%b"));
73     assertTrue(testee.equals("A12345^cd"));
74     assertTrue(testee.equals("A12345*efg"));
75     assertTrue(testee.equals("A12345)^&!"));
76     assertTrue(testee.equals("A12345}01&*"));
77     assertTrue(testee.equals("A12345[A23456"));
78     assertTrue(testee.equals("A12345@|Uniprot"));
79     assertTrue(testee.equals("A12345'whatever you want here"));
80     assertTrue(testee.equals("A12345,"));
81     assertTrue(testee.equals("A12345?"));
82     assertTrue(testee.equals("A12345_"));
83     /*
84      * case insensitive matching
85      */
86     assertTrue(testee.equals("a12345"));
87
88     /*
89      * matcher name = target name + word separator...
90      */
91     testee = sequenceIdMatcher.new SeqIdName("A12345#");
92     assertTrue(testee.equals("A12345"));
93
94     /*
95      * case insensitive matching
96      */
97     assertTrue(testee.equals("a12345"));
98
99     /*
100      * miscellaneous failing cases
101      */
102     testee = sequenceIdMatcher.new SeqIdName("A12345");
103     assertFalse(testee.equals((Object) null));
104     assertFalse(testee.equals(""));
105     assertFalse(testee.equals("A12346|A12345"));
106     /*
107      * case insensitive matching
108      */
109     assertTrue(testee.equals("a12345"));
110
111     testee = sequenceIdMatcher.new SeqIdName("A12345?B23456");
112     assertFalse(testee.equals("B23456"));
113     assertFalse(testee.equals("A12345|"));
114     assertFalse(testee.equals("A12345?"));
115
116     testee = sequenceIdMatcher.new SeqIdName("A12345<");
117     assertFalse(testee.equals("A12345?"));
118     assertTrue(testee.equals("A12345<")); // bug? inconsistent
119     /*
120      * case insensitive matching
121      */
122     assertTrue(testee.equals("a12345"));
123
124     testee = sequenceIdMatcher.new SeqIdName("UNIPROT|A12345");
125     assertFalse(testee.equals("A12345"));
126     assertFalse(testee.equals("UNIPROT|B98765"));
127     assertFalse(testee.equals("UNIPROT|"));
128     assertTrue(testee.equals("UNIPROT"));
129   }
130 }