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

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

see #13036 - deprecate Command() default constructor, fix unit tests and java warnings

  • 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 DataSet ds = new DataSet();
49 OsmDataLayer layer = new OsmDataLayer(ds, "", null);
50 MainApplication.getLayerManager().addLayer(layer);
51 try {
52 Command cmd1 = TestUtils.newCommand(ds);
53 Command cmd2 = TestUtils.newCommand(ds);
54 MainApplication.undoRedo.add(cmd1);
55 MainApplication.undoRedo.add(cmd2);
56 MainApplication.undoRedo.undo(1);
57
58 assertFalse(MainApplication.undoRedo.commands.isEmpty());
59 assertFalse(MainApplication.undoRedo.redoCommands.isEmpty());
60
61 MapFrame map = MainApplication.getMap();
62 CommandStackDialog dlg = new CommandStackDialog();
63 map.addToggleDialog(dlg);
64 dlg.unfurlDialog();
65 assertTrue(dlg.isVisible());
66 map.removeToggleDialog(dlg);
67 dlg.hideDialog();
68 assertFalse(dlg.isVisible());
69 } finally {
70 MainApplication.undoRedo.clean();
71 MainApplication.getLayerManager().removeLayer(layer);
72 }
73 }
74}
Note: See TracBrowser for help on using the repository browser.