Ticket #16914: v1-0002-GenericRelationEditorTest-fix-for-non-headless-mo.patch

File v1-0002-GenericRelationEditorTest-fix-for-non-headless-mo.patch, 4.0 KB (added by ris, 8 years ago)
  • src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    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 {  
    905905            boolean modified = false;
    906906            for (OsmPrimitive p : primitivesToAdd) {
    907907                if (p instanceof Relation && orig.equals(p)) {
    908                     if (!GraphicsEnvironment.isHeadless()) {
    909                         warnOfCircularReferences(p);
    910                     }
     908                    warnOfCircularReferences(p);
    911909                    continue;
    912910                } else if (MemberTableModel.hasMembersReferringTo(relation.getMembers(), Collections.singleton(p))
    913911                        && !confirmAddingPrimitive(p)) {
  • test/unit/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditorTest.java

    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  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.dialogs.relation;
    33
     4import static org.junit.Assert.assertEquals;
    45import static org.junit.Assert.assertNotNull;
    56import static org.junit.Assert.assertNull;
    67
    78import java.util.Collections;
    89
     10import javax.swing.JOptionPane;
    911import javax.swing.JPanel;
    1012
    1113import org.junit.Rule;
    import org.openstreetmap.josm.gui.layer.OsmDataLayer;  
    2022import org.openstreetmap.josm.gui.tagging.TagEditorPanel;
    2123import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    2224import org.openstreetmap.josm.testutils.JOSMTestRules;
     25import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
    2326
    2427import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2528
    public class GenericRelationEditorTest {  
    8285     */
    8386    @Test
    8487    public void testAddPrimitivesToRelation() {
     88        TestUtils.assumeWorkingJMockit();
     89        final JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker();
     90
    8591        Relation r = TestUtils.addFakeDataSet(new Relation(1));
    8692        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
    87100        assertNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.singleton(new Relation(1))));
    88101
     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
    89107        assertNotNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.singleton(new Node(1))));
    90108        assertNotNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.singleton(new Way(1))));
    91109        assertNotNull(GenericRelationEditor.addPrimitivesToRelation(r, Collections.singleton(new Relation(2))));
     110
     111        assertEquals(1, jopsMocker.getInvocationLog().size());
    92112    }
    93113
    94114    /**