diff --git a/bundles/org.openhab.binding.networkupstools/src/test/java/org/openhab/binding/networkupstools/internal/NutNameChannelsTest.java b/bundles/org.openhab.binding.networkupstools/src/test/java/org/openhab/binding/networkupstools/internal/NutNameChannelsTest.java index 285247256..36c39a17b 100644 --- a/bundles/org.openhab.binding.networkupstools/src/test/java/org/openhab/binding/networkupstools/internal/NutNameChannelsTest.java +++ b/bundles/org.openhab.binding.networkupstools/src/test/java/org/openhab/binding/networkupstools/internal/NutNameChannelsTest.java @@ -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 readReadme() { - final String path = getClass().getProtectionDomain().getClassLoader().getResource(".").getFile() + "../.."; - try { - final List lines = Files.readAllLines(Paths.get(path, "README.md")); + final String path = Path.of(getClass().getProtectionDomain().getClassLoader().getResource(".").toURI()) + .toString(); + final List 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 readThingsXml(final Pattern pattern, final String filename) { - final String path = getClass().getProtectionDomain().getClassLoader().getResource(".").getFile() - + "../../src/main/resources/OH-INF/thing"; try { - final List lines = Files.readAllLines(Paths.get(path, filename)); + final String path = Path.of(getClass().getProtectionDomain().getClassLoader().getResource(".").toURI()) + .toString(); + final List 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; } }