Changeset 14358 in josm for trunk/test
- Timestamp:
- 2018-10-23T01:34:26+02:00 (6 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/io/SaveLayersDialogTest.java
r10962 r14358 2 2 package org.openstreetmap.josm.gui.io; 3 3 4 import static org.junit.Assert.assertEquals; 4 5 import static org.junit.Assert.assertFalse; 5 6 import static org.junit.Assert.assertTrue; … … 7 8 import java.util.Collections; 8 9 import java.util.List; 10 import javax.swing.JComponent; 11 import javax.swing.JLabel; 12 import javax.swing.JList; 13 import javax.swing.JOptionPane; 9 14 10 15 import org.junit.Rule; … … 13 18 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 14 19 import org.openstreetmap.josm.testutils.JOSMTestRules; 20 import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker; 15 21 16 22 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 34 40 public void testConfirmSaveLayerInfosOK() { 35 41 final List<SaveLayerInfo> list = Collections.singletonList(new SaveLayerInfo(new OsmDataLayer(new DataSet(), null, null))); 42 43 final JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker() { 44 @Override 45 protected void act(final Object message) { 46 // use this opportunity to assert that our SaveLayerInfo is the single option in the JList 47 @SuppressWarnings("unchecked") 48 final JList<SaveLayerInfo> jList = (JList<SaveLayerInfo>) ((JComponent) message).getComponent(1); 49 assertEquals(1, jList.getModel().getSize()); 50 assertEquals(list.get(0), jList.getModel().getElementAt(0)); 51 } 52 53 @Override 54 protected String getStringFromMessage(final Object message) { 55 return ((JLabel) ((JComponent) message).getComponent(0)).getText(); 56 } 57 }; 58 59 jopsMocker.getMockResultMap().put( 60 "<html>1 layer has unresolved conflicts.<br>Either resolve them first or discard the " 61 + "modifications.<br>Layer with conflicts:</html>", JOptionPane.OK_OPTION 62 ); 63 36 64 assertFalse(SaveLayersDialog.confirmSaveLayerInfosOK(new SaveLayersModel() { 37 65 @Override … … 40 68 } 41 69 })); 70 71 assertEquals(1, jopsMocker.getInvocationLog().size()); 72 Object[] invocationLogEntry = jopsMocker.getInvocationLog().get(0); 73 assertEquals(JOptionPane.OK_OPTION, (int) invocationLogEntry[0]); 74 assertEquals("Unsaved data and conflicts", invocationLogEntry[2]); 75 76 jopsMocker.resetInvocationLog(); 77 jopsMocker.getMockResultMap().clear(); 78 jopsMocker.getMockResultMap().put( 79 "<html>1 layer needs saving but has no associated file.<br>Either select a file for this " 80 + "layer or discard the changes.<br>Layer without a file:</html>", JOptionPane.OK_OPTION 81 ); 82 42 83 assertFalse(SaveLayersDialog.confirmSaveLayerInfosOK(new SaveLayersModel() { 43 84 @Override … … 46 87 } 47 88 })); 89 90 assertEquals(1, jopsMocker.getInvocationLog().size()); 91 invocationLogEntry = jopsMocker.getInvocationLog().get(0); 92 assertEquals(JOptionPane.OK_OPTION, (int) invocationLogEntry[0]); 93 assertEquals("Unsaved data and missing associated file", invocationLogEntry[2]); 94 95 jopsMocker.resetInvocationLog(); 96 jopsMocker.getMockResultMap().clear(); 97 jopsMocker.getMockResultMap().put( 98 "<html>1 layer needs saving but has an associated file<br>which cannot be written.<br>Either " 99 + "select another file for this layer or discard the changes.<br>Layer with a non-writable " 100 + "file:</html>", JOptionPane.OK_OPTION 101 ); 102 48 103 assertFalse(SaveLayersDialog.confirmSaveLayerInfosOK(new SaveLayersModel() { 49 104 @Override … … 52 107 } 53 108 })); 109 110 assertEquals(1, jopsMocker.getInvocationLog().size()); 111 invocationLogEntry = jopsMocker.getInvocationLog().get(0); 112 assertEquals(JOptionPane.OK_OPTION, (int) invocationLogEntry[0]); 113 assertEquals("Unsaved data non-writable files", invocationLogEntry[2]); 114 115 jopsMocker.resetInvocationLog(); 116 jopsMocker.getMockResultMap().clear(); 117 54 118 assertTrue(SaveLayersDialog.confirmSaveLayerInfosOK(new SaveLayersModel())); 55 119 } -
trunk/test/unit/org/openstreetmap/josm/testutils/mockers/JOptionPaneSimpleMocker.java
r14332 r14358 76 76 JOptionPane.CANCEL_OPTION, 77 77 JOptionPane.CLOSED_OPTION 78 }, 79 // it's hard to know much about DEFAULT_OPTION, so we can't really police anything here, so 80 // including all known options 81 JOptionPane.DEFAULT_OPTION, new int[] { 82 JOptionPane.OK_OPTION, 83 JOptionPane.CANCEL_OPTION, 84 JOptionPane.CLOSED_OPTION, 85 JOptionPane.YES_OPTION, 86 JOptionPane.NO_OPTION 78 87 } 79 88 );
Note:
See TracChangeset
for help on using the changeset viewer.