JAL-1803 tests added for PDBEntry.Type
[jalview.git] / test / jalview / datamodel / PDBEntryTest.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.assertEquals;
24 import static org.testng.Assert.assertFalse;
25 import static org.testng.Assert.assertNotEquals;
26 import static org.testng.Assert.assertNotSame;
27 import static org.testng.Assert.assertNull;
28 import static org.testng.Assert.assertSame;
29 import static org.testng.Assert.assertTrue;
30
31 //import org.testng.Assert;
32 import org.testng.annotations.AfterMethod;
33 import org.testng.annotations.BeforeMethod;
34 import org.testng.annotations.Test;
35
36 public class PDBEntryTest
37 {
38
39   @BeforeMethod(alwaysRun = true)
40   public void setUp() throws Exception
41   {
42   }
43
44   @AfterMethod(alwaysRun = true)
45   public void tearDown() throws Exception
46   {
47   }
48
49   @Test(groups = { "Functional" })
50   public void testEquals()
51   {
52     PDBEntry pdbEntry = new PDBEntry("1xyz", "A", PDBEntry.Type.PDB,
53             "x/y/z/File");
54
55     PDBEntry case1 = new PDBEntry("1XYZ", "A", PDBEntry.Type.PDB,
56             "x/y/z/File");
57     PDBEntry case2 = new PDBEntry("1xyz", "a", PDBEntry.Type.PDB,
58             "x/y/z/File");
59     PDBEntry case3 = new PDBEntry("1xyz", "A", PDBEntry.Type.FILE,
60             "x/y/z/File");
61     PDBEntry case4 = new PDBEntry(null, null, null, null);
62     PDBEntry case5 = new PDBEntry(null, "A", PDBEntry.Type.PDB,
63             "x/y/z/File");
64     PDBEntry case6 = new PDBEntry("1xyz", null, PDBEntry.Type.PDB,
65             "x/y/z/File");
66     PDBEntry case7 = new PDBEntry("1xyz", "A", null, "x/y/z/File");
67     PDBEntry case8 = new PDBEntry("1xyz", "A", PDBEntry.Type.PDB, null);
68     PDBEntry case9 = new PDBEntry("1xyz", "A", null, "x/y/z/File");
69
70     /*
71      * assertions will invoke PDBEntry.equals()
72      */
73     assertFalse(pdbEntry.equals(null));
74     assertFalse(pdbEntry.equals("a"));
75     assertEquals(case1, pdbEntry);
76     assertEquals(case2, pdbEntry);
77     assertNotEquals(case3, pdbEntry);
78     assertNotEquals(case4, pdbEntry);
79     assertNotEquals(case5, pdbEntry);
80     assertNotEquals(case6, pdbEntry);
81     assertNotEquals(case7, pdbEntry);
82     assertEquals(case8, pdbEntry);
83     assertEquals(case7, case9);
84
85     /*
86      * change string wrapper property to string...
87      */
88     case1.getProperty().put("chain_code", "a");
89     assertFalse(pdbEntry.equals(case1));
90     assertFalse(case1.equals(pdbEntry));
91   }
92
93   @Test(groups = { "Functional" })
94   public void testSetChainCode()
95   {
96     PDBEntry pdbEntry = new PDBEntry("1xyz", null, PDBEntry.Type.PDB,
97             "x/y/z/File");
98     assertNull(pdbEntry.getChainCode());
99
100     pdbEntry.setChainCode("a");
101     assertEquals("a", pdbEntry.getChainCode());
102
103     pdbEntry.setChainCode(null);
104     assertNull(pdbEntry.getChainCode());
105   }
106
107   @Test(groups = { "Functional" })
108   public void testGetType()
109   {
110     assertSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("FILE"));
111     assertSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("File"));
112     assertSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("file"));
113     assertNotSame(PDBEntry.Type.FILE, PDBEntry.Type.getType("file "));
114   }
115
116   @Test(groups = { "Functional" })
117   public void testTypeMatches()
118   {
119     // TODO Type.matches() is not used - delete?
120     assertTrue(PDBEntry.Type.FILE.matches("FILE"));
121     assertTrue(PDBEntry.Type.FILE.matches("File"));
122     assertTrue(PDBEntry.Type.FILE.matches("file"));
123     assertFalse(PDBEntry.Type.FILE.matches("FILE "));
124   }
125 }