You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Marcono1234 (via GitHub)" <gi...@apache.org> on 2023/07/23 15:54:05 UTC

[GitHub] [commons-imaging] Marcono1234 opened a new pull request, #306: [IMAGING-359] Fix test resource file paths not being constructed properly

Marcono1234 opened a new pull request, #306:
URL: https://github.com/apache/commons-imaging/pull/306

   Using `URL.getFile()` is faulty because its result is URL encoded. This caused test failures when running in a directory with spaces in its file path.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-imaging] Marcono1234 commented on a diff in pull request #306: [IMAGING-359] Fix test resource file paths not being constructed properly

Posted by "Marcono1234 (via GitHub)" <gi...@apache.org>.
Marcono1234 commented on code in PR #306:
URL: https://github.com/apache/commons-imaging/pull/306#discussion_r1271482842


##########
src/test/java/org/apache/commons/imaging/test/TestResources.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.imaging.test;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * Helper class which provides convenience methods for accessing test resources.
+ */
+public class TestResources {
+    private TestResources() {
+    }
+
+    private static URI resourceUri(String path) {
+        URL url = TestResources.class.getResource(path);
+        if (url == null) {
+            throw new IllegalArgumentException("Resource does not exist: " + path);
+        }
+        try {
+            return url.toURI();
+        } catch (URISyntaxException e) {
+            throw new IllegalArgumentException(e);
+        }
+    }
+
+    /**
+     * Gets a {@link File} for a {@linkplain Class#getResource(String) resource path}.
+     */
+    public static File fileResource(String path) {
+        return new File(resourceUri(path));
+    }
+
+    /**
+     * Gets a {@link Path} for a {@linkplain Class#getResource(String) resource path}.
+     */
+    public static Path pathResource(String path) {

Review Comment:
   I am not completely sure about those names; at least `fileResource` sounds a bit like it also verifies the resource is an existing file (and not a directory), which it doesn't.
   
   Maybe `resourceFile` and `resourcePath` would be better (or some other name)? What do you think?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-imaging] garydgregory commented on a diff in pull request #306: [IMAGING-359] Fix test resource file paths not being constructed properly

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #306:
URL: https://github.com/apache/commons-imaging/pull/306#discussion_r1274773071


##########
src/test/java/org/apache/commons/imaging/formats/bmp/BmpImageParserTest.java:
##########
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.imaging.formats.bmp;
 
+import static org.apache.commons.imaging.test.TestResources.fileResource;

Review Comment:
   I think we should only use static imports for JUnit.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-imaging] Marcono1234 commented on pull request #306: [IMAGING-359] Fix test resource file paths not being constructed properly

Posted by "Marcono1234 (via GitHub)" <gi...@apache.org>.
Marcono1234 commented on PR #306:
URL: https://github.com/apache/commons-imaging/pull/306#issuecomment-1646876210

   I meant caused test failures _previously_. Simply clone the current state of `master` into a directory with spaces in its name and try to run the tests; you will see a lot of `NoSuchFileException`s being thrown, with the file path containing the space encoded as `%20`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-imaging] garydgregory merged pull request #306: [IMAGING-359] Fix test resource file paths not being constructed properly

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory merged PR #306:
URL: https://github.com/apache/commons-imaging/pull/306


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-imaging] Marcono1234 commented on a diff in pull request #306: [IMAGING-359] Fix test resource file paths not being constructed properly

Posted by "Marcono1234 (via GitHub)" <gi...@apache.org>.
Marcono1234 commented on code in PR #306:
URL: https://github.com/apache/commons-imaging/pull/306#discussion_r1278314111


##########
src/test/java/org/apache/commons/imaging/formats/bmp/BmpImageParserTest.java:
##########
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.imaging.formats.bmp;
 
+import static org.apache.commons.imaging.test.TestResources.fileResource;

Review Comment:
   Have changed it to regular imports



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-imaging] garydgregory commented on pull request #306: [IMAGING-359] Fix test resource file paths not being constructed properly

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #306:
URL: https://github.com/apache/commons-imaging/pull/306#issuecomment-1656807844

   https://issues.apache.org/jira/browse/IMAGING-359


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-imaging] codecov-commenter commented on pull request #306: [IMAGING-359] Fix test resource file paths not being constructed properly

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #306:
URL: https://github.com/apache/commons-imaging/pull/306#issuecomment-1656788878

   ## [Codecov](https://app.codecov.io/gh/apache/commons-imaging/pull/306?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   > Merging [#306](https://app.codecov.io/gh/apache/commons-imaging/pull/306?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (7925ec8) into [master](https://app.codecov.io/gh/apache/commons-imaging/commit/80fbe7dfb1353f7a42e8ac8ddbadb8fd552af3d5?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (80fbe7d) will **not change** coverage.
   > Report is 5 commits behind head on master.
   > The diff coverage is `n/a`.
   
   ```diff
   @@            Coverage Diff            @@
   ##             master     #306   +/-   ##
   =========================================
     Coverage     70.82%   70.82%           
     Complexity     3405     3405           
   =========================================
     Files           333      333           
     Lines         16834    16834           
     Branches       2588     2588           
   =========================================
     Hits          11922    11922           
     Misses         3897     3897           
     Partials       1015     1015           
   ```
   
   
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-imaging] garydgregory commented on pull request #306: [IMAGING-359] Fix test resource file paths not being constructed properly

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #306:
URL: https://github.com/apache/commons-imaging/pull/306#issuecomment-1646875731

   Where are the test failures? The builds are all green here.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-imaging] Marcono1234 commented on a diff in pull request #306: [IMAGING-359] Fix test resource file paths not being constructed properly

Posted by "Marcono1234 (via GitHub)" <gi...@apache.org>.
Marcono1234 commented on code in PR #306:
URL: https://github.com/apache/commons-imaging/pull/306#discussion_r1271482842


##########
src/test/java/org/apache/commons/imaging/test/TestResources.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.imaging.test;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * Helper class which provides convenience methods for accessing test resources.
+ */
+public class TestResources {
+    private TestResources() {
+    }
+
+    private static URI resourceUri(String path) {
+        URL url = TestResources.class.getResource(path);
+        if (url == null) {
+            throw new IllegalArgumentException("Resource does not exist: " + path);
+        }
+        try {
+            return url.toURI();
+        } catch (URISyntaxException e) {
+            throw new IllegalArgumentException(e);
+        }
+    }
+
+    /**
+     * Gets a {@link File} for a {@linkplain Class#getResource(String) resource path}.
+     */
+    public static File fileResource(String path) {
+        return new File(resourceUri(path));
+    }
+
+    /**
+     * Gets a {@link Path} for a {@linkplain Class#getResource(String) resource path}.
+     */
+    public static Path pathResource(String path) {

Review Comment:
   I am not completely sure about those names; at least `fileResource` sounds a bit like it also verifies that the resource is an existing file (and not a directory), which it doesn't.
   
   Maybe `resourceFile` and `resourcePath` would be better (or some other name)? What do you think?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org