Class |
Line # |
Actions |
|||
---|---|---|---|---|---|
TrimRegionCommandTest | 41 | 43 | 8 |
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.commands; | |
22 | ||
23 | import static org.testng.AssertJUnit.assertEquals; | |
24 | ||
25 | import jalview.datamodel.Alignment; | |
26 | import jalview.datamodel.AlignmentI; | |
27 | import jalview.datamodel.Sequence; | |
28 | import jalview.datamodel.SequenceI; | |
29 | import jalview.gui.JvOptionPane; | |
30 | ||
31 | import org.testng.annotations.BeforeClass; | |
32 | import org.testng.annotations.BeforeMethod; | |
33 | import org.testng.annotations.Test; | |
34 | ||
35 | /** | |
36 | * Unit tests for TrimRegionCommand | |
37 | * | |
38 | * @author gmcarstairs | |
39 | * | |
40 | */ | |
41 | public class TrimRegionCommandTest | |
42 | { | |
43 | ||
44 | 1 | @BeforeClass(alwaysRun = true) |
45 | public void setUpJvOptionPane() | |
46 | { | |
47 | 1 | JvOptionPane.setInteractiveMode(false); |
48 | 1 | JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
49 | } | |
50 | ||
51 | private AlignmentI al; | |
52 | ||
53 | 6 | @BeforeMethod(alwaysRun = true) |
54 | public void setUp() | |
55 | { | |
56 | 6 | SequenceI[] seqs = new SequenceI[2]; |
57 | 6 | seqs[0] = new Sequence("seq0", "abcde-"); |
58 | 6 | seqs[1] = new Sequence("seq1", "-ghjkl"); |
59 | 6 | al = new Alignment(seqs); |
60 | 6 | al.setDataset(null); |
61 | } | |
62 | ||
63 | /** | |
64 | * Test performing, undoing and redoing a 'trim left' | |
65 | */ | |
66 | 1 | @Test(groups = { "Functional" }) |
67 | public void testTrimLeft_withUndoAndRedo() | |
68 | { | |
69 | 1 | TrimRegionCommand cmd = new TrimRegionCommand("Remove Left", true, |
70 | al.getSequencesArray(), 2, al); | |
71 | 1 | assertEquals(2, cmd.getSize()); |
72 | 1 | assertEquals("cde-", al.getSequenceAt(0).getSequenceAsString()); |
73 | 1 | assertEquals("hjkl", al.getSequenceAt(1).getSequenceAsString()); |
74 | ||
75 | /* | |
76 | * undo and verify | |
77 | */ | |
78 | 1 | cmd.undoCommand(new AlignmentI[] { al }); |
79 | 1 | assertEquals("abcde-", al.getSequenceAt(0).getSequenceAsString()); |
80 | 1 | assertEquals("-ghjkl", al.getSequenceAt(1).getSequenceAsString()); |
81 | ||
82 | /* | |
83 | * redo and verify | |
84 | */ | |
85 | 1 | cmd.doCommand(new AlignmentI[] { al }); |
86 | 1 | assertEquals("cde-", al.getSequenceAt(0).getSequenceAsString()); |
87 | 1 | assertEquals("hjkl", al.getSequenceAt(1).getSequenceAsString()); |
88 | } | |
89 | ||
90 | /** | |
91 | * Trim left of no columns - should do nothing. This is the case where the | |
92 | * first column is selected and 'Remove Left' is selected. | |
93 | */ | |
94 | 1 | @Test(groups = { "Functional" }) |
95 | public void testTrimLeft_noColumns() | |
96 | { | |
97 | 1 | TrimRegionCommand cmd = new TrimRegionCommand("Remove Left", true, |
98 | al.getSequencesArray(), 0, al); | |
99 | 1 | assertEquals(0, cmd.getSize()); |
100 | 1 | assertEquals("abcde-", al.getSequenceAt(0).getSequenceAsString()); |
101 | 1 | assertEquals("-ghjkl", al.getSequenceAt(1).getSequenceAsString()); |
102 | } | |
103 | ||
104 | /** | |
105 | * Trim left of a single column | |
106 | */ | |
107 | 1 | @Test(groups = { "Functional" }) |
108 | public void testTrimLeft_oneColumn() | |
109 | { | |
110 | 1 | TrimRegionCommand cmd = new TrimRegionCommand("Remove Left", true, |
111 | al.getSequencesArray(), 1, al); | |
112 | 1 | assertEquals(1, cmd.getSize()); |
113 | 1 | assertEquals("bcde-", al.getSequenceAt(0).getSequenceAsString()); |
114 | 1 | assertEquals("ghjkl", al.getSequenceAt(1).getSequenceAsString()); |
115 | } | |
116 | ||
117 | /** | |
118 | * Trim right of no columns - should do nothing. This is the case where the | |
119 | * last column is selected and 'Remove Right' is selected. | |
120 | */ | |
121 | 1 | @Test(groups = { "Functional" }) |
122 | public void testTrimRight_noColumns() | |
123 | { | |
124 | 1 | TrimRegionCommand cmd = new TrimRegionCommand("Remove Right", false, |
125 | al.getSequencesArray(), 5, al); | |
126 | 1 | assertEquals(0, cmd.getSize()); |
127 | 1 | assertEquals("abcde-", al.getSequenceAt(0).getSequenceAsString()); |
128 | 1 | assertEquals("-ghjkl", al.getSequenceAt(1).getSequenceAsString()); |
129 | } | |
130 | ||
131 | /** | |
132 | * Trim right of a single column | |
133 | */ | |
134 | 1 | @Test(groups = { "Functional" }) |
135 | public void testTrimRight_oneColumn() | |
136 | { | |
137 | 1 | TrimRegionCommand cmd = new TrimRegionCommand("Remove Right", false, |
138 | al.getSequencesArray(), 4, al); | |
139 | 1 | assertEquals(1, cmd.getSize()); |
140 | 1 | assertEquals("abcde", al.getSequenceAt(0).getSequenceAsString()); |
141 | 1 | assertEquals("-ghjk", al.getSequenceAt(1).getSequenceAsString()); |
142 | } | |
143 | ||
144 | /** | |
145 | * Test performing, undoing and redoing a 'trim right' | |
146 | */ | |
147 | 1 | @Test(groups = { "Functional" }) |
148 | public void testTrimRight_withUndoAndRedo() | |
149 | { | |
150 | 1 | TrimRegionCommand cmd = new TrimRegionCommand("Remove Right", false, |
151 | al.getSequencesArray(), 2, al); | |
152 | 1 | assertEquals(3, cmd.getSize()); |
153 | 1 | assertEquals("abc", al.getSequenceAt(0).getSequenceAsString()); |
154 | 1 | assertEquals("-gh", al.getSequenceAt(1).getSequenceAsString()); |
155 | ||
156 | /* | |
157 | * undo and verify | |
158 | */ | |
159 | 1 | cmd.undoCommand(new AlignmentI[] { al }); |
160 | 1 | assertEquals("abcde-", al.getSequenceAt(0).getSequenceAsString()); |
161 | 1 | assertEquals("-ghjkl", al.getSequenceAt(1).getSequenceAsString()); |
162 | ||
163 | /* | |
164 | * redo and verify | |
165 | */ | |
166 | 1 | cmd.doCommand(new AlignmentI[] { al }); |
167 | 1 | assertEquals("abc", al.getSequenceAt(0).getSequenceAsString()); |
168 | 1 | assertEquals("-gh", al.getSequenceAt(1).getSequenceAsString()); |
169 | } | |
170 | } |