Skip to content

Commit

Permalink
fixing test and adding comments
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianKirmaier committed Dec 9, 2024
1 parent 98480e1 commit 16e3921
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public JSONObject toJSON() {
try {
URL resourceUrl = getClass().getResource(resourcePath);
if (resourceUrl != null) {
// we don't access any stream here, so we don't need to close it
URLConnection conn = resourceUrl.openConnection();
json.put("modified", conn.getLastModified());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public void testToJson() {
JSONObject json = new JSONObject();
json.put("type", "ImageSourceFile");
json.put("path", ImageUtils.escapeJson(testImageFile.getAbsolutePath()));
json.put("modified", testImageFile.lastModified());

assertTrue(imageSource.toJSON().similar(json));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.junit.jupiter.api.Test;

import java.awt.image.BufferedImage;
import java.net.URL;
import java.net.URLConnection;

import static org.junit.jupiter.api.Assertions.*;

Expand All @@ -30,12 +32,18 @@ void testIdentityHashValue_validResourcePath_returnsHash() {
}

@Test
void testToJson_returnsExpectedJson() {
void testToJson_returnsExpectedJson() throws Exception {
ImageSourceResource resource = new ImageSourceResource("/testImage.png");

JSONObject json = new JSONObject();
json.put("type", "ImageSourceResource");
json.put("resourcePath", "/testImage.png");
URL resourceUrl = getClass().getResource("/testImage.png");
if (resourceUrl != null) {
// we don't access any stream here, so we don't need to close it
URLConnection conn = resourceUrl.openConnection();
json.put("modified", conn.getLastModified());
}
assertTrue(resource.toJSON().similar(json));
}
}

0 comments on commit 16e3921

Please sign in to comment.