1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertFalse;
|
---|
5 | import static org.junit.Assert.assertTrue;
|
---|
6 |
|
---|
7 | import org.junit.Rule;
|
---|
8 | import org.junit.Test;
|
---|
9 | import org.openstreetmap.josm.Main;
|
---|
10 | import org.openstreetmap.josm.TestUtils;
|
---|
11 | import org.openstreetmap.josm.command.Command;
|
---|
12 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
13 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
14 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
15 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
16 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
17 |
|
---|
18 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Unit tests of {@link CommandStackDialog} class.
|
---|
22 | */
|
---|
23 | public class CommandStackDialogTest {
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Setup tests
|
---|
27 | */
|
---|
28 | @Rule
|
---|
29 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
30 | public JOSMTestRules test = new JOSMTestRules().main().platform().projection();
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Unit test of {@link CommandStackDialog} class - empty case.
|
---|
34 | */
|
---|
35 | @Test
|
---|
36 | public void testCommandStackDialogEmpty() {
|
---|
37 | CommandStackDialog dlg = new CommandStackDialog();
|
---|
38 | dlg.showDialog();
|
---|
39 | assertTrue(dlg.isVisible());
|
---|
40 | dlg.hideDialog();
|
---|
41 | assertFalse(dlg.isVisible());
|
---|
42 | }
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Unit test of {@link CommandStackDialog} class - not empty case.
|
---|
46 | */
|
---|
47 | @Test
|
---|
48 | public void testCommandStackDialogNotEmpty() {
|
---|
49 | OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null);
|
---|
50 | Main.getLayerManager().addLayer(layer);
|
---|
51 | try {
|
---|
52 | Command cmd1 = TestUtils.newCommand();
|
---|
53 | Command cmd2 = TestUtils.newCommand();
|
---|
54 | Main.main.undoRedo.add(cmd1);
|
---|
55 | Main.main.undoRedo.add(cmd2);
|
---|
56 | Main.main.undoRedo.undo(1);
|
---|
57 |
|
---|
58 | assertFalse(Main.main.undoRedo.commands.isEmpty());
|
---|
59 | assertFalse(Main.main.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 | Main.main.undoRedo.clean();
|
---|
71 | Main.getLayerManager().removeLayer(layer);
|
---|
72 | }
|
---|
73 | }
|
---|
74 | }
|
---|