[networkupstools] Some sat improvements (#10017)

Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl>
This commit is contained in:
Hilbrand Bouwkamp
2021-02-04 07:04:50 +01:00
committed by GitHub
parent c4a3b1e6ba
commit ff9454596e
7 changed files with 25 additions and 33 deletions

View File

@@ -16,8 +16,9 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -28,7 +29,6 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Test;
import org.openhab.core.library.CoreItemFactory;
@@ -121,7 +121,7 @@ public class NutNameChannelsTest {
final String path = getClass().getProtectionDomain().getClassLoader().getResource(".").getFile() + "../..";
try {
final List<String> lines = FileUtils.readLines(new File(path, "README.md"));
final List<String> lines = Files.readAllLines(Paths.get(path, "README.md"));
return lines.stream().filter(line -> README_PATTERN.matcher(line).find())
.collect(Collectors.toMap(this::lineToNutName, Function.identity()));
@@ -135,7 +135,7 @@ public class NutNameChannelsTest {
final String path = getClass().getProtectionDomain().getClassLoader().getResource(".").getFile()
+ "../../src/main/resources/OH-INF/thing";
try {
final List<String> lines = FileUtils.readLines(new File(path, filename));
final List<String> lines = Files.readAllLines(Paths.get(path, filename));
return lines.stream().filter(line -> pattern.matcher(line).find()).map(String::trim).sorted()
.collect(Collectors.toList());
} catch (final IOException e) {

View File

@@ -18,7 +18,6 @@ import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
import org.junit.jupiter.api.Test;
/**
@@ -40,10 +39,14 @@ public class NutNameTest {
assertTrue(matcher.find(), "NutName name '" + nn + "' could not be matched with expected pattern.");
final String expectedChannelId = matcher.group(1)
+ StringUtils.capitalize(Optional.ofNullable(matcher.group(2)).orElse(""))
+ StringUtils.capitalize(Optional.ofNullable(matcher.group(3)).orElse(""))
+ StringUtils.capitalize(Optional.ofNullable(matcher.group(4)).orElse(""));
+ capitalize(Optional.ofNullable(matcher.group(2)).orElse(""))
+ capitalize(Optional.ofNullable(matcher.group(3)).orElse(""))
+ capitalize(Optional.ofNullable(matcher.group(4)).orElse(""));
assertEquals(expectedChannelId, nn.getChannelId(), "Channel name not correct");
}
}
private String capitalize(String s) {
return s.isEmpty() ? "" : Character.toUpperCase(s.charAt(0)) + s.substring(1);
}
}