]> git.basschouten.com Git - openhab-addons.git/commitdiff
[networkupstools] fix tests (#10082)
authorJ-N-K <J-N-K@users.noreply.github.com>
Sun, 7 Feb 2021 12:44:47 +0000 (13:44 +0100)
committerGitHub <noreply@github.com>
Sun, 7 Feb 2021 12:44:47 +0000 (13:44 +0100)
Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
bundles/org.openhab.binding.networkupstools/src/test/java/org/openhab/binding/networkupstools/internal/NutNameChannelsTest.java

index 285247256063858e15b1d9aace15dbc779fc03a8..36c39a17bba1eb1999816c167de869b4b9b04dd5 100644 (file)
@@ -17,8 +17,9 @@ import static org.hamcrest.Matchers.is;
 import static org.junit.jupiter.api.Assertions.*;
 
 import java.io.IOException;
+import java.net.URISyntaxException;
 import java.nio.file.Files;
-import java.nio.file.Paths;
+import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -118,28 +119,29 @@ public class NutNameChannelsTest {
     }
 
     private Map<NutName, String> readReadme() {
-        final String path = getClass().getProtectionDomain().getClassLoader().getResource(".").getFile() + "../..";
-
         try {
-            final List<String> lines = Files.readAllLines(Paths.get(path, "README.md"));
+            final String path = Path.of(getClass().getProtectionDomain().getClassLoader().getResource(".").toURI())
+                    .toString();
+            final List<String> lines = Files.readAllLines(Path.of(path, "..", "..", "README.md"));
 
             return lines.stream().filter(line -> README_PATTERN.matcher(line).find())
                     .collect(Collectors.toMap(this::lineToNutName, Function.identity()));
-        } catch (final IOException e) {
-            fail("Could not read README.md from: " + path);
+        } catch (final IOException | URISyntaxException e) {
+            fail("Could not read README.md");
             return null;
         }
     }
 
     private List<String> readThingsXml(final Pattern pattern, final String filename) {
-        final String path = getClass().getProtectionDomain().getClassLoader().getResource(".").getFile()
-                + "../../src/main/resources/OH-INF/thing";
         try {
-            final List<String> lines = Files.readAllLines(Paths.get(path, filename));
+            final String path = Path.of(getClass().getProtectionDomain().getClassLoader().getResource(".").toURI())
+                    .toString();
+            final List<String> lines = Files
+                    .readAllLines(Path.of(path, "..", "..", "src", "main", "resources", "OH-INF", "thing", filename));
             return lines.stream().filter(line -> pattern.matcher(line).find()).map(String::trim).sorted()
                     .collect(Collectors.toList());
-        } catch (final IOException e) {
-            fail("Could not read things xml from: " + path);
+        } catch (final IOException | URISyntaxException e) {
+            fail("Could not read things xml");
             return null;
         }
     }