Changeset 14366 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2018-10-26T01:55:07+02:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/io/DownloadOpenChangesetsTaskTest.java
r13435 r14366 2 2 package org.openstreetmap.josm.gui.io; 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 import static org.junit.Assert.assertTrue; 7 8 9 import java.awt.GraphicsEnvironment; 10 import java.net.URL; 11 12 import javax.swing.JOptionPane; 8 13 import javax.swing.JPanel; 9 14 10 15 import org.junit.Rule; 11 16 import org.junit.Test; 17 import org.openstreetmap.josm.TestUtils; 12 18 import org.openstreetmap.josm.data.UserIdentityManager; 19 import org.openstreetmap.josm.gui.oauth.OAuthAuthorizationWizard; 13 20 import org.openstreetmap.josm.testutils.JOSMTestRules; 21 import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker; 22 import org.openstreetmap.josm.testutils.mockers.WindowMocker; 23 import org.openstreetmap.josm.tools.UserCancelException; 24 25 import com.google.common.collect.ImmutableMap; 14 26 15 27 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 28 import mockit.Invocation; 29 import mockit.Mock; 30 import mockit.MockUp; 16 31 17 32 /** … … 25 40 @Rule 26 41 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 27 public JOSMTestRules test = new JOSMTestRules().preferences().devAPI() .timeout(20000);42 public JOSMTestRules test = new JOSMTestRules().preferences().devAPI(); 28 43 29 44 /** 30 * Test of {@link DownloadOpenChangesetsTask} class. 45 * OAuth wizard mocker. 46 */ 47 public static class OAuthWizardMocker extends MockUp<OAuthAuthorizationWizard> { 48 /** {@code true} if wizard has been called */ 49 public boolean called; 50 51 @Mock 52 void showDialog() throws UserCancelException { 53 this.called = true; 54 throw new UserCancelException(); 55 } 56 57 @Mock 58 void obtainAccessToken(final Invocation invocation, final URL serverUrl) { 59 if (GraphicsEnvironment.isHeadless()) { 60 // we can't really let execution proceed any further as construction of the ui 61 // elements will fail with a mocked Window 62 this.called = true; 63 return; 64 } 65 // else we can allow a bit more of the code to be covered before we raise 66 // UserCancelException in showDialog 67 invocation.proceed(serverUrl); 68 } 69 } 70 71 /** 72 * Test of {@link DownloadOpenChangesetsTask} class when anonymous. 31 73 */ 32 74 @Test 33 public void testDownloadOpenChangesetsTask() { 75 public void testAnonymous() { 76 TestUtils.assumeWorkingJMockit(); 77 if (GraphicsEnvironment.isHeadless()) { 78 new WindowMocker(); 79 } 80 final OAuthWizardMocker oaWizardMocker = new OAuthWizardMocker(); 81 final JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker( 82 ImmutableMap.<String, Object>of( 83 "<html>Could not retrieve the list of your open changesets because<br>JOSM does not know " 84 + "your identity.<br>You have either chosen to work anonymously or you are not " 85 + "entitled<br>to know the identity of the user on whose behalf you are working.</html>", JOptionPane.OK_OPTION 86 ) 87 ); 88 34 89 DownloadOpenChangesetsTask task = new DownloadOpenChangesetsTask(new JPanel()); 35 90 assertNull(task.getChangesets()); … … 39 94 assertNull(task.getChangesets()); 40 95 41 task = new DownloadOpenChangesetsTask(new JPanel()); 96 assertEquals(1, jopsMocker.getInvocationLog().size()); 97 Object[] invocationLogEntry = jopsMocker.getInvocationLog().get(0); 98 assertEquals(JOptionPane.OK_OPTION, (int) invocationLogEntry[0]); 99 assertEquals("Missing user identity", invocationLogEntry[2]); 100 101 assertTrue(oaWizardMocker.called); 102 } 103 104 /** 105 * Test of {@link DownloadOpenChangesetsTask} class when "partially identified". 106 */ 107 @Test 108 public void testPartiallyIdentified() { 109 TestUtils.assumeWorkingJMockit(); 110 if (GraphicsEnvironment.isHeadless()) { 111 new WindowMocker(); 112 } 113 final OAuthWizardMocker oaWizardMocker = new OAuthWizardMocker(); 114 final JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker( 115 ImmutableMap.<String, Object>of("There are no open changesets", JOptionPane.OK_OPTION) 116 ); 117 118 DownloadOpenChangesetsTask task = new DownloadOpenChangesetsTask(new JPanel()); 42 119 UserIdentityManager.getInstance().setPartiallyIdentified(System.getProperty("osm.username", "josm_test")); 43 120 assertTrue(UserIdentityManager.getInstance().isPartiallyIdentified()); 44 121 task.run(); 45 122 assertNotNull(task.getChangesets()); 123 124 assertEquals(1, jopsMocker.getInvocationLog().size()); 125 Object[] invocationLogEntry = jopsMocker.getInvocationLog().get(0); 126 assertEquals(JOptionPane.OK_OPTION, (int) invocationLogEntry[0]); 127 assertEquals("No open changesets", invocationLogEntry[2]); 128 129 assertTrue(oaWizardMocker.called); 46 130 } 47 131 }
Note:
See TracChangeset
for help on using the changeset viewer.