source: josm/trunk/test/unit/org/openstreetmap/josm/gui/dialogs/CommandStackDialogTest.java@ 11110

Last change on this file since 11110 was 11110, checked in by Don-vip, 8 years ago

add more unit tests

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs;
3
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertTrue;
6
7import org.junit.Rule;
8import org.junit.Test;
9import org.openstreetmap.josm.Main;
10import org.openstreetmap.josm.TestUtils;
11import org.openstreetmap.josm.command.Command;
12import org.openstreetmap.josm.data.osm.DataSet;
13import org.openstreetmap.josm.gui.layer.OsmDataLayer;
14import org.openstreetmap.josm.testutils.JOSMTestRules;
15
16import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
17
18/**
19 * Unit tests of {@link CommandStackDialog} class.
20 */
21public class CommandStackDialogTest {
22
23 /**
24 * Setup tests
25 */
26 @Rule
27 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
28 public JOSMTestRules test = new JOSMTestRules().commands();
29
30 /**
31 * Unit test of {@link CommandStackDialog} class - empty case.
32 */
33 @Test
34 public void testCommandStackDialogEmpty() {
35 CommandStackDialog dlg = new CommandStackDialog();
36 dlg.showDialog();
37 assertTrue(dlg.isVisible());
38 dlg.hideDialog();
39 assertFalse(dlg.isVisible());
40 }
41
42 /**
43 * Unit test of {@link CommandStackDialog} class - not empty case.
44 */
45 @Test
46 public void testCommandStackDialogNotEmpty() {
47 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null);
48 Main.getLayerManager().addLayer(layer);
49 try {
50 Command cmd1 = TestUtils.newCommand();
51 Command cmd2 = TestUtils.newCommand();
52 Main.main.undoRedo.add(cmd1);
53 Main.main.undoRedo.add(cmd2);
54 Main.main.undoRedo.undo(1);
55
56 assertFalse(Main.main.undoRedo.commands.isEmpty());
57 assertFalse(Main.main.undoRedo.redoCommands.isEmpty());
58
59 CommandStackDialog dlg = new CommandStackDialog();
60 Main.map.addToggleDialog(dlg);
61 dlg.unfurlDialog();
62 assertTrue(dlg.isVisible());
63 Main.map.removeToggleDialog(dlg);
64 dlg.hideDialog();
65 assertFalse(dlg.isVisible());
66 } finally {
67 Main.main.undoRedo.clean();
68 Main.getLayerManager().removeLayer(layer);
69 }
70 }
71}
Note: See TracBrowser for help on using the repository browser.