[networkupstools] fix tests (#10082)

Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
This commit is contained in:
J-N-K 2021-02-07 13:44:47 +01:00 committed by GitHub
parent 1210fec9f9
commit 97298e55a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View 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;
}
}