Ignore:
Timestamp:
2015-12-15T21:47:02+01:00 (9 years ago)
Author:
floscher
Message:

[mapillary] Fix tests in MapillaryURLTest that were failing in Java 7 due to different ordering of HashMaps

Location:
applications/editors/josm/plugins/mapillary
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java

    r31826 r31833  
    3131  private final CopyOnWriteArrayList<MapillaryDataListener> listeners = new CopyOnWriteArrayList<>();
    3232  /** The bounds of the areas for which the pictures have been downloaded. */
    33   public CopyOnWriteArrayList<Bounds> bounds;
     33  public List<Bounds> bounds;
    3434
    3535  /**
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/FinishedUploadDialog.java

    r31828 r31833  
    88import java.awt.event.ActionListener;
    99import java.io.IOException;
    10 import java.net.URL;
    1110
    1211import javax.swing.BoxLayout;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryMainDialog.java

    r31828 r31833  
    22package org.openstreetmap.josm.plugins.mapillary.gui;
    33
     4import static org.openstreetmap.josm.tools.I18n.marktr;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    5 import static org.openstreetmap.josm.tools.I18n.marktr;
    66
    77import java.awt.BorderLayout;
     
    1515import java.io.ByteArrayInputStream;
    1616import java.io.IOException;
    17 import java.net.MalformedURLException;
    1817import java.util.Arrays;
    1918import java.util.List;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java

    r31828 r31833  
    33
    44import java.awt.FlowLayout;
     5import java.awt.GridBagConstraints;
    56import java.awt.GridBagLayout;
    67import java.awt.event.ActionEvent;
    78import java.io.IOException;
    8 import java.net.URL;
    99
    1010import javax.swing.AbstractAction;
     
    9292    onLogout();
    9393    panel.add(loginPanel, GBC.eol());
    94     panel.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH));
     94    panel.add(Box.createVerticalGlue(), GBC.eol().fill(GridBagConstraints.BOTH));
    9595
    9696    gui.getDisplayPreference().addSubTab(this, "Mapillary", new JScrollPane(panel));
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryDownloader.java

    r31828 r31833  
    66import java.util.ArrayList;
    77import java.util.concurrent.ArrayBlockingQueue;
    8 import java.util.concurrent.ConcurrentHashMap;
    98import java.util.concurrent.ThreadPoolExecutor;
    109import java.util.concurrent.TimeUnit;
     
    3938
    4039  /** Executor that will run the petitions. */
    41   private static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(3, 5,
    42       100, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(100));;
     40  private static ThreadPoolExecutor executor = new ThreadPoolExecutor(3, 5, 100, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(100));
    4341
    4442  /**
     
    5250   */
    5351  public static void getImages(LatLon minLatLon, LatLon maxLatLon) {
    54     if (maxLatLon == null || maxLatLon == null) {
     52    if (minLatLon == null || maxLatLon == null) {
    5553      throw new IllegalArgumentException();
    5654    }
     
    9088  private static void run(Thread t) {
    9189    threads.add(t);
    92     EXECUTOR.execute(t);
     90    executor.execute(t);
    9391  }
    9492
     
    214212    }
    215213    threads.clear();
    216     EXECUTOR.shutdownNow();
     214    executor.shutdownNow();
    217215    try {
    218       EXECUTOR.awaitTermination(30, TimeUnit.SECONDS);
     216      executor.awaitTermination(30, TimeUnit.SECONDS);
    219217    } catch (InterruptedException e) {
    220218      Main.error(e);
    221219    }
    222     EXECUTOR = new ThreadPoolExecutor(3, 5, 100, TimeUnit.SECONDS,
     220    executor = new ThreadPoolExecutor(3, 5, 100, TimeUnit.SECONDS,
    223221        new ArrayBlockingQueue<Runnable>(100));
    224222  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java

    r31827 r31833  
    3737  @Override
    3838  public void run() {
    39     try {
    40       ServerSocket serverSocket = new ServerSocket(PORT);
    41       Socket clientSocket = serverSocket.accept();
    42       PrintWriter out = new PrintWriter(new OutputStreamWriter(
    43           clientSocket.getOutputStream(), "UTF-8"), true);
    44       Scanner in = new Scanner(new InputStreamReader(
    45           clientSocket.getInputStream(), "UTF-8"));
     39    try (
     40        ServerSocket serverSocket = new ServerSocket(PORT);
     41        Socket clientSocket = serverSocket.accept();
     42        PrintWriter out = new PrintWriter(new OutputStreamWriter(clientSocket.getOutputStream(), "UTF-8"), true);
     43        Scanner in = new Scanner(new InputStreamReader(clientSocket.getInputStream(), "UTF-8"));
     44    ) {
    4645      String s;
    4746      String accessToken = null;
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/io/download/MapillarySequenceDownloadThreadTest.java

    r31828 r31833  
    66import static org.junit.Assert.assertTrue;
    77
    8 import java.util.Locale;
    98import java.util.concurrent.ExecutorService;
    109import java.util.concurrent.Executors;
     
    1514import org.openstreetmap.josm.plugins.mapillary.AbstractTest;
    1615import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
    17 import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
    18 import org.openstreetmap.josm.plugins.mapillary.io.download.MapillaryDownloader;
    19 import org.openstreetmap.josm.plugins.mapillary.io.download.MapillarySequenceDownloadThread;
    2016
    2117/**
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryURLTest.java

    r31831 r31833  
    33import static org.junit.Assert.assertEquals;
    44import static org.junit.Assert.assertNull;
     5import static org.junit.Assert.assertTrue;
    56import static org.junit.Assert.fail;
    67
     
    6162  @Test
    6263  public void testConnectURL() throws MalformedURLException {
    63     assertEquals(
    64         new URL("https://www.mapillary.com/connect/?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz&scope=user%3Aread+public%3Aupload+public%3Awrite&response_type=token&redirect_uri=http%3A%2F%2Fredirect-host%2F%C3%A4"),
    65         MapillaryURL.connectURL("http://redirect-host/ä")
    66     );
    67     assertEquals(
    68         new URL("https://www.mapillary.com/connect/?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz&scope=user%3Aread+public%3Aupload+public%3Awrite&response_type=token"),
    69         MapillaryURL.connectURL(null)
    70     );
    71     assertEquals(
    72         new URL("https://www.mapillary.com/connect/?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz&scope=user%3Aread+public%3Aupload+public%3Awrite&response_type=token"),
    73         MapillaryURL.connectURL("")
     64    assertUrlEquals(
     65        MapillaryURL.connectURL("http://redirect-host/ä"),
     66        "https://www.mapillary.com/connect/",
     67        "client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz",
     68        "scope=user%3Aread+public%3Aupload+public%3Awrite",
     69        "response_type=token",
     70        "redirect_uri=http%3A%2F%2Fredirect-host%2F%C3%A4"
     71    );
     72
     73    assertUrlEquals(
     74        MapillaryURL.connectURL(null),
     75        "https://www.mapillary.com/connect/",
     76        "client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz",
     77        "scope=user%3Aread+public%3Aupload+public%3Awrite",
     78        "response_type=token"
     79    );
     80
     81    assertUrlEquals(
     82        MapillaryURL.connectURL(""),
     83        "https://www.mapillary.com/connect/",
     84        "client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz",
     85        "scope=user%3Aread+public%3Aupload+public%3Awrite",
     86        "response_type=token"
    7487    );
    7588  }
     
    7790  @Test
    7891  public void testSearchImageURL() throws MalformedURLException {
    79     assertEquals(
    80         new URL("https://a.mapillary.com/v2/search/im/?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz&min_lon=2.220000&max_lat=3.333000&max_lon=4.444400&limit=20&page=42&min_lat=1.100000"),
    81         MapillaryURL.searchImageURL(new Bounds(1.1, 2.22, 3.333, 4.4444), 42)
    82     );
    83     assertEquals(
    84         new URL("https://a.mapillary.com/v2/search/im/?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz&limit=20&page=-73"),
    85         MapillaryURL.searchImageURL(null, -73)
     92    assertUrlEquals(
     93        MapillaryURL.searchImageURL(new Bounds(1.1, 2.22, 3.333, 4.4444), 42),
     94        "https://a.mapillary.com/v2/search/im/",
     95        "client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz",
     96        "min_lon=2.220000",
     97        "max_lon=4.444400",
     98        "min_lat=1.100000",
     99        "max_lat=3.333000",
     100        "limit=20",
     101        "page=42"
     102    );
     103    assertUrlEquals(
     104        MapillaryURL.searchImageURL(null, -73),
     105        "https://a.mapillary.com/v2/search/im/",
     106        "client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz",
     107        "limit=20",
     108        "page=-73"
    86109    );
    87110  }
     
    89112  @Test
    90113  public void testSearchSequenceURL() throws MalformedURLException {
    91     assertEquals(
    92         new URL("https://a.mapillary.com/v2/search/s/?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz&min_lon=-66.666666&max_lat=77.777778&max_lon=88.888889&limit=10&page=42&min_lat=-55.555550"),
    93         MapillaryURL.searchSequenceURL(new Bounds(-55.55555, -66.666666, 77.7777777, 88.88888888, false), 42)
    94     );
    95     assertEquals(
    96         new URL("https://a.mapillary.com/v2/search/s/?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz&limit=10&page=-73"),
    97         MapillaryURL.searchSequenceURL(null, -73)
     114    assertUrlEquals(
     115        MapillaryURL.searchSequenceURL(new Bounds(-55.55555, -66.666666, 77.7777777, 88.88888888, false), 42),
     116        "https://a.mapillary.com/v2/search/s/",
     117        "client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz",
     118        "min_lon=-66.666666",
     119        "max_lon=88.888889",
     120        "min_lat=-55.555550",
     121        "max_lat=77.777778",
     122        "limit=10",
     123        "page=42"
     124    );
     125    assertUrlEquals(
     126        MapillaryURL.searchSequenceURL(null, -73),
     127        "https://a.mapillary.com/v2/search/s/",
     128        "client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz",
     129        "limit=10",
     130        "page=-73"
    98131    );
    99132  }
     
    101134  @Test
    102135  public void testSearchTrafficSignURL() throws MalformedURLException {
    103     assertEquals(
    104         new URL("https://a.mapillary.com/v2/search/im/or/?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz&min_lon=2.220000&max_lat=3.333000&max_lon=4.444400&limit=20&page=-42&min_lat=1.100000"),
    105         MapillaryURL.searchTrafficSignURL(new Bounds(1.1, 2.22, 3.333, 4.4444), -42)
    106     );
    107     assertEquals(
    108         new URL("https://a.mapillary.com/v2/search/im/or/?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz&limit=20&page=73"),
    109         MapillaryURL.searchTrafficSignURL(null, 73)
     136    assertUrlEquals(
     137        MapillaryURL.searchTrafficSignURL(new Bounds(1.1, 2.22, 3.333, 4.4444), -42),
     138        "https://a.mapillary.com/v2/search/im/or/",
     139        "client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz",
     140        "min_lon=2.220000",
     141        "max_lon=4.444400",
     142        "min_lat=1.100000",
     143        "max_lat=3.333000",
     144        "limit=20",
     145        "page=-42"
     146    );
     147    assertUrlEquals(
     148        MapillaryURL.searchTrafficSignURL(null, 73),
     149        "https://a.mapillary.com/v2/search/im/or/",
     150        "client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz",
     151        "limit=20",
     152        "page=73"
    110153    );
    111154  }
     
    128171
    129172  @Test
    130   public void testString2URL() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
     173  public void testString2MalformedURL()
     174      throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    131175    Method method = MapillaryURL.class.getDeclaredMethod("string2URL", String.class);
    132176    method.setAccessible(true);
     
    138182    TestUtil.testUtilityClass(MapillaryURL.class);
    139183  }
     184
     185  private void assertUrlEquals(URL actualUrl, String expectedBaseUrl, String... expectedParams) {
     186    assertEquals(expectedBaseUrl, actualUrl.toString().substring(0, actualUrl.toString().indexOf('?')));
     187    String[] actualParams = actualUrl.getQuery().split("&");
     188    assertEquals(expectedParams.length, actualParams.length);
     189    for (int exIndex = 0; exIndex < expectedParams.length; exIndex++) {
     190      boolean parameterIsPresent = false;
     191      for (int acIndex = 0; !parameterIsPresent && acIndex < actualParams.length; acIndex++) {
     192        parameterIsPresent |= actualParams[acIndex].equals(expectedParams[exIndex]);
     193      }
     194      assertTrue(
     195          expectedParams[exIndex] + " was expected in the query string of " + actualUrl.toString() + " but wasn't there." ,
     196          parameterIsPresent
     197      );
     198    }
     199  }
    140200}
Note: See TracChangeset for help on using the changeset viewer.