From e1669ae8e01b9458fee7cd492df38cef24e0497b Mon Sep 17 00:00:00 2001
From: Robert Scott <code@humanleg.org.uk>
Date: Mon, 29 Oct 2018 21:59:28 +0000
Subject: [PATCH v1 2/2] GenericRelationEditorTest: fix for non-headless mode
---
.../gui/dialogs/relation/GenericRelationEditor.java | 4 +---
.../dialogs/relation/GenericRelationEditorTest.java | 20 ++++++++++++++++++++
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java b/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
index 37fb97a5d..9c2a90bce 100644
|
a
|
b
|
public class GenericRelationEditor extends RelationEditor {
|
| 905 | 905 | boolean modified = false; |
| 906 | 906 | for (OsmPrimitive p : primitivesToAdd) { |
| 907 | 907 | if (p instanceof Relation && orig.equals(p)) { |
| 908 | | if (!GraphicsEnvironment.isHeadless()) { |
| 909 | | warnOfCircularReferences(p); |
| 910 | | } |
| | 908 | warnOfCircularReferences(p); |
| 911 | 909 | continue; |
| 912 | 910 | } else if (MemberTableModel.hasMembersReferringTo(relation.getMembers(), Collections.singleton(p)) |
| 913 | 911 | && !confirmAddingPrimitive(p)) { |
diff --git a/test/unit/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditorTest.java b/test/unit/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditorTest.java
index f52faf622..b2391cf31 100644
|
a
|
b
|
|
| 1 | 1 | // License: GPL. For details, see LICENSE file. |
| 2 | 2 | package org.openstreetmap.josm.gui.dialogs.relation; |
| 3 | 3 | |
| | 4 | import static org.junit.Assert.assertEquals; |
| 4 | 5 | import static org.junit.Assert.assertNotNull; |
| 5 | 6 | import static org.junit.Assert.assertNull; |
| 6 | 7 | |
| 7 | 8 | import java.util.Collections; |
| 8 | 9 | |
| | 10 | import javax.swing.JOptionPane; |
| 9 | 11 | import javax.swing.JPanel; |
| 10 | 12 | |
| 11 | 13 | import org.junit.Rule; |
| … |
… |
import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
| 20 | 22 | import org.openstreetmap.josm.gui.tagging.TagEditorPanel; |
| 21 | 23 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField; |
| 22 | 24 | import org.openstreetmap.josm.testutils.JOSMTestRules; |
| | 25 | import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker; |
| 23 | 26 | |
| 24 | 27 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
| 25 | 28 | |
| … |
… |
public class GenericRelationEditorTest {
|
| 82 | 85 | */ |
| 83 | 86 | @Test |
| 84 | 87 | public void testAddPrimitivesToRelation() { |
| | 88 | TestUtils.assumeWorkingJMockit(); |
| | 89 | final JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker(); |
| | 90 | |
| 85 | 91 | Relation r = TestUtils.addFakeDataSet(new Relation(1)); |
| 86 | 92 | assertNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.<OsmPrimitive>emptyList())); |
| | 93 | |
| | 94 | jopsMocker.getMockResultMap().put( |
| | 95 | "<html>You are trying to add a relation to itself.<br><br>This creates circular references " |
| | 96 | + "and is therefore discouraged.<br>Skipping relation 'incomplete'.</html>", |
| | 97 | JOptionPane.OK_OPTION |
| | 98 | ); |
| | 99 | |
| 87 | 100 | assertNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.singleton(new Relation(1)))); |
| 88 | 101 | |
| | 102 | assertEquals(1, jopsMocker.getInvocationLog().size()); |
| | 103 | Object[] invocationLogEntry = jopsMocker.getInvocationLog().get(0); |
| | 104 | assertEquals(JOptionPane.OK_OPTION, (int) invocationLogEntry[0]); |
| | 105 | assertEquals("Warning", invocationLogEntry[2]); |
| | 106 | |
| 89 | 107 | assertNotNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.singleton(new Node(1)))); |
| 90 | 108 | assertNotNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.singleton(new Way(1)))); |
| 91 | 109 | assertNotNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.singleton(new Relation(2)))); |
| | 110 | |
| | 111 | assertEquals(1, jopsMocker.getInvocationLog().size()); |
| 92 | 112 | } |
| 93 | 113 | |
| 94 | 114 | /** |