source: josm/trunk/test/unit/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommandTest.java@ 9666

Last change on this file since 9666 was 9666, checked in by stoecker, 8 years ago

see #12410 fix style of tests

File size: 3.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command.conflict;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertNotNull;
6import static org.junit.Assert.assertTrue;
7import nl.jqno.equalsverifier.EqualsVerifier;
8import nl.jqno.equalsverifier.Warning;
9
10import org.junit.BeforeClass;
11import org.junit.Test;
12import org.openstreetmap.josm.JOSMFixture;
13import org.openstreetmap.josm.Main;
14import org.openstreetmap.josm.data.conflict.Conflict;
15import org.openstreetmap.josm.data.coor.LatLon;
16import org.openstreetmap.josm.data.osm.DataSet;
17import org.openstreetmap.josm.data.osm.Node;
18import org.openstreetmap.josm.data.osm.Way;
19import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
20import org.openstreetmap.josm.gui.layer.OsmDataLayer;
21
22/**
23 * Unit tests of {@link CoordinateConflictResolveCommand} class.
24 */
25public class CoordinateConflictResolveCommandTest {
26
27 /**
28 * Setup test.
29 */
30 @BeforeClass
31 public static void setUpBeforeClass() {
32 JOSMFixture.createUnitTestFixture().init(true);
33 Main.map.mapView.addLayer(new OsmDataLayer(new DataSet(), null, null));
34 }
35
36 private static Conflict<Node> createConflict() {
37 return new Conflict<>(new Node(LatLon.ZERO), new Node(new LatLon(50, 50)));
38 }
39
40 /**
41 * Unit test of {@code CoordinateConflictResolveCommand#executeCommand} and {@code CoordinateConflictResolveCommand#undoCommand} methods.
42 */
43 @Test
44 public void testExecuteKeepMineUndoCommand() {
45 Conflict<Node> conflict = createConflict();
46 CoordinateConflictResolveCommand cmd = new CoordinateConflictResolveCommand(conflict, MergeDecisionType.KEEP_MINE);
47 assertTrue(cmd.executeCommand());
48 assertEquals(LatLon.ZERO, conflict.getMy().getCoor());
49 cmd.undoCommand();
50 assertEquals(LatLon.ZERO, conflict.getMy().getCoor());
51 }
52
53 /**
54 * Unit test of {@code CoordinateConflictResolveCommand#executeCommand} and {@code CoordinateConflictResolveCommand#undoCommand} methods.
55 */
56 @Test
57 public void testExecuteKeepTheirUndoCommand() {
58 Conflict<Node> conflict = createConflict();
59 CoordinateConflictResolveCommand cmd = new CoordinateConflictResolveCommand(conflict, MergeDecisionType.KEEP_THEIR);
60 assertTrue(cmd.executeCommand());
61 assertEquals(conflict.getTheir().getCoor(), conflict.getMy().getCoor());
62 cmd.undoCommand();
63 //assertEquals(LatLon.ZERO, conflict.getMy().getCoor()); // FIXME it does not work
64 }
65
66 /**
67 * Unit test of {@code CoordinateConflictResolveCommand#getDescriptionIcon} method.
68 */
69 @Test
70 public void testGetDescriptionIcon() {
71 Conflict<Node> conflict = createConflict();
72 assertNotNull(new CoordinateConflictResolveCommand(conflict, null).getDescriptionIcon());
73 }
74
75 /**
76 * Unit test of methods {@link CoordinateConflictResolveCommand#equals} and {@link CoordinateConflictResolveCommand#hashCode}.
77 */
78 @Test
79 public void equalsContract() {
80 EqualsVerifier.forClass(CoordinateConflictResolveCommand.class).usingGetClass()
81 .withPrefabValues(Conflict.class,
82 new Conflict<>(new Node(), new Node()), new Conflict<>(new Way(), new Way()))
83 .withPrefabValues(OsmDataLayer.class,
84 new OsmDataLayer(new DataSet(), "1", null), new OsmDataLayer(new DataSet(), "2", null))
85 .suppress(Warning.NONFINAL_FIELDS)
86 .verify();
87 }
88}
Note: See TracBrowser for help on using the repository browser.