2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.commands;
23 import static org.testng.AssertJUnit.assertEquals;
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;
31 import org.testng.annotations.BeforeClass;
32 import org.testng.annotations.BeforeMethod;
33 import org.testng.annotations.Test;
36 * Unit tests for TrimRegionCommand
41 public class TrimRegionCommandTest
44 @BeforeClass(alwaysRun = true)
45 public void setUpJvOptionPane()
47 JvOptionPane.setInteractiveMode(false);
48 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
51 private AlignmentI al;
53 @BeforeMethod(alwaysRun = true)
56 SequenceI[] seqs = new SequenceI[2];
57 seqs[0] = new Sequence("seq0", "abcde-");
58 seqs[1] = new Sequence("seq1", "-ghjkl");
59 al = new Alignment(seqs);
64 * Test performing, undoing and redoing a 'trim left'
66 @Test(groups = { "Functional" })
67 public void testTrimLeft_withUndoAndRedo()
69 TrimRegionCommand cmd = new TrimRegionCommand("Remove Left", true,
70 al.getSequencesArray(), 2, al);
71 assertEquals(2, cmd.getSize());
72 assertEquals("cde-", al.getSequenceAt(0).getSequenceAsString());
73 assertEquals("hjkl", al.getSequenceAt(1).getSequenceAsString());
78 cmd.undoCommand(new AlignmentI[] { al });
79 assertEquals("abcde-", al.getSequenceAt(0).getSequenceAsString());
80 assertEquals("-ghjkl", al.getSequenceAt(1).getSequenceAsString());
85 cmd.doCommand(new AlignmentI[] { al });
86 assertEquals("cde-", al.getSequenceAt(0).getSequenceAsString());
87 assertEquals("hjkl", al.getSequenceAt(1).getSequenceAsString());
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.
94 @Test(groups = { "Functional" })
95 public void testTrimLeft_noColumns()
97 TrimRegionCommand cmd = new TrimRegionCommand("Remove Left", true,
98 al.getSequencesArray(), 0, al);
99 assertEquals(0, cmd.getSize());
100 assertEquals("abcde-", al.getSequenceAt(0).getSequenceAsString());
101 assertEquals("-ghjkl", al.getSequenceAt(1).getSequenceAsString());
105 * Trim left of a single column
107 @Test(groups = { "Functional" })
108 public void testTrimLeft_oneColumn()
110 TrimRegionCommand cmd = new TrimRegionCommand("Remove Left", true,
111 al.getSequencesArray(), 1, al);
112 assertEquals(1, cmd.getSize());
113 assertEquals("bcde-", al.getSequenceAt(0).getSequenceAsString());
114 assertEquals("ghjkl", al.getSequenceAt(1).getSequenceAsString());
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.
121 @Test(groups = { "Functional" })
122 public void testTrimRight_noColumns()
124 TrimRegionCommand cmd = new TrimRegionCommand("Remove Right", false,
125 al.getSequencesArray(), 5, al);
126 assertEquals(0, cmd.getSize());
127 assertEquals("abcde-", al.getSequenceAt(0).getSequenceAsString());
128 assertEquals("-ghjkl", al.getSequenceAt(1).getSequenceAsString());
132 * Trim right of a single column
134 @Test(groups = { "Functional" })
135 public void testTrimRight_oneColumn()
137 TrimRegionCommand cmd = new TrimRegionCommand("Remove Right", false,
138 al.getSequencesArray(), 4, al);
139 assertEquals(1, cmd.getSize());
140 assertEquals("abcde", al.getSequenceAt(0).getSequenceAsString());
141 assertEquals("-ghjk", al.getSequenceAt(1).getSequenceAsString());
145 * Test performing, undoing and redoing a 'trim right'
147 @Test(groups = { "Functional" })
148 public void testTrimRight_withUndoAndRedo()
150 TrimRegionCommand cmd = new TrimRegionCommand("Remove Right", false,
151 al.getSequencesArray(), 2, al);
152 assertEquals(3, cmd.getSize());
153 assertEquals("abc", al.getSequenceAt(0).getSequenceAsString());
154 assertEquals("-gh", al.getSequenceAt(1).getSequenceAsString());
159 cmd.undoCommand(new AlignmentI[] { al });
160 assertEquals("abcde-", al.getSequenceAt(0).getSequenceAsString());
161 assertEquals("-ghjkl", al.getSequenceAt(1).getSequenceAsString());
166 cmd.doCommand(new AlignmentI[] { al });
167 assertEquals("abc", al.getSequenceAt(0).getSequenceAsString());
168 assertEquals("-gh", al.getSequenceAt(1).getSequenceAsString());