Skip to content

Commit

Permalink
Fix test failures
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <[email protected]>
  • Loading branch information
tsmock committed Apr 18, 2024
1 parent cc2193b commit d2ca6b2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 34 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ plugin.icon=images/mapillary-logo.svg
plugin.link=https://wiki.openstreetmap.org/wiki/JOSM/Plugins/Mapillary
# Minimum required JOSM version to run this plugin, choose the lowest version possible that is compatible.
# You can check if the plugin compiles against this version by executing `./gradlew compileJava_minJosm`.
plugin.main.version=18877
plugin.main.version=18940
# Version of JOSM against which the plugin is compiled
# Please check, if the specified version is available for download from https://josm.openstreetmap.de/download/ .
# If not, choose the next higher number that is available, or the gradle build will break.
plugin.compile.version=18877
plugin.compile.version=18940
# The datepicker plugin is currently in the source tree. TODO fix
plugin.requires=apache-commons

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
import org.openstreetmap.josm.plugins.mapillary.data.mapillary.ObjectDetections;
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
import org.openstreetmap.josm.testutils.annotations.HTTP;
import org.openstreetmap.josm.testutils.annotations.Projection;
import org.openstreetmap.josm.testutils.annotations.TaggingPresets;

/**
* Annotation for ObjectDetections (ensures they have the appropriate presets)
*
* @author Taylor Smock
*/
@Documented
@HTTP
@ExtendWith(ObjectDetectionsAnnotation.ObjectDetectionsExtension.class)
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@BasicPreferences
@HTTP
@Projection
@TaggingPresets
@ExtendWith(ObjectDetectionsAnnotation.ObjectDetectionsExtension.class)
public @interface ObjectDetectionsAnnotation {
class ObjectDetectionsExtension implements AfterAllCallback, BeforeAllCallback {

Expand All @@ -37,10 +40,6 @@ public void afterAll(ExtensionContext context) {

@Override
public void beforeAll(ExtensionContext context) {
// TODO replace with @Presets dependency
if (TaggingPresets.getTaggingPresets().isEmpty()) {
TaggingPresets.readFromPreferences();
}
ObjectDetections.updatePresets();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,35 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;

import org.junit.jupiter.api.Test;
import org.openstreetmap.josm.TestUtils;

class ImageMetaDataUtilTest {
@Test
void testXmpXmlParse() throws IOException, URISyntaxException {
boolean pano = ImageMetaDataUtil.checkXmpProjectionType(new String(
Files.readAllBytes(
Paths.get(ImageMetaDataUtil.class.getResource("/xmpTestImages/xmpProjectionOnly.xml").toURI())),
StandardCharsets.UTF_8), "equirectangular");
void testXmpXmlParse() throws IOException {
boolean pano = ImageMetaDataUtil.checkXmpProjectionType(
Files.readString(Paths.get(TestUtils.getTestDataRoot(), "xmpTestImages", "xmpProjectionOnly.xml")),
"equirectangular");
assertTrue(pano);
}

@Test
void testImageFileXMP() throws URISyntaxException {
final File xmpImageFile = new File(
ImageMetaDataUtil.class.getResource("/xmpTestImages/xmpProjectionOnly.jpg").toURI());
void testImageFileXMP() {
final File xmpImageFile = Paths.get(TestUtils.getTestDataRoot(), "xmpTestImages", "xmpProjectionOnly.jpg")
.toFile();
boolean pano = ImageMetaDataUtil.isPanorama(xmpImageFile);
assertTrue(pano);
}

@Test
void testImageStreamingXMP() throws URISyntaxException, IOException {
try (FileInputStream xmpImageStream = new FileInputStream(
new File(ImageMetaDataUtil.class.getResource("/xmpTestImages/xmpProjectionOnly.jpg").toURI()))) {
void testImageStreamingXMP() throws IOException {
try (InputStream xmpImageStream = Files
.newInputStream(Paths.get(TestUtils.getTestDataRoot(), "xmpTestImages", "xmpProjectionOnly.jpg"))) {
boolean pano = ImageMetaDataUtil.isPanorama(xmpImageStream);
assertTrue(pano);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

import jakarta.json.Json;
import jakarta.json.JsonReader;
import org.junit.jupiter.api.Test;
import org.openstreetmap.josm.TestUtils;
import org.openstreetmap.josm.plugins.mapillary.model.UserProfile;
import org.openstreetmap.josm.plugins.mapillary.utils.JsonUtil;
import org.openstreetmap.josm.plugins.mapillary.utils.TestUtil;
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;

import jakarta.json.Json;
import jakarta.json.JsonReader;

@BasicPreferences
class JsonUserProfileDecoderTest {
private static Object getFakeAvatar() {
Expand All @@ -34,14 +33,14 @@ void testUtilityClass() {
TestUtil.testUtilityClass(JsonUserProfileDecoder.class);
}

private static InputStream getJsonInputStream(final String path) throws IOException, URISyntaxException {
String fileContent = String.join("\n", Files.readAllLines(
Paths.get(JsonUserProfileDecoderTest.class.getResource(path).toURI()), StandardCharsets.UTF_8));
private static InputStream getJsonInputStream(final String path) throws IOException {
String fileContent = String.join("\n",
Files.readAllLines(Paths.get(TestUtils.getTestDataRoot(), path), StandardCharsets.UTF_8));
return new ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8));
}

@Test
void testDecodeUserProfile() throws IOException, URISyntaxException, IllegalArgumentException {
void testDecodeUserProfile() throws IOException, IllegalArgumentException {
try (InputStream inputStream = getJsonInputStream("/__files/api/v4/responses/graph/104214208486349.json");
JsonReader reader = Json.createReader(inputStream)) {
UserProfile profile = JsonUserProfileDecoder.decodeUserProfile(reader.readObject());
Expand All @@ -52,7 +51,7 @@ void testDecodeUserProfile() throws IOException, URISyntaxException, IllegalArgu
}

@Test
void testDecodeUserProfile2() throws IOException, URISyntaxException, IllegalArgumentException {
void testDecodeUserProfile2() throws IOException, IllegalArgumentException {
try (InputStream inputStream = getJsonInputStream("/__files/api/v4/responses/graph/104214208486350.json");
JsonReader reader = Json.createReader(inputStream)) {
UserProfile profile = JsonUserProfileDecoder.decodeUserProfile(reader.readObject());
Expand All @@ -69,8 +68,8 @@ void testDecodeInvalidUserProfile() throws IllegalArgumentException, SecurityExc
assertNull(JsonUserProfileDecoder.decodeUserProfile(JsonUtil.string2jsonObject("{}")));
assertNull(JsonUserProfileDecoder.decodeUserProfile(JsonUtil.string2jsonObject("{\"key\":\"arbitrary_key\"}")));

UserProfile profile = JsonUserProfileDecoder.decodeUserProfile(
JsonUtil.string2jsonObject("{\"id\":\"-1\", \"username\":\"arbitrary_username\"}"));
UserProfile profile = JsonUserProfileDecoder
.decodeUserProfile(JsonUtil.string2jsonObject("{\"id\":\"-1\", \"username\":\"arbitrary_username\"}"));
assertNotNull(profile);
assertSame(getFakeAvatar(), profile.avatar());

Expand Down

0 comments on commit d2ca6b2

Please sign in to comment.