Skip to content

Commit

Permalink
Various small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
floscher committed Jun 22, 2017
1 parent b5807cd commit 2d97ef4
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 37 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -26,7 +26,7 @@ version = getVersionName()

repositories {
// for JUnit
mavenCentral()
jcenter()
//for josm-(latest|tested).jar
ivy {
url 'https://josm.openstreetmap.de/download'
Expand Down
Expand Up @@ -51,6 +51,7 @@ public final class MapillaryMainDialog extends ToggleDialog implements
private static final long serialVersionUID = 6856496736429480600L;

private static final String BASE_TITLE = marktr("Mapillary picture");
private static final String MESSAGE_SEPARATOR = " — ";

private static MapillaryMainDialog instance;

Expand Down Expand Up @@ -305,16 +306,16 @@ public synchronized void updateTitle() {
MapillaryImage mapillaryImage = (MapillaryImage) this.image;
UserProfile user = mapillaryImage.getUser();
if (user != null) {
title.append(" — ").append(user.getUsername());
title.append(MESSAGE_SEPARATOR).append(user.getUsername());
}
if (mapillaryImage.getCapturedAt() != 0) {
title.append(" — ").append(mapillaryImage.getDate());
title.append(MESSAGE_SEPARATOR).append(mapillaryImage.getDate());
}
setTitle(title.toString());
} else if (this.image instanceof MapillaryImportedImage) {
MapillaryImportedImage mapillaryImportedImage = (MapillaryImportedImage) this.image;
title.append(" — ").append(mapillaryImportedImage.getFile().getName());
title.append(" — ").append(mapillaryImportedImage.getDate());
title.append(MESSAGE_SEPARATOR).append(mapillaryImportedImage.getFile().getName());
title.append(MESSAGE_SEPARATOR).append(mapillaryImportedImage.getDate());
setTitle(title.toString());
}
}
Expand Down
@@ -1,8 +1,6 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapillary.utils;

import static org.openstreetmap.josm.tools.I18n.tr;

import java.awt.Desktop;
import java.io.IOException;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -267,16 +265,16 @@ public static synchronized void unjoin(MapillaryAbstractImage imgA, MapillaryAbs
public static void updateHelpText() {
StringBuilder ret = new StringBuilder();
if (PluginState.isDownloading()) {
ret.append(tr("Downloading Mapillary images"));
ret.append(I18n.tr("Downloading Mapillary images"));
} else if (MapillaryLayer.getInstance().getData().getImages().size() > 0) {
ret.append(I18n.tr("Total Mapillary images: {0}", MapillaryLayer.getInstance().getToolTipText()));
} else if (PluginState.isSubmittingChangeset()) {
ret.append(tr("Submitting Mapillary Changeset"));
ret.append(I18n.tr("Submitting Mapillary Changeset"));
} else {
ret.append(tr("No images found"));
ret.append(I18n.tr("No images found"));
}
if (MapillaryLayer.getInstance().mode != null) {
ret.append(" — ").append(tr(MapillaryLayer.getInstance().mode.toString()));
ret.append(" — ").append(I18n.tr(MapillaryLayer.getInstance().mode.toString()));
}
if (PluginState.isUploading()) {
ret.append(" — ").append(PluginState.getUploadString());
Expand Down
Expand Up @@ -16,7 +16,7 @@
import org.openstreetmap.josm.gui.layer.Layer;

public class MapillaryLayerTest extends AbstractTest {
private Layer dummyLayer = ImageryLayer.create(new ImageryInfo("dummy", "https://example.org"));
private final Layer dummyLayer = ImageryLayer.create(new ImageryInfo("dummy", "https://example.org"));

@Test
public void testGetIcon() {
Expand Down
Expand Up @@ -2,6 +2,8 @@
package org.openstreetmap.josm.plugins.mapillary;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.Arrays;
Expand All @@ -19,24 +21,19 @@
*/
public class MapillarySequenceTest {

private MapillaryImage img1;
private MapillaryImage img2;
private MapillaryImage img3;
private MapillaryImage img4;
private MapillarySequence seq;
private final MapillaryImage img1 = new MapillaryImage("key1", new LatLon(0.1, 0.1), 90);
private final MapillaryImage img2 = new MapillaryImage("key2", new LatLon(0.2, 0.2), 90);
private final MapillaryImage img3 = new MapillaryImage("key3", new LatLon(0.3, 0.3), 90);
private final MapillaryImage img4 = new MapillaryImage("key4", new LatLon(0.4, 0.4), 90);
private final MapillaryImage imgWithoutSeq = new MapillaryImage("key5", new LatLon(0.5, 0.5), 90);
private final MapillarySequence seq = new MapillarySequence();

/**
* Creates 4 {@link MapillaryImage} objects and puts them in a
* {@link MapillarySequence} object.
*/
@Before
public void setUp() {
img1 = new MapillaryImage("key1__________________", new LatLon(0.1, 0.1), 90);
img2 = new MapillaryImage("key2__________________", new LatLon(0.2, 0.2), 90);
img3 = new MapillaryImage("key3__________________", new LatLon(0.3, 0.3), 90);
img4 = new MapillaryImage("key4__________________", new LatLon(0.4, 0.4), 90);
seq = new MapillarySequence();

seq.add(Arrays.asList(new MapillaryAbstractImage[] { img1, img2, img3, img4 }));
}

Expand All @@ -46,30 +43,35 @@ public void setUp() {
*/
@Test
public void nextAndPreviousTest() {
assertEquals(this.img2, this.img1.next());
assertEquals(this.img2, this.seq.next(this.img1));
assertEquals(img2, img1.next());
assertEquals(img1, img2.previous());
assertEquals(img3, img2.next());
assertEquals(img2, img3.previous());
assertEquals(img4, img3.next());
assertEquals(img3, img4.previous());


assertEquals(this.img1, this.img2.previous());
assertEquals(this.img1, this.seq.previous(this.img2));
assertNull(img4.next());
assertNull(img1.previous());

assertEquals(null, this.img4.next());
assertEquals(null, this.seq.next(this.img4));
assertEquals(null, this.img1.previous());
assertEquals(null, this.seq.previous(this.img1));
assertNull(imgWithoutSeq.next());
assertNull(imgWithoutSeq.previous());

// Test IllegalArgumentException when asking for the next image of an image
// that is not in the sequence.
try {
this.seq.next(new MapillaryImage("key5__________________", new LatLon(0.5, 0.5), 90));
seq.next(imgWithoutSeq);
fail();
} catch (IllegalArgumentException e) {
assertTrue(true);
}
// Test IllegalArgumentException when asking for the previous image of an
// image that is not in the sequence.
try {
this.seq.previous(new MapillaryImage("key5", new LatLon(0.5, 0.5), 90));
seq.previous(imgWithoutSeq);
fail();
} catch (IllegalArgumentException e) {
assertTrue(true);
}
}
}
Expand Up @@ -6,7 +6,11 @@
import javax.json.Json;
import javax.json.JsonObject;

public class JsonUtil {
public final class JsonUtil {
private JsonUtil() {
// Private constructor to avoid instantiation
}

public static JsonObject string2jsonObject(String s) {
return Json.createReader(new ByteArrayInputStream(s.getBytes())).readObject();
}
Expand Down
Expand Up @@ -58,7 +58,7 @@ private static InputStream getJsonInputStream(final String path) throws IOExcept
}

@Test
public void testDecodeUserProfile() throws IOException, URISyntaxException, IllegalArgumentException, IllegalAccessException {
public void testDecodeUserProfile() throws IOException, URISyntaxException, IllegalArgumentException {
UserProfile profile = JsonUserProfileDecoder.decodeUserProfile(Json.createReader(getJsonInputStream("/api/v3/responses/userProfile.json")).readObject());
assertEquals("2BJl04nvnfW1y2GNaj7x5w", profile.getKey());
assertEquals("gyllen", profile.getUsername());
Expand All @@ -67,15 +67,15 @@ public void testDecodeUserProfile() throws IOException, URISyntaxException, Ille
}

@Test
public void testDecodeUserProfile2() throws IOException, URISyntaxException, IllegalArgumentException, IllegalAccessException {
public void testDecodeUserProfile2() throws IOException, URISyntaxException, IllegalArgumentException {
UserProfile profile = JsonUserProfileDecoder.decodeUserProfile(Json.createReader(getJsonInputStream("/api/v3/responses/userProfile2.json")).readObject());
assertEquals("abcdefg1", profile.getKey());
assertEquals("mapillary_userÄ2!", profile.getUsername());
assertTrue(FAKE_AVATAR == profile.getAvatar());
}

@Test
public void testDecodeInvalidUserProfile() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
public void testDecodeInvalidUserProfile() throws IllegalArgumentException, SecurityException {
assertNull(JsonUserProfileDecoder.decodeUserProfile(null));
assertNull(JsonUserProfileDecoder.decodeUserProfile(JsonUtil.string2jsonObject("{}")));
assertNull(JsonUserProfileDecoder.decodeUserProfile(JsonUtil.string2jsonObject("{\"key\":\"arbitrary_key\"}")));
Expand Down

0 comments on commit 2d97ef4

Please sign in to comment.