1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.command.conflict;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertFalse;
|
---|
5 | import static org.junit.Assert.assertNotNull;
|
---|
6 | import static org.junit.Assert.assertTrue;
|
---|
7 | import nl.jqno.equalsverifier.EqualsVerifier;
|
---|
8 | import nl.jqno.equalsverifier.Warning;
|
---|
9 |
|
---|
10 | import org.junit.BeforeClass;
|
---|
11 | import org.junit.Test;
|
---|
12 | import org.openstreetmap.josm.JOSMFixture;
|
---|
13 | import org.openstreetmap.josm.Main;
|
---|
14 | import org.openstreetmap.josm.data.conflict.Conflict;
|
---|
15 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
16 | import org.openstreetmap.josm.data.osm.Node;
|
---|
17 | import org.openstreetmap.josm.data.osm.Way;
|
---|
18 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Unit tests of {@link ConflictAddCommand} class.
|
---|
22 | */
|
---|
23 | public class ConflictAddCommandTest {
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Setup test.
|
---|
27 | */
|
---|
28 | @BeforeClass
|
---|
29 | public static void setUpBeforeClass() {
|
---|
30 | JOSMFixture.createUnitTestFixture().init(true);
|
---|
31 | Main.map.mapView.addLayer(new OsmDataLayer(new DataSet(), null, null));
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Unit test of {@code ConflictAddCommand#executeCommand} and {@code ConflictAddCommand#undoCommand} methods.
|
---|
36 | */
|
---|
37 | @Test
|
---|
38 | public void testExecuteUndoCommand() {
|
---|
39 | OsmDataLayer layer = Main.map.mapView.getEditLayer();
|
---|
40 | Conflict<Node> conflict = new Conflict<>(new Node(), new Node());
|
---|
41 | ConflictAddCommand cmd = new ConflictAddCommand(layer, conflict);
|
---|
42 | assertTrue(cmd.executeCommand());
|
---|
43 | assertFalse(layer.getConflicts().isEmpty());
|
---|
44 | assertTrue(layer.getConflicts().hasConflict(conflict));
|
---|
45 | cmd.undoCommand();
|
---|
46 | assertFalse(layer.getConflicts().hasConflict(conflict));
|
---|
47 | assertTrue(layer.getConflicts().isEmpty());
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Unit test of {@code ConflictAddCommand#getDescriptionIcon} method.
|
---|
52 | */
|
---|
53 | @Test
|
---|
54 | public void testGetDescriptionIcon() {
|
---|
55 | OsmDataLayer layer = Main.map.mapView.getEditLayer();
|
---|
56 | Conflict<Node> conflict = new Conflict<>(new Node(), new Node());
|
---|
57 | assertNotNull(new ConflictAddCommand(layer, conflict).getDescriptionIcon());
|
---|
58 | }
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Unit test of methods {@link ConflictAddCommand#equals} and {@link ConflictAddCommand#hashCode}.
|
---|
62 | */
|
---|
63 | @Test
|
---|
64 | public void equalsContract() {
|
---|
65 | EqualsVerifier.forClass(ConflictAddCommand.class).usingGetClass()
|
---|
66 | .withPrefabValues(Conflict.class,
|
---|
67 | new Conflict<>(new Node(), new Node()), new Conflict<>(new Way(), new Way()))
|
---|
68 | .withPrefabValues(OsmDataLayer.class,
|
---|
69 | new OsmDataLayer(new DataSet(), "1", null), new OsmDataLayer(new DataSet(), "2", null))
|
---|
70 | .suppress(Warning.NONFINAL_FIELDS)
|
---|
71 | .verify();
|
---|
72 | }
|
---|
73 | }
|
---|