[nanoleaf] Fix LayoutTest failing on Windows (#12563)
On Windows the view has different line endings causing some tests to fail. For readability the big strings have also been moved into files. Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
parent
5712de5e63
commit
0f56369b2a
|
@ -15,9 +15,13 @@ package org.openhab.binding.nanoleaf.internal;
|
|||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openhab.binding.nanoleaf.internal.model.Layout;
|
||||
import org.openhab.binding.nanoleaf.internal.model.Write;
|
||||
|
@ -34,74 +38,26 @@ import com.google.gson.Gson;
|
|||
public class LayoutTest {
|
||||
|
||||
private final Gson gson = new Gson();
|
||||
String layout1Json = "";
|
||||
String layoutInconsistentPanelNoJson = "";
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
layout1Json = "{\n" + " \"numPanels\": 14,\n" + " \"sideLength\": 0,\n"
|
||||
+ " \"positionData\": [\n" + " {\n" + " \"panelId\": 60147,\n"
|
||||
+ " \"x\": 199,\n" + " \"y\": 99,\n" + " \"o\": 0,\n"
|
||||
+ " \"shapeType\": 3\n" + " },\n" + " {\n" + " \"panelId\": 61141,\n"
|
||||
+ " \"x\": 200,\n" + " \"y\": 199,\n" + " \"o\": 90,\n"
|
||||
+ " \"shapeType\": 2\n" + " },\n" + " {\n" + " \"panelId\": 42064,\n"
|
||||
+ " \"x\": 100,\n" + " \"y\": 200,\n" + " \"o\": 180,\n"
|
||||
+ " \"shapeType\": 2\n" + " },\n" + " {\n" + " \"panelId\": 186,\n"
|
||||
+ " \"x\": 0,\n" + " \"y\": 200,\n" + " \"o\": 180,\n"
|
||||
+ " \"shapeType\": 2\n" + " },\n" + " {\n" + " \"panelId\": 19209,\n"
|
||||
+ " \"x\": 0,\n" + " \"y\": 100,\n" + " \"o\": 270,\n"
|
||||
+ " \"shapeType\": 2\n" + " },\n" + " {\n" + " \"panelId\": 36604,\n"
|
||||
+ " \"x\": 300,\n" + " \"y\": 99,\n" + " \"o\": 0,\n"
|
||||
+ " \"shapeType\": 2\n" + " },\n" + " {\n" + " \"panelId\": 37121,\n"
|
||||
+ " \"x\": 400,\n" + " \"y\": 99,\n" + " \"o\": 270,\n"
|
||||
+ " \"shapeType\": 2\n" + " },\n" + " {\n" + " \"panelId\": 45187,\n"
|
||||
+ " \"x\": 400,\n" + " \"y\": 199,\n" + " \"o\": 270,\n"
|
||||
+ " \"shapeType\": 2\n" + " },\n" + " {\n" + " \"panelId\": 33626,\n"
|
||||
+ " \"x\": 500,\n" + " \"y\": 199,\n" + " \"o\": 270,\n"
|
||||
+ " \"shapeType\": 2\n" + " },\n" + " {\n" + " \"panelId\": 10523,\n"
|
||||
+ " \"x\": 600,\n" + " \"y\": 199,\n" + " \"o\": 270,\n"
|
||||
+ " \"shapeType\": 2\n" + " },\n" + " {\n" + " \"panelId\": 54086,\n"
|
||||
+ " \"x\": 599,\n" + " \"y\": 99,\n" + " \"o\": 540,\n"
|
||||
+ " \"shapeType\": 2\n" + " },\n" + " {\n" + " \"panelId\": 3512,\n"
|
||||
+ " \"x\": 699,\n" + " \"y\": 99,\n" + " \"o\": 540,\n"
|
||||
+ " \"shapeType\": 2\n" + " },\n" + " {\n" + " \"panelId\": 16398,\n"
|
||||
+ " \"x\": 799,\n" + " \"y\": 99,\n" + " \"o\": 540,\n"
|
||||
+ " \"shapeType\": 2\n" + " },\n" + " {\n" + " \"panelId\": 39163,\n"
|
||||
+ " \"x\": 800,\n" + " \"y\": 199,\n" + " \"o\": 630,\n"
|
||||
+ " \"shapeType\": 2\n" + " }\n" + " ]\n" + " }";
|
||||
layoutInconsistentPanelNoJson = "{\"numPanels\":15,\"sideLength\":100,\"positionData\":[{\"panelId\":41451,\"x\":350,\"y\":0,\"o\":0,\"shapeType\":3},{\"panelId\":8134,\"x\":350,\"y\":150,\"o\":0,\"shapeType\":2},{\"panelId\":58086,\"x\":200,\"y\":100,\"o\":270,\"shapeType\":2},{\"panelId\":38724,\"x\":300,\"y\":200,\"o\":0,\"shapeType\":2},{\"panelId\":48111,\"x\":200,\"y\":200,\"o\":270,\"shapeType\":2},{\"panelId\":56093,\"x\":100,\"y\":200,\"o\":0,\"shapeType\":2},{\"panelId\":55836,\"x\":0,\"y\":200,\"o\":0,\"shapeType\":2},{\"panelId\":31413,\"x\":100,\"y\":300,\"o\":90,\"shapeType\":2},{\"panelId\":9162,\"x\":300,\"y\":300,\"o\":90,\"shapeType\":2},{\"panelId\":13276,\"x\":400,\"y\":300,\"o\":90,\"shapeType\":2},{\"panelId\":17870,\"x\":400,\"y\":200,\"o\":0,\"shapeType\":2},{\"panelId\":5164,\"x\":500,\"y\":200,\"o\":0,\"shapeType\":2},{\"panelId\":64279,\"x\":600,\"y\":200,\"o\":0,\"shapeType\":2},{\"panelId\":39755,\"x\":500,\"y\":100,\"o\":90,\"shapeType\":2}]}";
|
||||
private void assertLayoutFromJson(Path jsonFile, Path viewFile) throws IOException {
|
||||
String json = Files.readString(jsonFile);
|
||||
Layout layout = Objects.requireNonNull(gson.fromJson(json, Layout.class));
|
||||
|
||||
String expectedView = Files.readAllLines(viewFile).stream().collect(Collectors.joining(System.lineSeparator()));
|
||||
|
||||
assertThat(layout.getLayoutView(), is(equalTo(expectedView)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTheRightLayoutView() {
|
||||
@Nullable
|
||||
Layout layout = gson.fromJson(layout1Json, Layout.class);
|
||||
if (layout == null) {
|
||||
layout = new Layout();
|
||||
}
|
||||
String layoutView = layout.getLayoutView();
|
||||
assertThat(layoutView, is(equalTo(
|
||||
" 186 42064 61141 45187 33626 10523 39163 \n"
|
||||
+ " \n"
|
||||
+ "19209 60147 36604 37121 54086 3512 16398 \n")));
|
||||
public void testTheRightLayoutView() throws IOException {
|
||||
assertLayoutFromJson(Path.of("src/test/resources/right-layout.json"),
|
||||
Path.of("src/test/resources/right-layout-view"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTheInconsistentLayoutView() {
|
||||
@Nullable
|
||||
Layout layout = gson.fromJson(layoutInconsistentPanelNoJson, Layout.class);
|
||||
if (layout == null) {
|
||||
layout = new Layout();
|
||||
}
|
||||
String layoutView = layout.getLayoutView();
|
||||
assertThat(layoutView,
|
||||
is(equalTo(" 31413 9162 13276 \n"
|
||||
+ " \n"
|
||||
+ "55836 56093 48111 38724 17870 5164 64279 \n"
|
||||
+ " 8134 \n"
|
||||
+ " 58086 39755 \n"
|
||||
+ " \n"
|
||||
+ " 41451 \n")));
|
||||
public void testTheInconsistentLayoutView() throws IOException {
|
||||
assertLayoutFromJson(Path.of("src/test/resources/inconsistent-layout.json"),
|
||||
Path.of("src/test/resources/inconsistent-layout-view"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -111,8 +67,8 @@ public class LayoutTest {
|
|||
write.setAnimType("static");
|
||||
write.setLoop(false);
|
||||
int panelID = 123;
|
||||
int quotient = Integer.divideUnsigned(Integer.valueOf(panelID), 256);
|
||||
int remainder = Integer.remainderUnsigned(Integer.valueOf(panelID), 256);
|
||||
int quotient = Integer.divideUnsigned(panelID, 256);
|
||||
int remainder = Integer.remainderUnsigned(panelID, 256);
|
||||
write.setAnimData(String.format("0 1 %d %d %d %d %d 0 0 10", quotient, remainder, 20, 40, 60));
|
||||
String content = gson.toJson(write);
|
||||
assertThat(content, containsStringIgnoringCase("palette"));
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
31413 9162 13276
|
||||
|
||||
55836 56093 48111 38724 17870 5164 64279
|
||||
8134
|
||||
58086 39755
|
||||
|
||||
41451
|
||||
|
|
@ -0,0 +1 @@
|
|||
{"numPanels":15,"sideLength":100,"positionData":[{"panelId":41451,"x":350,"y":0,"o":0,"shapeType":3},{"panelId":8134,"x":350,"y":150,"o":0,"shapeType":2},{"panelId":58086,"x":200,"y":100,"o":270,"shapeType":2},{"panelId":38724,"x":300,"y":200,"o":0,"shapeType":2},{"panelId":48111,"x":200,"y":200,"o":270,"shapeType":2},{"panelId":56093,"x":100,"y":200,"o":0,"shapeType":2},{"panelId":55836,"x":0,"y":200,"o":0,"shapeType":2},{"panelId":31413,"x":100,"y":300,"o":90,"shapeType":2},{"panelId":9162,"x":300,"y":300,"o":90,"shapeType":2},{"panelId":13276,"x":400,"y":300,"o":90,"shapeType":2},{"panelId":17870,"x":400,"y":200,"o":0,"shapeType":2},{"panelId":5164,"x":500,"y":200,"o":0,"shapeType":2},{"panelId":64279,"x":600,"y":200,"o":0,"shapeType":2},{"panelId":39755,"x":500,"y":100,"o":90,"shapeType":2}]}
|
|
@ -0,0 +1,4 @@
|
|||
186 42064 61141 45187 33626 10523 39163
|
||||
|
||||
19209 60147 36604 37121 54086 3512 16398
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
{
|
||||
"numPanels":14,
|
||||
"sideLength":0,
|
||||
"positionData":[
|
||||
{
|
||||
"panelId":60147,
|
||||
"x":199,
|
||||
"y":99,
|
||||
"o":0,
|
||||
"shapeType":3
|
||||
},
|
||||
{
|
||||
"panelId":61141,
|
||||
"x":200,
|
||||
"y":199,
|
||||
"o":90,
|
||||
"shapeType":2
|
||||
},
|
||||
{
|
||||
"panelId":42064,
|
||||
"x":100,
|
||||
"y":200,
|
||||
"o":180,
|
||||
"shapeType":2
|
||||
},
|
||||
{
|
||||
"panelId":186,
|
||||
"x":0,
|
||||
"y":200,
|
||||
"o":180,
|
||||
"shapeType":2
|
||||
},
|
||||
{
|
||||
"panelId":19209,
|
||||
"x":0,
|
||||
"y":100,
|
||||
"o":270,
|
||||
"shapeType":2
|
||||
},
|
||||
{
|
||||
"panelId":36604,
|
||||
"x":300,
|
||||
"y":99,
|
||||
"o":0,
|
||||
"shapeType":2
|
||||
},
|
||||
{
|
||||
"panelId":37121,
|
||||
"x":400,
|
||||
"y":99,
|
||||
"o":270,
|
||||
"shapeType":2
|
||||
},
|
||||
{
|
||||
"panelId":45187,
|
||||
"x":400,
|
||||
"y":199,
|
||||
"o":270,
|
||||
"shapeType":2
|
||||
},
|
||||
{
|
||||
"panelId":33626,
|
||||
"x":500,
|
||||
"y":199,
|
||||
"o":270,
|
||||
"shapeType":2
|
||||
},
|
||||
{
|
||||
"panelId":10523,
|
||||
"x":600,
|
||||
"y":199,
|
||||
"o":270,
|
||||
"shapeType":2
|
||||
},
|
||||
{
|
||||
"panelId":54086,
|
||||
"x":599,
|
||||
"y":99,
|
||||
"o":540,
|
||||
"shapeType":2
|
||||
},
|
||||
{
|
||||
"panelId":3512,
|
||||
"x":699,
|
||||
"y":99,
|
||||
"o":540,
|
||||
"shapeType":2
|
||||
},
|
||||
{
|
||||
"panelId":16398,
|
||||
"x":799,
|
||||
"y":99,
|
||||
"o":540,
|
||||
"shapeType":2
|
||||
},
|
||||
{
|
||||
"panelId":39163,
|
||||
"x":800,
|
||||
"y":199,
|
||||
"o":630,
|
||||
"shapeType":2
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue