Skip to content

Commit

Permalink
fix(test): JSON-LD Unit tests fail on Windows (#3670)
Browse files Browse the repository at this point in the history
Fix JSON-LD unit tests failure on Windows (#3408)

Fixes comparison of cached file names on Windows machines as described by Barium. In the unit tests for JsonLdExtension the URI is asserted against the value: "file:/tmp/foo/doc.json" but on Windows the value will include the drive name such as: "file:/C:/tmp/foo/doc.json".

The suggested solution of replacing for example
assertThat(cache).containsEntry("http://foo.org/doc.json", new URI("file:/tmp/foo/doc.json"));

with
assertThat(cache).containsEntry("http://foo.org/doc.json", new File("/tmp/foo/doc.json").toURI());

was implmeented and verified on windows machine
  • Loading branch information
rohrbachd authored Nov 30, 2023
1 parent 726f293 commit ffd513f
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
Expand Down Expand Up @@ -51,7 +52,7 @@ void verifyCachedDocsFromConfig_oneValidEntry(ServiceExtensionContext context, J
DocumentLoader documentLoader = getFieldValue("documentLoader", service);
Map<String, URI> cache = getFieldValue("uriCache", documentLoader);

assertThat(cache).containsEntry("http://foo.org/doc.json", new URI("file:/tmp/foo/doc.json"));
assertThat(cache).containsEntry("http://foo.org/doc.json", new File("/tmp/foo/doc.json").toURI());
}

@Test
Expand All @@ -67,7 +68,7 @@ void verifyCachedDocsFromConfig_oneValidEntry_withSuperfluous(ServiceExtensionCo
DocumentLoader documentLoader = getFieldValue("documentLoader", service);
Map<String, URI> cache = getFieldValue("uriCache", documentLoader);

assertThat(cache).containsEntry("http://foo.org/doc.json", new URI("file:/tmp/foo/doc.json"));
assertThat(cache).containsEntry("http://foo.org/doc.json", new File("/tmp/foo/doc.json").toURI());
}

@Test
Expand All @@ -84,8 +85,8 @@ void verifyCachedDocsFromConfig_multipleValidEntries(ServiceExtensionContext con
DocumentLoader documentLoader = getFieldValue("documentLoader", service);
Map<String, URI> cache = getFieldValue("uriCache", documentLoader);

assertThat(cache).containsEntry("http://foo.org/doc.json", new URI("file:/tmp/foo/doc.json"));
assertThat(cache).containsEntry("http://bar.org/doc.json", new URI("file:/tmp/bar/doc.json"));
assertThat(cache).containsEntry("http://foo.org/doc.json", new File("/tmp/foo/doc.json").toURI());
assertThat(cache).containsEntry("http://bar.org/doc.json", new File("/tmp/bar/doc.json").toURI());
}

@Test
Expand All @@ -101,7 +102,7 @@ void verifyCachedDocsFromConfig_multipleEntries_oneIncomplete(ServiceExtensionCo
DocumentLoader documentLoader = getFieldValue("documentLoader", service);
Map<String, URI> cache = getFieldValue("uriCache", documentLoader);

assertThat(cache).containsEntry("http://foo.org/doc.json", new URI("file:/tmp/foo/doc.json"))
assertThat(cache).containsEntry("http://foo.org/doc.json", new File("/tmp/foo/doc.json").toURI())
.noneSatisfy((s, uri) -> assertThat(s).isEqualTo("http://bar.org/doc.json"));

}
Expand All @@ -119,7 +120,7 @@ void verifyCachedDocsFromConfig_multipleEntries_oneInvalid(ServiceExtensionConte
DocumentLoader documentLoader = getFieldValue("documentLoader", service);
Map<String, URI> cache = getFieldValue("uriCache", documentLoader);

assertThat(cache).containsEntry("http://foo.org/doc.json", new URI("file:/tmp/foo/doc.json"))
assertThat(cache).containsEntry("http://foo.org/doc.json", new File("/tmp/foo/doc.json").toURI())
.noneSatisfy((s, uri) -> assertThat(s).isEqualTo("http://bar.org/doc.json"));

}
Expand Down

0 comments on commit ffd513f

Please sign in to comment.