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

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

see #15182 - deprecate Main.main.undoRedo. Replacement: gui.MainApplication.undoRedo

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