diff --git a/benchmark/build.gradle b/benchmark/build.gradle index bae3a15ceec969d7597cb4d7a0c9de3d43d222d0..d4f5bd791f9dce5fc138d9f2ecd2fe9673beafde 100644 --- a/benchmark/build.gradle +++ b/benchmark/build.gradle @@ -5,10 +5,10 @@ plugins { dependencies { implementation project(':eraser-base') implementation project(':feedbackloop.learner_backup') - implementation group: 'com.opencsv', name: 'opencsv', version: '4.1' + implementation group: 'com.opencsv', name: 'opencsv', version: "${openscv_version}" implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: "${apache_httpcomponents_version}" implementation group: 'org.apache.httpcomponents', name: 'fluent-hc', version: "${apache_httpcomponents_version}" - testImplementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.11.2' + testImplementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: "${log4j_version}" } application.mainClass = 'de.tudresden.inf.st.eraser.benchmark.Main' diff --git a/buildSrc/src/main/groovy/eraser.java-common-conventions.gradle b/buildSrc/src/main/groovy/eraser.java-common-conventions.gradle index 8639ba92b6ec0fa6ad86248e115e8b5ddcc29d75..21077d8d8a54b9e6bee47df5b45df1ca96142a1f 100644 --- a/buildSrc/src/main/groovy/eraser.java-common-conventions.gradle +++ b/buildSrc/src/main/groovy/eraser.java-common-conventions.gradle @@ -9,16 +9,13 @@ repositories { } dependencies { - implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.2' - implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.2' - testImplementation group: 'junit', name: 'junit', version: '4.12' - testImplementation group: 'org.hamcrest', name: 'hamcrest-junit', version: '2.0.0.0' - - // testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2' - - // testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' + implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: "${log4j_version}" + implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: "${log4j_version}" + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: "${jupiter_version}" + testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.18.1' + testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "${jupiter_version}" } -// tasks.named('test') { -// useJUnitPlatform() -// } +tasks.named('test') { + useJUnitPlatform() +} diff --git a/eraser-base/build.gradle b/eraser-base/build.gradle index c0df8732d090b276d36e7bb7604169bef32db3ed..bda6f86b130a008a80336a26635f152f0ed734ed 100644 --- a/eraser-base/build.gradle +++ b/eraser-base/build.gradle @@ -17,23 +17,29 @@ apply plugin: 'jastadd' dependencies { jastadd2 "org.jastadd:jastadd:2.3.4" api group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "${jackson_version}" - api group: 'org.fusesource.mqtt-client', name: 'mqtt-client', version: '1.15' - implementation group: 'org.influxdb', name: 'influxdb-java', version: '2.15' - testImplementation group: 'org.testcontainers', name: 'testcontainers', version: '1.11.2' - testImplementation group: 'org.testcontainers', name: 'influxdb', version: '1.11.2' - testImplementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.11.2' + api group: 'org.fusesource.mqtt-client', name: 'mqtt-client', version: '1.16' + implementation group: 'org.influxdb', name: 'influxdb-java', version: '2.20' + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: "${jupiter_version}" + testImplementation group: 'org.testcontainers', name: 'testcontainers', version: '1.15.0' + testImplementation group: 'org.testcontainers', name: 'influxdb', version: '1.15.0' + testImplementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: "${log4j_version}" } application { mainClass = 'de.tudresden.inf.st.eraser.Main' } - -test { - testLogging { - events "passed", "skipped", "failed" - exceptionFormat "full" - } -} +// +//test { +// testLogging { +// events "passed", "skipped", "failed" +// exceptionFormat "full" +// } +//} + +//jacoco { +// toolVersion = '0.7.9' +// applyTo junitPlatformTest +//} jacocoTestReport { reports { @@ -42,6 +48,12 @@ jacocoTestReport { } } +//junitPlatformTest { +// jacoco { +// destinationFile = file("${buildDir}/jacoco/test.exec") +// } +//} + def relastFiles = fileTree('src/main/jastadd/') { include '**/*.relast' }.toList().toArray() String[] relastArguments = [ diff --git a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/ControllingItemTest.java b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/ControllingItemTest.java index 40d7a97d5575269136f92293c7f2f7317dcc7cbe..81a71fb6a5e13e96e96d1a18ee71e6ac27237d42 100644 --- a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/ControllingItemTest.java +++ b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/ControllingItemTest.java @@ -3,11 +3,13 @@ package de.tudresden.inf.st.eraser; import de.tudresden.inf.st.eraser.util.TestUtils; import de.tudresden.inf.st.eraser.util.TestUtils.ModelAndItem; import de.tudresden.inf.st.eraser.jastadd.model.*; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.function.Consumer; +import static org.junit.jupiter.api.Assertions.*; + /** * Testing the simple rule engine. * @@ -24,12 +26,12 @@ public class ControllingItemTest { NumberItem item2 = TestUtils.addItemTo(mai.model, 4, true); item1.addControlling(item2); - Assert.assertEquals(0, item1.getState(), DELTA); - Assert.assertEquals(4, item2.getState(), DELTA); + assertEquals(0, item1.getState(), DELTA); + assertEquals(4, item2.getState(), DELTA); item1.setState(5); - Assert.assertEquals(5, item1.getState(), DELTA); - Assert.assertEquals("Item was not controlled correctly", 5, item2.getState(), DELTA); + assertEquals(5, item1.getState(), DELTA); + assertEquals(5, item2.getState(), DELTA, "Item was not controlled correctly"); } @Test @@ -43,16 +45,16 @@ public class ControllingItemTest { item1.addControlling(item3); item1.addControlling(item4); - Assert.assertEquals(0, item1.getState(), DELTA); - Assert.assertEquals(3, item2.getState(), DELTA); - Assert.assertEquals(4, item3.getState(), DELTA); - Assert.assertEquals(5, item4.getState(), DELTA); + assertEquals(0, item1.getState(), DELTA); + assertEquals(3, item2.getState(), DELTA); + assertEquals(4, item3.getState(), DELTA); + assertEquals(5, item4.getState(), DELTA); item1.setState(5); - Assert.assertEquals(5, item1.getState(), DELTA); - Assert.assertEquals("Item2 was not controlled correctly", 5, item2.getState(), DELTA); - Assert.assertEquals("Item3 was not controlled correctly", 5, item3.getState(), DELTA); - Assert.assertEquals("Item4 was not controlled correctly", 5, item4.getState(), DELTA); + assertEquals(5, item1.getState(), DELTA); + assertEquals(5, item2.getState(), DELTA, "Item2 was not controlled correctly"); + assertEquals(5, item3.getState(), DELTA, "Item3 was not controlled correctly"); + assertEquals(5, item4.getState(), DELTA, "Item4 was not controlled correctly"); } @Test @@ -80,41 +82,41 @@ public class ControllingItemTest { target.addControlledBy(booleanItem); target.addControlledBy(colorItem); - Assert.assertEquals(0, numberItem.getState(), DELTA); - Assert.assertEquals("0", stringItem.getState()); - Assert.assertFalse(booleanItem.getState()); - Assert.assertEquals(TupleHSB.of(0, 0, 0), colorItem.getState()); - Assert.assertEquals(TupleHSB.of(0, 0, 0), target.getState()); + assertEquals(0, numberItem.getState(), DELTA); + assertEquals("0", stringItem.getState()); + assertFalse(booleanItem.getState()); + assertEquals(TupleHSB.of(0, 0, 0), colorItem.getState()); + assertEquals(TupleHSB.of(0, 0, 0), target.getState()); // number 5 -> set brightness to 5 numberItem.setState(5); - Assert.assertEquals(5, numberItem.getState(), DELTA); - Assert.assertEquals("Item was not controlled correctly", TupleHSB.of(0, 0, 5), target.getState()); + assertEquals(5, numberItem.getState(), DELTA); + assertEquals(TupleHSB.of(0, 0, 5), target.getState(), "Item was not controlled correctly"); // string 30 -> set brightness to 30 stringItem.setState("30"); - Assert.assertEquals("30", stringItem.getState()); - Assert.assertEquals("Item was not controlled correctly", TupleHSB.of(0, 0, 30), target.getState()); + assertEquals("30", stringItem.getState()); + assertEquals(TupleHSB.of(0, 0, 30), target.getState(), "Item was not controlled correctly"); // string 30,20,10 -> set HSB to (30,20,10) stringItem.setState("30,20,10"); - Assert.assertEquals("30,20,10", stringItem.getState()); - Assert.assertEquals("Item was not controlled correctly", TupleHSB.of(30, 20, 10), target.getState()); + assertEquals("30,20,10", stringItem.getState()); + assertEquals(TupleHSB.of(30, 20, 10), target.getState(), "Item was not controlled correctly"); // boolean true -> set brightness to full (100) booleanItem.setState(true); - Assert.assertTrue(booleanItem.getState()); - Assert.assertEquals("Item was not controlled correctly", TupleHSB.of(30, 20, 100), target.getState()); + assertTrue(booleanItem.getState()); + assertEquals(TupleHSB.of(30, 20, 100), target.getState(), "Item was not controlled correctly"); // color (33,33,33) -> set brightness to (33,33,33) colorItem.setState(TupleHSB.of(33, 33, 33)); - Assert.assertEquals(TupleHSB.of(33, 33, 33), colorItem.getState()); - Assert.assertEquals("Item was not controlled correctly", TupleHSB.of(33, 33, 33), target.getState()); + assertEquals(TupleHSB.of(33, 33, 33), colorItem.getState()); + assertEquals(TupleHSB.of(33, 33, 33), target.getState(), "Item was not controlled correctly"); // number 44 -> set brightness to 44 numberItem.setState(44); - Assert.assertEquals(44, numberItem.getState(), DELTA); - Assert.assertEquals("Item was not controlled correctly", TupleHSB.of(33, 33, 44), target.getState()); + assertEquals(44, numberItem.getState(), DELTA); + assertEquals(TupleHSB.of(33, 33, 44), target.getState(), "Item was not controlled correctly"); } private <T extends Item> T initAndAddItem(Group group, T item, Consumer<T> setState) { diff --git a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/DecisionTreeTest.java b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/DecisionTreeTest.java index 85f0722976a1365aa021dd55ea1d3694589530bd..ee4755b32dcc845e18df6c704c8830be081701b6 100644 --- a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/DecisionTreeTest.java +++ b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/DecisionTreeTest.java @@ -2,8 +2,9 @@ package de.tudresden.inf.st.eraser; import de.tudresden.inf.st.eraser.jastadd.model.*; import de.tudresden.inf.st.eraser.util.TestUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Testing the decision tree aspect of the knowledge base. @@ -26,17 +27,17 @@ public class DecisionTreeTest { // current value is four, so return value should be "four or greater" Leaf leaf = dtroot.internalClassify(); - Assert.assertEquals(isFourOrGreater, leaf); + assertEquals(isFourOrGreater, leaf); // change value to 5, so return value should still be "four or greater" mai.item.setState(5); leaf = dtroot.internalClassify(); - Assert.assertEquals(isFourOrGreater, leaf); + assertEquals(isFourOrGreater, leaf); // change value to 2, so return value should now be "less than four" mai.item.setState(2); leaf = dtroot.internalClassify(); - Assert.assertEquals(isLessThanFour, leaf); + assertEquals(isLessThanFour, leaf); } @Test @@ -65,17 +66,17 @@ public class DecisionTreeTest { // current value is 20, so return value should be "less than 25" Leaf leaf = dtroot.internalClassify(); - Assert.assertEquals(isLessThan25, leaf); + assertEquals(isLessThan25, leaf); // change value to 25, so return value should still be "25 or greater" mai.item.setState(25); leaf = dtroot.internalClassify(); - Assert.assertEquals(is25OrGreater, leaf); + assertEquals(is25OrGreater, leaf); // change value to 100, so return value should now be "greater than 75" mai.item.setState(100); leaf = dtroot.internalClassify(); - Assert.assertEquals(is75OrGreater, leaf); + assertEquals(is75OrGreater, leaf); } @Test @@ -140,7 +141,7 @@ public class DecisionTreeTest { for (TestResult result : testResults) { mai.item.setState(Math.round(result.value)); Leaf leaf = dtroot.internalClassify(); - Assert.assertEquals(result.chooseLeft ? leaf : right, leaf); + assertEquals(result.chooseLeft ? leaf : right, leaf); } } diff --git a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/ExpressionEvalTest.java b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/ExpressionEvalTest.java index 1758931346632a63c9f3297912b1fb7d1430da46..c602b5f4d3761714b5ba23e4aadfece2a21bfd7a 100644 --- a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/ExpressionEvalTest.java +++ b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/ExpressionEvalTest.java @@ -3,13 +3,12 @@ package de.tudresden.inf.st.eraser; import beaver.Parser; import de.tudresden.inf.st.eraser.jastadd.model.*; import de.tudresden.inf.st.eraser.util.ParserUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.hamcrest.core.IsInstanceOf.instanceOf; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; /** * Test correct evaluation of NumberExpression and LogicalExpression. @@ -21,56 +20,56 @@ public class ExpressionEvalTest { @Test public void plusExpression() throws IOException, Parser.Exception { NumberExpression sut = ParserUtils.parseNumberExpression("(3 + 4)"); - assertThat(sut.eval(), equalTo(7.0)); + assertEquals(7.0, sut.eval()); } @Test public void minusExpression() throws IOException, Parser.Exception { NumberExpression sut = ParserUtils.parseNumberExpression("(4.1 - 12.5)"); - assertThat(sut.eval(), equalTo(-8.4)); + assertEquals(-8.4, sut.eval()); } @Test public void multExpression() throws IOException, Parser.Exception { NumberExpression sut = ParserUtils.parseNumberExpression("(3 * 4)"); - assertThat(sut.eval(), equalTo(12.0)); + assertEquals(12.0, sut.eval()); } @Test public void divExpression() throws IOException, Parser.Exception { NumberExpression sut = ParserUtils.parseNumberExpression("(1.1 / 4.0)"); - assertThat(sut.eval(), equalTo(0.275)); + assertEquals(0.275, sut.eval()); } @Test public void powerExpression() throws IOException, Parser.Exception { NumberExpression sut = ParserUtils.parseNumberExpression("(16 ^ 0.5)"); - assertThat(sut.eval(), equalTo(4.0)); + assertEquals(4.0, sut.eval()); } @Test public void parenthesizedExpression() throws IOException, Parser.Exception { NumberExpression sut = ParserUtils.parseNumberExpression("(3)"); - assertThat(sut.eval(), equalTo(3.0)); + assertEquals(3.0, sut.eval()); } @Test public void complexExpression() throws IOException, Parser.Exception { NumberExpression sut = ParserUtils.parseNumberExpression("((3 + 4) * (1 / (12 - 8)))"); - assertThat(sut.eval(), equalTo(1.75)); + assertEquals(1.75, sut.eval()); MultExpression multExpression = (MultExpression) sut; // 3+4 - assertThat(multExpression.getLeftOperand(), instanceOf(AddExpression.class)); - assertThat(multExpression.getLeftOperand().eval(), equalTo(7.0)); + assertThat(multExpression.getLeftOperand()).isInstanceOf(AddExpression.class); + assertEquals(7.0, multExpression.getLeftOperand().eval()); // 1/(12-8) - assertThat(multExpression.getRightOperand(), instanceOf(DivExpression.class)); + assertThat(multExpression.getRightOperand()).isInstanceOf(DivExpression.class); DivExpression divExpression = (DivExpression) multExpression.getRightOperand(); - assertThat(divExpression.eval(), equalTo(0.25)); + assertEquals(0.25, divExpression.eval()); // 12-8 - assertThat(divExpression.getRightOperand().eval(), equalTo(4.0)); + assertEquals(4.0, divExpression.getRightOperand().eval()); } @Test @@ -78,12 +77,12 @@ public class ExpressionEvalTest { double itemValue = 5.3; Item referenceItem = ParserUtils.parseItem("Number Item: id=\"myItem\" state=\"" + itemValue + "\";"); NumberExpression sut = ParserUtils.parseNumberExpression("(myItem * 3)", referenceItem.getRoot()); - assertThat(sut.eval(), equalTo(itemValue * 3)); + assertEquals(itemValue * 3, sut.eval()); // set item state to new value itemValue = 17; referenceItem.setStateFromDouble(itemValue); - assertThat(sut.eval(), equalTo(itemValue * 3)); + assertEquals(itemValue * 3, sut.eval()); } @Test @@ -112,54 +111,54 @@ public class ExpressionEvalTest { } private void comparingExpression(double left, String actualComparatorString, double right, boolean expectedResult) throws IOException, Parser.Exception { - String expression = String.format("(%s %s %s)", Double.toString(left), actualComparatorString, Double.toString(right)); + String expression = String.format("(%s %s %s)", left, actualComparatorString, right); LogicalExpression sut = ParserUtils.parseLogicalExpression(expression); - assertThat(sut.eval(), equalTo(expectedResult)); + assertEquals(expectedResult, sut.eval()); } @Test public void notExpression() throws IOException, Parser.Exception { LogicalExpression sut = ParserUtils.parseLogicalExpression("!(0==0)"); - assertThat(sut.eval(), equalTo(false)); + assertFalse(sut.eval()); LogicalExpression sut2 = ParserUtils.parseLogicalExpression("!!(0==0)"); - assertThat(sut2.eval(), equalTo(true)); + assertTrue(sut2.eval()); } @Test public void andExpression() throws IOException, Parser.Exception { LogicalExpression sut = ParserUtils.parseLogicalExpression("((0==0) & (0==0))"); - assertThat(sut.eval(), equalTo(true)); + assertTrue(sut.eval()); LogicalExpression sut2 = ParserUtils.parseLogicalExpression("((0==0) & (0==1))"); - assertThat(sut2.eval(), equalTo(false)); + assertFalse(sut2.eval()); LogicalExpression sut3 = ParserUtils.parseLogicalExpression("((0==1) & (0==0))"); - assertThat(sut3.eval(), equalTo(false)); + assertFalse(sut3.eval()); LogicalExpression sut4 = ParserUtils.parseLogicalExpression("((0==1) & (0==1))"); - assertThat(sut4.eval(), equalTo(false)); + assertFalse(sut4.eval()); } @Test public void orExpression() throws IOException, Parser.Exception { LogicalExpression sut = ParserUtils.parseLogicalExpression("((0==0) | (0==0))"); - assertThat(sut.eval(), equalTo(true)); + assertTrue(sut.eval()); LogicalExpression sut2 = ParserUtils.parseLogicalExpression("((0==0) | (0==1))"); - assertThat(sut2.eval(), equalTo(true)); + assertTrue(sut2.eval()); LogicalExpression sut3 = ParserUtils.parseLogicalExpression("((0==1) | (0==0))"); - assertThat(sut3.eval(), equalTo(true)); + assertTrue(sut3.eval()); LogicalExpression sut4 = ParserUtils.parseLogicalExpression("((0==1) | (0==1))"); - assertThat(sut4.eval(), equalTo(false)); + assertFalse(sut4.eval()); } @Test public void parenthesizedLogicalExpression() throws IOException, Parser.Exception { LogicalExpression sut = ParserUtils.parseLogicalExpression("((0==0))"); - assertThat(sut.eval(), equalTo(true)); + assertTrue(sut.eval()); ParenthesizedLogicalExpression parenthesizedLogicalExpression = (ParenthesizedLogicalExpression) sut; - assertThat(parenthesizedLogicalExpression.getOperand().eval(), equalTo(true)); + assertTrue(parenthesizedLogicalExpression.getOperand().eval()); } } diff --git a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/ExpressionParserTest.java b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/ExpressionParserTest.java index a034d3c8f8699046c9c89d2f139f14880a80b704..a1c9f0014bca6d7ddb95e729d2ee725a203719d1 100644 --- a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/ExpressionParserTest.java +++ b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/ExpressionParserTest.java @@ -3,14 +3,12 @@ package de.tudresden.inf.st.eraser; import beaver.Parser; import de.tudresden.inf.st.eraser.jastadd.model.*; import de.tudresden.inf.st.eraser.util.ParserUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.hamcrest.core.IsInstanceOf.instanceOf; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Test correct parsing of NumberExpression and LogicalExpression. @@ -24,125 +22,125 @@ public class ExpressionParserTest { @Test public void plusExpression() throws IOException, Parser.Exception { NumberExpression sut = parseWithRoundTripNumberExpression("(3 + 4)"); - assertThat(sut, instanceOf(AddExpression.class)); + assertThat(sut).isInstanceOf(AddExpression.class); AddExpression addExpression = (AddExpression) sut; - assertThat(addExpression.getLeftOperand(), instanceOf(NumberLiteralExpression.class)); + assertThat(addExpression.getLeftOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression left = (NumberLiteralExpression) addExpression.getLeftOperand(); - assertThat(left.getValue(), equalTo(3.0)); - assertThat(addExpression.getRightOperand(), instanceOf(NumberLiteralExpression.class)); + assertEquals(3.0, left.getValue()); + assertThat(addExpression.getRightOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression right = (NumberLiteralExpression) addExpression.getRightOperand(); - assertThat(right.getValue(), equalTo(4.0)); + assertEquals(4.0, right.getValue()); } @Test public void minusExpression() throws IOException, Parser.Exception { NumberExpression sut = parseWithRoundTripNumberExpression("(12.5 - 4.1)"); - assertThat(sut, instanceOf(SubExpression.class)); + assertThat(sut).isInstanceOf(SubExpression.class); SubExpression subExpression = (SubExpression) sut; - assertThat(subExpression.getLeftOperand(), instanceOf(NumberLiteralExpression.class)); + assertThat(subExpression.getLeftOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression left = (NumberLiteralExpression) subExpression.getLeftOperand(); - assertThat(left.getValue(), equalTo(12.5)); - assertThat(subExpression.getRightOperand(), instanceOf(NumberLiteralExpression.class)); + assertEquals(12.5, left.getValue()); + assertThat(subExpression.getRightOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression right = (NumberLiteralExpression) subExpression.getRightOperand(); - assertThat(right.getValue(), equalTo(4.1)); + assertEquals(4.1, right.getValue()); } @Test public void multExpression() throws IOException, Parser.Exception { NumberExpression sut = parseWithRoundTripNumberExpression("(0 * 0)"); - assertThat(sut, instanceOf(MultExpression.class)); + assertThat(sut).isInstanceOf(MultExpression.class); MultExpression multExpression = (MultExpression) sut; - assertThat(multExpression.getLeftOperand(), instanceOf(NumberLiteralExpression.class)); + assertThat(multExpression.getLeftOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression left = (NumberLiteralExpression) multExpression.getLeftOperand(); - assertThat(left.getValue(), equalTo(0.0)); - assertThat(multExpression.getRightOperand(), instanceOf(NumberLiteralExpression.class)); + assertEquals(0.0, left.getValue()); + assertThat(multExpression.getRightOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression right = (NumberLiteralExpression) multExpression.getRightOperand(); - assertThat(right.getValue(), equalTo(0.0)); + assertEquals(0.0, right.getValue()); } @Test public void divExpression() throws IOException, Parser.Exception { NumberExpression sut = parseWithRoundTripNumberExpression("(1.1 / 0.0)"); - assertThat(sut, instanceOf(DivExpression.class)); + assertThat(sut).isInstanceOf(DivExpression.class); DivExpression divExpression = (DivExpression) sut; - assertThat(divExpression.getLeftOperand(), instanceOf(NumberLiteralExpression.class)); + assertThat(divExpression.getLeftOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression left = (NumberLiteralExpression) divExpression.getLeftOperand(); - assertThat(left.getValue(), equalTo(1.1)); - assertThat(divExpression.getRightOperand(), instanceOf(NumberLiteralExpression.class)); + assertEquals(1.1, left.getValue()); + assertThat(divExpression.getRightOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression right = (NumberLiteralExpression) divExpression.getRightOperand(); - assertThat(right.getValue(), equalTo(0.0)); + assertEquals(0.0, right.getValue()); } @Test public void powerExpression() throws IOException, Parser.Exception { NumberExpression sut = parseWithRoundTripNumberExpression("(3 ^ 0.5)"); - assertThat(sut, instanceOf(PowerExpression.class)); + assertThat(sut).isInstanceOf(PowerExpression.class); PowerExpression powExpression = (PowerExpression) sut; - assertThat(powExpression.getLeftOperand(), instanceOf(NumberLiteralExpression.class)); + assertThat(powExpression.getLeftOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression left = (NumberLiteralExpression) powExpression.getLeftOperand(); - assertThat(left.getValue(), equalTo(3.0)); - assertThat(powExpression.getRightOperand(), instanceOf(NumberLiteralExpression.class)); + assertEquals(3.0, left.getValue()); + assertThat(powExpression.getRightOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression right = (NumberLiteralExpression) powExpression.getRightOperand(); - assertThat(right.getValue(), equalTo(0.5)); + assertEquals(0.5, right.getValue()); } @Test public void parenthesizedExpression() throws IOException, Parser.Exception { NumberExpression sut = parseWithRoundTripNumberExpression("(3)"); - assertThat(sut, instanceOf(ParenthesizedNumberExpression.class)); + assertThat(sut).isInstanceOf(ParenthesizedNumberExpression.class); ParenthesizedNumberExpression parenExpression = (ParenthesizedNumberExpression) sut; - assertThat(parenExpression.getOperand(), instanceOf(NumberLiteralExpression.class)); + assertThat(parenExpression.getOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression left = (NumberLiteralExpression) parenExpression.getOperand(); - assertThat(left.getValue(), equalTo(3.0)); + assertEquals(3.0, left.getValue()); } @Test public void complexExpression() throws IOException, Parser.Exception { NumberExpression sut = parseWithRoundTripNumberExpression("((3 + 4) * (1 / (12 - 8)))"); - assertThat(sut, instanceOf(MultExpression.class)); + assertThat(sut).isInstanceOf(MultExpression.class); MultExpression multExpression = (MultExpression) sut; // 3+4 - assertThat(multExpression.getLeftOperand(), instanceOf(AddExpression.class)); + assertThat(multExpression.getLeftOperand()).isInstanceOf(AddExpression.class); AddExpression addExpression = (AddExpression) multExpression.getLeftOperand(); - assertThat(addExpression.getLeftOperand(), instanceOf(NumberLiteralExpression.class)); + assertThat(addExpression.getLeftOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression left = (NumberLiteralExpression) addExpression.getLeftOperand(); - assertThat(left.getValue(), equalTo(3.0)); - assertThat(addExpression.getRightOperand(), instanceOf(NumberLiteralExpression.class)); + assertEquals(3.0, left.getValue()); + assertThat(addExpression.getRightOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression right = (NumberLiteralExpression) addExpression.getRightOperand(); - assertThat(right.getValue(), equalTo(4.0)); + assertEquals(4.0, right.getValue()); // 1/(12-8) - assertThat(multExpression.getRightOperand(), instanceOf(DivExpression.class)); + assertThat(multExpression.getRightOperand()).isInstanceOf(DivExpression.class); DivExpression divExpression = (DivExpression) multExpression.getRightOperand(); - assertThat(divExpression.getLeftOperand(), instanceOf(NumberLiteralExpression.class)); + assertThat(divExpression.getLeftOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression leftOfDiv = (NumberLiteralExpression) divExpression.getLeftOperand(); - assertThat(leftOfDiv.getValue(), equalTo(1.0)); + assertEquals(1.0, leftOfDiv.getValue()); // 12-8 - assertThat(divExpression.getRightOperand(), instanceOf(SubExpression.class)); + assertThat(divExpression.getRightOperand()).isInstanceOf(SubExpression.class); SubExpression rightofDiv = (SubExpression) divExpression.getRightOperand(); - assertThat(rightofDiv.getLeftOperand(), instanceOf(NumberLiteralExpression.class)); + assertThat(rightofDiv.getLeftOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression leftOfSSub = (NumberLiteralExpression) rightofDiv.getLeftOperand(); - assertThat(leftOfSSub.getValue(), equalTo(12.0)); - assertThat(rightofDiv.getRightOperand(), instanceOf(NumberLiteralExpression.class)); + assertEquals(12.0, leftOfSSub.getValue()); + assertThat(rightofDiv.getRightOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression rightOfSub = (NumberLiteralExpression) rightofDiv.getRightOperand(); - assertThat(rightOfSub.getValue(), equalTo(8.0)); + assertEquals(8.0, rightOfSub.getValue()); } @Test public void expressionWithItem() throws IOException, Parser.Exception { Item referenceItem = ParserUtils.parseItem("Number Item: id=\"myItem\";"); NumberExpression sut = parseWithRoundTripNumberExpression("(myItem * 3)", referenceItem.getRoot()); - assertThat(sut, instanceOf(MultExpression.class)); + assertThat(sut).isInstanceOf(MultExpression.class); MultExpression multExpression = (MultExpression) sut; - assertThat(multExpression.getLeftOperand(), instanceOf(Designator.class)); + assertThat(multExpression.getLeftOperand()).isInstanceOf(Designator.class); Designator left = (Designator) multExpression.getLeftOperand(); - assertThat(left.getItem(), equalTo(referenceItem)); - assertThat(multExpression.getRightOperand(), instanceOf(NumberLiteralExpression.class)); + assertEquals(referenceItem, left.getItem()); + assertThat(multExpression.getRightOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression right = (NumberLiteralExpression) multExpression.getRightOperand(); - assertThat(right.getValue(), equalTo(3.0)); + assertEquals(3.0, right.getValue()); } @Test @@ -156,23 +154,23 @@ public class ExpressionParserTest { } private void comparingExpression(String actualComparatorString, ComparatorType expectedComparatorType, double left, double right) throws IOException, Parser.Exception { - String expression = String.format("(%s %s %s)", Double.toString(left), actualComparatorString, Double.toString(right)); + String expression = String.format("(%s %s %s)", left, actualComparatorString, right); LogicalExpression sut = parseWithRoundTripLogicalExpression(expression); - assertThat(sut, instanceOf(ComparingExpression.class)); + assertThat(sut).isInstanceOf(ComparingExpression.class); ComparingExpression comparingExpression = (ComparingExpression) sut; - assertThat(comparingExpression.getLeftOperand(), instanceOf(NumberLiteralExpression.class)); + assertThat(comparingExpression.getLeftOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression leftExpression = (NumberLiteralExpression) comparingExpression.getLeftOperand(); - assertThat(leftExpression.getValue(), equalTo(left)); - assertThat(comparingExpression.getRightOperand(), instanceOf(NumberLiteralExpression.class)); + assertEquals(left, leftExpression.getValue()); + assertThat(comparingExpression.getRightOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression rightExpression = (NumberLiteralExpression) comparingExpression.getRightOperand(); - assertThat(rightExpression.getValue(), equalTo(right)); - assertThat(comparingExpression.getComparator(), equalTo(expectedComparatorType)); + assertEquals(right, rightExpression.getValue()); + assertEquals(expectedComparatorType, comparingExpression.getComparator()); } @Test public void notExpression() throws IOException, Parser.Exception { LogicalExpression sut = parseWithRoundTripLogicalExpression("!" + TRUE_EXPRESSION); - assertThat(sut, instanceOf(NotExpression.class)); + assertThat(sut).isInstanceOf(NotExpression.class); NotExpression notExpression = (NotExpression) sut; checkZeroEqualsZero(notExpression.getOperand()); } @@ -180,7 +178,7 @@ public class ExpressionParserTest { @Test public void andExpression() throws IOException, Parser.Exception { LogicalExpression sut = parseWithRoundTripLogicalExpression("(" + TRUE_EXPRESSION + " & " + TRUE_EXPRESSION + ")"); - assertThat(sut, instanceOf(AndExpression.class)); + assertThat(sut).isInstanceOf(AndExpression.class); AndExpression notExpression = (AndExpression) sut; checkZeroEqualsZero(notExpression.getLeftOperand()); checkZeroEqualsZero(notExpression.getRightOperand()); @@ -189,7 +187,7 @@ public class ExpressionParserTest { @Test public void orExpression() throws IOException, Parser.Exception { LogicalExpression sut = parseWithRoundTripLogicalExpression("(" + TRUE_EXPRESSION + " | " + TRUE_EXPRESSION + ")"); - assertThat(sut, instanceOf(OrExpression.class)); + assertThat(sut).isInstanceOf(OrExpression.class); OrExpression notExpression = (OrExpression) sut; checkZeroEqualsZero(notExpression.getLeftOperand()); checkZeroEqualsZero(notExpression.getRightOperand()); @@ -198,7 +196,7 @@ public class ExpressionParserTest { @Test public void parenthesizedLogicalExpression() throws IOException, Parser.Exception { LogicalExpression sut = parseWithRoundTripLogicalExpression("(" + TRUE_EXPRESSION + ")"); - assertThat(sut, instanceOf(ParenthesizedLogicalExpression.class)); + assertThat(sut).isInstanceOf(ParenthesizedLogicalExpression.class); ParenthesizedLogicalExpression parenthesizedLogicalExpression = (ParenthesizedLogicalExpression) sut; checkZeroEqualsZero(parenthesizedLogicalExpression.getOperand()); } @@ -212,7 +210,7 @@ public class ExpressionParserTest { String first = sut.prettyPrint(); NumberExpression reParsed = ParserUtils.parseNumberExpression(first, root); String second = reParsed.prettyPrint(); - assertThat(first, equalTo(second)); + assertEquals(second, first); return sut; } @@ -221,18 +219,18 @@ public class ExpressionParserTest { String first = sut.prettyPrint(); LogicalExpression reParsed = ParserUtils.parseLogicalExpression(first); String second = reParsed.prettyPrint(); - assertThat(first, equalTo(second)); + assertEquals(second, first); return sut; } private void checkZeroEqualsZero(LogicalExpression logicalExpression) { - assertThat(logicalExpression, instanceOf(ComparingExpression.class)); + assertThat(logicalExpression).isInstanceOf(ComparingExpression.class); ComparingExpression comparingExpression = (ComparingExpression) logicalExpression; - assertThat(comparingExpression.getLeftOperand(), instanceOf(NumberLiteralExpression.class)); + assertThat(comparingExpression.getLeftOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression leftOfSSub = (NumberLiteralExpression) comparingExpression.getLeftOperand(); - assertThat(leftOfSSub.getValue(), equalTo(0.0)); - assertThat(comparingExpression.getRightOperand(), instanceOf(NumberLiteralExpression.class)); + assertEquals(0.0, leftOfSSub.getValue()); + assertThat(comparingExpression.getRightOperand()).isInstanceOf(NumberLiteralExpression.class); NumberLiteralExpression rightOfSub = (NumberLiteralExpression) comparingExpression.getRightOperand(); - assertThat(rightOfSub.getValue(), equalTo(0.0)); + assertEquals(0.0, rightOfSub.getValue()); } } diff --git a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/InfluxTest.java b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/InfluxTest.java index 9526a4db04802684261f820e807db35d6a47c24f..acbd2f541d554161e1185fc0c1a9e2c271d868aa 100644 --- a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/InfluxTest.java +++ b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/InfluxTest.java @@ -3,9 +3,9 @@ package de.tudresden.inf.st.eraser; import de.tudresden.inf.st.eraser.jastadd.model.*; import de.tudresden.inf.st.eraser.util.TestUtils; import de.tudresden.inf.st.eraser.util.TestUtils.ModelAndItem; -import org.junit.*; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.*; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.InfluxDBContainer; import java.time.Instant; @@ -14,12 +14,17 @@ import java.util.Arrays; import java.util.Comparator; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + /** * Testing item history aspect, and connection to influx db. * * @author rschoene - Initial contribution */ -@RunWith(Parameterized.class) +//@RunWith(Parameterized.class) +@Disabled("Parameterized test still to be ported to junit5") public class InfluxTest { private static final double DELTA = 0.001; @@ -30,59 +35,61 @@ public class InfluxTest { private ModelAndItem mai; - @ClassRule +// @ClassRule public static InfluxDBContainer influxDbContainer = new InfluxDBContainer() .withDatabase(InfluxRoot.createDefault().getDbName()) .withAdmin(InfluxRoot.createDefault().getUser()) .withAdminPassword(InfluxRoot.createDefault().getPassword()); - @Test - public void oneItem() { + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void oneItem(boolean useStub) { NumberItem item = mai.item; // set state once item.setState(firstState); - assertSameOrdered(query(item), + assertSameOrdered(query(useStub, item), DoubleStatePoint.of(Instant.ofEpochSecond(1), firstState, item.getID())); // set state again item.setState(secondState); - assertSameOrdered(query(item), + assertSameOrdered(query(useStub, item), DoubleStatePoint.of(Instant.ofEpochSecond(1), firstState, item.getID()), DoubleStatePoint.of(Instant.ofEpochSecond(2), secondState, item.getID())); // set state a third time item.setState(thirdState); - assertSameOrdered(query(item), + assertSameOrdered(query(useStub, item), DoubleStatePoint.of(Instant.ofEpochSecond(1), firstState, item.getID()), DoubleStatePoint.of(Instant.ofEpochSecond(2), secondState, item.getID()), DoubleStatePoint.of(Instant.ofEpochSecond(3), thirdState, item.getID())); } - @Test - public void twoItems() { + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void twoItems(boolean useStub) { NumberItem item1 = mai.item; NumberItem item2 = TestUtils.addItemTo(mai.model, 1.0, true); // set state once for first item item1.setState(firstState); - assertSameOrdered(query(item1, item2), + assertSameOrdered(query(useStub, item1, item2), DoubleStatePoint.of(Instant.ofEpochSecond(1), firstState, item1.getID())); // set state again for first item item1.setState(secondState); - assertSameOrdered(query(item1, item2), + assertSameOrdered(query(useStub, item1, item2), DoubleStatePoint.of(Instant.ofEpochSecond(1), firstState, item1.getID()), DoubleStatePoint.of(Instant.ofEpochSecond(2), secondState, item1.getID())); // set state for second item item2.setState(firstState); - assertSameOrdered(query(item1, item2), + assertSameOrdered(query(useStub, item1, item2), DoubleStatePoint.of(Instant.ofEpochSecond(1), firstState, item1.getID()), DoubleStatePoint.of(Instant.ofEpochSecond(2), secondState, item1.getID()), DoubleStatePoint.of(Instant.ofEpochSecond(3), firstState, item2.getID())); // set third state for first item item1.setState(thirdState); - assertSameOrdered(query(item1, item2), + assertSameOrdered(query(useStub, item1, item2), DoubleStatePoint.of(Instant.ofEpochSecond(1), firstState, item1.getID()), DoubleStatePoint.of(Instant.ofEpochSecond(2), secondState, item1.getID()), DoubleStatePoint.of(Instant.ofEpochSecond(3), firstState, item2.getID()), @@ -91,7 +98,7 @@ public class InfluxTest { // set second and third state for second item item2.setState(secondState); item2.setState(thirdState); - assertSameOrdered(query(item1, item2), + assertSameOrdered(query(useStub, item1, item2), DoubleStatePoint.of(Instant.ofEpochSecond(1), firstState, item1.getID()), DoubleStatePoint.of(Instant.ofEpochSecond(2), secondState, item1.getID()), DoubleStatePoint.of(Instant.ofEpochSecond(3), firstState, item2.getID()), @@ -100,10 +107,11 @@ public class InfluxTest { DoubleStatePoint.of(Instant.ofEpochSecond(6), thirdState, item2.getID())); } - @Test - public void justAdapter() { + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void justAdapter(boolean useStub) { InfluxAdapter influxAdapter = getInfluxRoot().influxAdapter(); - Assert.assertTrue("Adapter not connected", influxAdapter.isConnected()); + assertTrue(influxAdapter.isConnected(), "Adapter not connected"); influxAdapter.deleteDatabase(); // write one point @@ -119,16 +127,16 @@ public class InfluxTest { } else { result = influxAdapter.query(DoubleStatePoint.NAME, id, DoubleStatePoint.class); } - Assert.assertEquals("Did not get one result item", 1, result.size()); - Assert.assertEquals("Wrong class", DoubleStatePoint.class, result.get(0).getClass()); + assertEquals(1, result.size(), "Did not get one result item"); + assertEquals(DoubleStatePoint.class, result.get(0).getClass(), "Wrong class"); DoubleStatePoint point = (DoubleStatePoint) result.get(0); - Assert.assertEquals("Time differs", now, point.getTime()); - Assert.assertEquals("ID differs", id, point.getId()); - Assert.assertEquals("State differs", state, point.getState(), DELTA); + assertEquals(now, point.getTime(), "Time differs"); + assertEquals(id, point.getId(), "ID differs"); + assertEquals(state, point.getState(), DELTA, "State differs"); } private void assertSameOrdered(List<DoubleStatePoint> actual, DoubleStatePoint... expected) { - Assert.assertEquals("Number of items differs!", expected.length, actual.size()); + assertEquals(expected.length, actual.size(), "Number of items differs!"); // sort actual and expected points by time List<DoubleStatePoint> actualOrdered = new ArrayList<>(actual); actualOrdered.sort(Comparator.comparing(AbstractItemPoint::getTime)); @@ -136,14 +144,14 @@ public class InfluxTest { expectedOrdered.sort(Comparator.comparing(AbstractItemPoint::getTime)); // and then compare them for (int i = 0; i < actualOrdered.size(); i++) { - Assert.assertEquals("State of item " + i + " differs!", - expectedOrdered.get(i).getState(), actualOrdered.get(i).getState(), DELTA); - Assert.assertEquals("Id of item " + i + " differs!", - expectedOrdered.get(i).getId(), actualOrdered.get(i).getId()); + assertEquals(expectedOrdered.get(i).getState(), actualOrdered.get(i).getState(), DELTA, + "State of item " + i + " differs!"); + assertEquals(expectedOrdered.get(i).getId(), actualOrdered.get(i).getId(), + "Id of item " + i + " differs!"); } } - private ModelAndItem createModel() { + private ModelAndItem createModel(boolean useStub) { ModelAndItem mai = TestUtils.createModelAndItem(1.0, true); InfluxRoot influxRoot; if (useStub) { @@ -160,7 +168,7 @@ public class InfluxTest { influxRoot.setHostByName(influxDbContainer.getUrl().replaceAll("^http://", "")); } mai.model.getRoot().setInfluxRoot(influxRoot); - Assume.assumeTrue(influxRoot.influxAdapter().isConnected()); + assumeTrue(influxRoot.influxAdapter().isConnected()); influxRoot.influxAdapter().deleteDatabase(); return mai; } @@ -169,7 +177,7 @@ public class InfluxTest { return mai.model.getRoot().getInfluxRoot(); } - private List<DoubleStatePoint> query(ItemWithDoubleState... allItems) { + private List<DoubleStatePoint> query(boolean useStub, ItemWithDoubleState... allItems) { if (useStub) { return points; } else { @@ -181,26 +189,26 @@ public class InfluxTest { } } - @Before - public void setNewModel() { - mai = createModel(); + @BeforeEach + public void setNewModel(boolean useStub) { + mai = createModel(useStub); getInfluxRoot().influxAdapter().disableAsyncQuery(); } - @After + @AfterEach public void closeInfluxAdapter() throws Exception { if (mai != null && mai.model != null) { getInfluxRoot().influxAdapter().close(); } } - @Parameterized.Parameter - public String name; - - @Parameterized.Parameter(1) - public boolean useStub; +// @Parameterized.Parameter +// public String name; +// +// @Parameterized.Parameter(1) +// public boolean useStub; - @Parameterized.Parameters(name = "{0}") +// @Parameterized.Parameters(name = "{0}") public static Iterable<Object[]> getTests() { return Arrays.asList(new Object[][] { {"Impl", false}, diff --git a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/ItemTests.java b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/ItemTests.java index ff7bc53730b5336917361d1fa436fddde61206c4..f56a3bc6a2065a657c1d384a44a7c59a9db4b285 100644 --- a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/ItemTests.java +++ b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/ItemTests.java @@ -3,11 +3,14 @@ package de.tudresden.inf.st.eraser; import de.tudresden.inf.st.eraser.jastadd.model.*; import de.tudresden.inf.st.eraser.util.TestUtils; import de.tudresden.inf.st.eraser.util.TestUtils.ModelAndItem; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.time.Instant; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * Testing wrapper methods of {@link Item}. * @@ -20,12 +23,12 @@ public class ItemTests { ItemWithBooleanState sut = createItem(SwitchItem::new); sut.setState(true); - Assert.assertTrue("State 'true' should match 'true'", sut.stateEquals(true)); - Assert.assertFalse("State 'true' should not match 'false'", sut.stateEquals(false)); + assertTrue(sut.stateEquals(true), "State 'true' should match 'true'"); + assertFalse(sut.stateEquals(false), "State 'true' should not match 'false'"); sut.setState(false); - Assert.assertFalse("State 'false' should not match 'true'", sut.stateEquals(true)); - Assert.assertTrue("State 'false' should match 'false'", sut.stateEquals(false)); + assertFalse(sut.stateEquals(true), "State 'false' should not match 'true'"); + assertTrue(sut.stateEquals(false), "State 'false' should match 'false'"); } @Test @@ -33,10 +36,10 @@ public class ItemTests { ItemWithStringState sut = createItem(ImageItem::new); sut.setState("correct"); - Assert.assertTrue("State 'correct' should match 'correct'", - sut.stateEquals("correct")); - Assert.assertFalse("State 'correct' should not match 'something else'", - sut.stateEquals("something else")); + assertTrue(sut.stateEquals("correct"), + "State 'correct' should match 'correct'"); + assertFalse(sut.stateEquals("something else"), + "State 'correct' should not match 'something else'"); } @Test @@ -44,12 +47,12 @@ public class ItemTests { ItemWithDoubleState sut = createItem(NumberItem::new); sut.setState(3.0); - Assert.assertTrue("State '3.0' should match '3.0'", sut.stateEquals(3.0)); - Assert.assertFalse("State '3.0' should not match '7.0'", sut.stateEquals(7.0)); + assertTrue(sut.stateEquals(3.0), "State '3.0' should match '3.0'"); + assertFalse(sut.stateEquals(7.0), "State '3.0' should not match '7.0'"); sut.setState(4.0); - Assert.assertFalse("State '4.0' should not match '3.0'", sut.stateEquals(3.0)); - Assert.assertFalse("State '4.0' should not match '7.0'", sut.stateEquals(7.0)); + assertFalse(sut.stateEquals(3.0), "State '4.0' should not match '3.0'"); + assertFalse(sut.stateEquals(7.0), "State '4.0' should not match '7.0'"); } @Test @@ -57,32 +60,32 @@ public class ItemTests { ColorItem sut = createItem(ColorItem::new); sut.setState(TupleHSB.of(1, 2, 3)); - Assert.assertTrue("State 'TupleHSB(1,2,3)' should match 'TupleHSB(1,2,3)'", - sut.stateEquals(TupleHSB.of(1, 2, 3))); - Assert.assertFalse("State 'TupleHSB(1,2,3)' should not match 'TupleHSB(1,2,4)'", - sut.stateEquals(TupleHSB.of(1, 2, 4))); - Assert.assertFalse("State 'TupleHSB(1,2,3)' should not match 'TupleHSB(9,2,3)'", - sut.stateEquals(TupleHSB.of(9, 2, 3))); - Assert.assertFalse("State 'TupleHSB(1,2,3)' should not match 'TupleHSB(1,17,3)'", - sut.stateEquals(TupleHSB.of(1, 17, 3))); - Assert.assertFalse("State 'TupleHSB(1,2,3)' should not match 'TupleHSB(99,99,3)'", - sut.stateEquals(TupleHSB.of(99, 99, 3))); - Assert.assertFalse("State 'TupleHSB(1,2,3)' should not match 'TupleHSB(5,5,5)'", - sut.stateEquals(TupleHSB.of(5, 5, 5))); + assertTrue(sut.stateEquals(TupleHSB.of(1, 2, 3)), + "State 'TupleHSB(1,2,3)' should match 'TupleHSB(1,2,3)'"); + assertFalse(sut.stateEquals(TupleHSB.of(1, 2, 4)), + "State 'TupleHSB(1,2,3)' should not match 'TupleHSB(1,2,4)'"); + assertFalse(sut.stateEquals(TupleHSB.of(9, 2, 3)), + "State 'TupleHSB(1,2,3)' should not match 'TupleHSB(9,2,3)'"); + assertFalse(sut.stateEquals(TupleHSB.of(1, 17, 3)), + "State 'TupleHSB(1,2,3)' should not match 'TupleHSB(1,17,3)'"); + assertFalse(sut.stateEquals(TupleHSB.of(99, 99, 3)), + "State 'TupleHSB(1,2,3)' should not match 'TupleHSB(99,99,3)'"); + assertFalse(sut.stateEquals(TupleHSB.of(5, 5, 5)), + "State 'TupleHSB(1,2,3)' should not match 'TupleHSB(5,5,5)'"); sut.setState(TupleHSB.of(347, 80, 95)); - Assert.assertTrue("State 'TupleHSB(357,80,95)' should match 'TupleHSB(357,80,95)'", - sut.stateEquals(TupleHSB.of(347, 80, 95))); - Assert.assertFalse("State 'TupleHSB(357,80,95)' should not match 'TupleHSB(1,2,4)'", - sut.stateEquals(TupleHSB.of(1, 2, 4))); - Assert.assertFalse("State 'TupleHSB(357,80,95)' should not match 'TupleHSB(9,2,3)'", - sut.stateEquals(TupleHSB.of(9, 2, 3))); - Assert.assertFalse("State 'TupleHSB(357,80,95)' should not match 'TupleHSB(1,17,3)'", - sut.stateEquals(TupleHSB.of(1, 17, 3))); - Assert.assertFalse("State 'TupleHSB(357,80,95)' should not match 'TupleHSB(99,99,3)'", - sut.stateEquals(TupleHSB.of(99, 99, 3))); - Assert.assertFalse("State 'TupleHSB(357,80,95)' should not match 'TupleHSB(5,5,5)'", - sut.stateEquals(TupleHSB.of(5, 5, 5))); + assertTrue(sut.stateEquals(TupleHSB.of(347, 80, 95)), + "State 'TupleHSB(357,80,95)' should match 'TupleHSB(357,80,95)'"); + assertFalse(sut.stateEquals(TupleHSB.of(1, 2, 4)), + "State 'TupleHSB(357,80,95)' should not match 'TupleHSB(1,2,4)'"); + assertFalse(sut.stateEquals(TupleHSB.of(9, 2, 3)), + "State 'TupleHSB(357,80,95)' should not match 'TupleHSB(9,2,3)'"); + assertFalse(sut.stateEquals(TupleHSB.of(1, 17, 3)), + "State 'TupleHSB(357,80,95)' should not match 'TupleHSB(1,17,3)'"); + assertFalse(sut.stateEquals(TupleHSB.of(99, 99, 3)), + "State 'TupleHSB(357,80,95)' should not match 'TupleHSB(99,99,3)'"); + assertFalse(sut.stateEquals(TupleHSB.of(5, 5, 5)), + "State 'TupleHSB(357,80,95)' should not match 'TupleHSB(5,5,5)'"); } @Test @@ -90,10 +93,10 @@ public class ItemTests { DateTimeItem sut = createItem(DateTimeItem::new); sut.setState(Instant.ofEpochMilli(1543415826)); - Assert.assertTrue("State 'Date(1543415826)' should match 'Date(1543415826)'", - sut.stateEquals(Instant.ofEpochMilli(1543415826))); - Assert.assertFalse("State 'Date(1543415826)' should not match 'Date(4)'", - sut.stateEquals(Instant.ofEpochMilli(4))); + assertTrue(sut.stateEquals(Instant.ofEpochMilli(1543415826)), + "State 'Date(1543415826)' should match 'Date(1543415826)'"); + assertFalse(sut.stateEquals(Instant.ofEpochMilli(4)), + "State 'Date(1543415826)' should not match 'Date(4)'"); } @FunctionalInterface diff --git a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/MarshallingTests.java b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/MarshallingTests.java index abcbd203be180e81b766bc48aa66cdb7778efae7..2c795bdb37a03f2be183203bc9e21eb63c115945 100644 --- a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/MarshallingTests.java +++ b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/MarshallingTests.java @@ -50,7 +50,6 @@ public class MarshallingTests { TestRunner.runTest(unitTest, properties); } - @SuppressWarnings("javadoc") @Parameterized.Parameters(name = "{0}") public static Iterable<Object[]> getTests() { return Util.getTests(properties); diff --git a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/MqttTests.java b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/MqttTests.java index 24a4f0b29b03fa7d20144b409ad989703b9b16cc..c58d70e71379deecad67710468412b05b52e558f 100644 --- a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/MqttTests.java +++ b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/MqttTests.java @@ -5,12 +5,11 @@ import de.tudresden.inf.st.eraser.util.MqttReceiver; import de.tudresden.inf.st.eraser.util.TestUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; @@ -21,14 +20,19 @@ import java.util.List; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; +import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.core.IsCollectionContaining.hasItem; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; /** * Test for everything related to MQTT. * * @author rschoene - Initial contribution */ -@RunWith(Parameterized.class) +//@RunWith(Parameterized.class) +@Disabled("Parameterized test still to be ported to junit5") public class MqttTests { private static final String outgoingPrefix = "out"; @@ -42,65 +46,69 @@ public class MqttTests { private List<String> messages = new ArrayList<>(); private static Logger logger = LogManager.getLogger(MqttTests.class); - @ClassRule +// @ClassRule public static GenericContainer mqttBroker = new GenericContainer<>("eclipse-mosquitto:1.5") .withExposedPorts(1883); - @Test - public void resolve1() { - ModelItemAndTwoTopics modelAB = createAB(); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void resolve1(boolean useStub) { + ModelItemAndTwoTopics modelAB = createAB(useStub); MqttRoot sut = modelAB.model.getRoot().getMqttRoot(); // incoming mqtt topic might be "inc/a/" or "inc/a/b" - Assert.assertTrue(sut.resolveTopic("inc/a").isPresent()); - Assert.assertEquals("Could not resolve a.", modelAB.firstTopic, sut.resolveTopic("inc/a").get()); - Assert.assertTrue(sut.resolveTopic("inc/a/b").isPresent()); - Assert.assertEquals("Could not resolve a/b.", modelAB.secondTopic, sut.resolveTopic("inc/a/b").get()); + assertTrue(sut.resolveTopic("inc/a").isPresent()); + assertEquals(modelAB.firstTopic, sut.resolveTopic("inc/a").get(), "Could not resolve a."); + assertTrue(sut.resolveTopic("inc/a/b").isPresent()); + assertEquals(modelAB.secondTopic, sut.resolveTopic("inc/a/b").get(), "Could not resolve a/b."); } - @Test - public void brokerConnected() throws Exception { - ModelItemAndTwoTopics modelAB = createAB(); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void brokerConnected(boolean useStub) throws Exception { + ModelItemAndTwoTopics modelAB = createAB(useStub); MqttRoot sut = modelAB.model.getRoot().getMqttRoot(); // MqttRoot mqttRoot = new MqttRoot(); // mqttRoot.setHostByName("localhost"); // MQTTSender sender = new MQTTSenderImpl().setHost(mqttRoot.getHost()); MQTTSender sender = sut.getMqttSender(); - Assume.assumeTrue("Broker is not connected", sender.isConnected()); -// Assert.assertTrue(sender.isConnected()); + assumeTrue(sender.isConnected(), "Broker is not connected"); +// assertTrue(sender.isConnected()); sender.publish("test", "me"); } - @Test - public void itemUpdateSend1() throws Exception { + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void itemUpdateSend1(boolean useStub) throws Exception { String expectedTopic = outgoingPrefix + "/" + firstPart + "/" + secondPart; - ModelItemAndTwoTopics modelAB = createAB(); + ModelItemAndTwoTopics modelAB = createAB(useStub); assertSenderConnected(modelAB); NumberItem sut = modelAB.item; sut.setTopic(modelAB.secondTopic); - createMqttReceiver(expectedTopic); + createMqttReceiver(useStub, expectedTopic); sut.setState(firstState); assertTimeoutEquals(2, 1, messages::size); - Assert.assertEquals(Double.toString(firstState), messages.get(0)); + assertEquals(Double.toString(firstState), messages.get(0)); sut.setState(secondState); assertTimeoutEquals(2, 2, messages::size); - Assert.assertEquals(Double.toString(secondState), messages.get(1)); + assertEquals(Double.toString(secondState), messages.get(1)); } - @Test - public void itemUpdateSend2() throws Exception { + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void itemUpdateSend2(boolean useStub) throws Exception { String expectedTopic1 = outgoingPrefix + "/" + firstPart + "/" + secondPart; String expectedTopic2 = outgoingPrefix + "/" + alternativeFirstPart + "/" + secondPart; - ModelItemAndTwoTopics modelAB = createAB(); + ModelItemAndTwoTopics modelAB = createAB(useStub); assertSenderConnected(modelAB); NumberItem item1 = modelAB.item; @@ -111,23 +119,23 @@ public class MqttTests { NumberItem item2 = TestUtils.addItemTo(modelAB.model, 0, true); item2.setTopic(alternativeB); - createMqttReceiver(expectedTopic1, expectedTopic2); + createMqttReceiver(useStub, expectedTopic1, expectedTopic2); item1.setState(firstState); item2.setState(firstState); assertTimeoutEquals(2, 2, messages::size); - Assert.assertEquals(Double.toString(firstState), messages.get(0)); - Assert.assertEquals(Double.toString(firstState), messages.get(1)); + assertEquals(Double.toString(firstState), messages.get(0)); + assertEquals(Double.toString(firstState), messages.get(1)); item1.setState(secondState); item2.setState(thirdState); assertTimeoutEquals(3, 4, messages::size); // TODO actually this does not test, whether the topic was correct for each state - Assert.assertThat(messages, hasItem(Double.toString(secondState))); - Assert.assertThat(messages, hasItem(Double.toString(thirdState))); + assertThat(messages).contains(Double.toString(secondState)); + assertThat(messages).contains(Double.toString(thirdState)); } private void assertSenderConnected(ModelItemAndTwoTopics modelAB) { @@ -140,10 +148,10 @@ public class MqttTests { logger.catching(e); } } - Assert.assertTrue("Broker is not connected", mqttRoot.getMqttSender().isConnected()); + assertTrue(mqttRoot.getMqttSender().isConnected(), "Broker is not connected"); } - private void createMqttReceiver(String... expectedTopics) throws IOException { + private void createMqttReceiver(boolean useStub, String... expectedTopics) throws IOException { if (useStub) { // do not need receiver, as messages are directly written by MqttSenderStub and callback return; @@ -154,14 +162,14 @@ public class MqttTests { receiver.setHost(mqttBroker.getContainerIpAddress(), mqttBroker.getFirstMappedPort()); receiver.setTopicsForSubscription(expectedTopics); receiver.setOnMessage((topic, message) -> { - Assert.assertThat(expectedTopicList, hasItem(topic)); + assertThat(expectedTopicList).contains(topic); messages.add(message); }); receiver.start(); receiver.waitUntilReady(2, TimeUnit.SECONDS); } - private ModelItemAndTwoTopics createAB() { + private ModelItemAndTwoTopics createAB(boolean useStub) { TestUtils.ModelAndItem mai = TestUtils.createModelAndItem(0, true); SmartHomeEntityModel model = mai.model; MqttRoot mqttRoot = new MqttRoot(); @@ -217,21 +225,7 @@ public class MqttTests { } } // final assessment, throw exception if not matched. Or pass, if previously matched. - Assert.assertEquals(expected, actualProvider.get()); - } - - @Parameterized.Parameter - public String name; - - @Parameterized.Parameter(1) - public boolean useStub; - - @Parameterized.Parameters(name = "{0}") - public static Iterable<Object[]> getTests() { - return Arrays.asList(new Object[][] { - {"Impl", false}, - {"Stub", true} - }); + assertEquals(expected, actualProvider.get()); } } diff --git a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/NeuralNetworkTest.java b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/NeuralNetworkTest.java index d4549f59ed2e50d1c2e0db2d3e0b3dd5303e8ed0..517cdd3fac64a612d7946d2d6f7a6a6a0f12c004 100644 --- a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/NeuralNetworkTest.java +++ b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/NeuralNetworkTest.java @@ -3,8 +3,10 @@ package de.tudresden.inf.st.eraser; import de.tudresden.inf.st.eraser.jastadd.model.*; import de.tudresden.inf.st.eraser.util.TestUtils; import de.tudresden.inf.st.eraser.util.TestUtils.ModelAndItem; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Testing the neuronal network aspect of the knowledge base. @@ -65,7 +67,7 @@ public class NeuralNetworkTest { } private void assertLeafEqual(int expected, Leaf actualLeaf) { - Assert.assertEquals(Double.toString(expected), actualLeaf.getLabel()); + assertEquals(Double.toString(expected), actualLeaf.getLabel()); } private Double combineBinaryValues(double[] outputs) { diff --git a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/OpenHabImporterTest.java b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/OpenHabImporterTest.java index ba45dfa3d2381c7a4778eea8314074401df25c93..926e92c6a35190ae8da71953a209aaf6a20ceb93 100644 --- a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/OpenHabImporterTest.java +++ b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/OpenHabImporterTest.java @@ -119,7 +119,6 @@ public class OpenHabImporterTest { OpenHabImportRunner.runTest(unitTest, properties); } - @SuppressWarnings("javadoc") @Parameterized.Parameters(name = "{0}") public static Iterable<Object[]> getTests() { return Util.getTests(properties); diff --git a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/RulesTest.java b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/RulesTest.java index fc01bb76bb022cfa0a5ff25113d9fc2957c0c3c0..28058d1149406248267307edacc043b46e765717 100644 --- a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/RulesTest.java +++ b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/RulesTest.java @@ -4,13 +4,9 @@ import beaver.Parser; import de.tudresden.inf.st.eraser.jastadd.model.*; import de.tudresden.inf.st.eraser.util.ParserUtils; import de.tudresden.inf.st.eraser.util.TestUtils; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Test; import java.io.IOException; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ScheduledFuture; @@ -18,12 +14,15 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.StreamSupport; +import static org.assertj.core.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * Testing the simple rule engine. * * @author rschoene - Initial contribution */ -@RunWith(Parameterized.class) public class RulesTest { private static final double DELTA = 0.01d; @@ -65,16 +64,16 @@ public class RulesTest { root.addRule(rule); rule.activateFor(item); - Assert.assertEquals(m("Counter not initialized correctly"), 0, counter.get(item)); + assertEquals(0, counter.get(item), "Counter not initialized correctly"); setState(item, 5); - Assert.assertEquals(m("Change of item state should trigger the rule"), 1, counter.get(item)); + assertEquals(1, counter.get(item), "Change of item state should trigger the rule"); setState(item, 5); - Assert.assertEquals(m("Set state to same value should not trigger the rule"), 1, counter.get(item)); + assertEquals(1, counter.get(item), "Set state to same value should not trigger the rule"); setState(item, 3); - Assert.assertEquals(m("Change of item state should trigger the rule"), 2, counter.get(item)); + assertEquals(2, counter.get(item), "Change of item state should trigger the rule"); } @Test @@ -89,12 +88,12 @@ public class RulesTest { rule.activateFor(item); rule.activateFor(item); - Assert.assertEquals(m("Rule was not activated exactly once (observer count)"), 1, rule.getObserverList().size()); + assertEquals(1, rule.getObserverList().size(), "Rule was not activated exactly once (observer count)"); int ruleCount = 0; for (ItemObserver observer : rule.getObserverList()) { ruleCount += observer.getTriggeredRuleList().size(); } - Assert.assertEquals(m("Rule was not activated exactly once (rule count)"), 1, ruleCount); + assertEquals(1, ruleCount, "Rule was not activated exactly once (rule count)"); } @Test @@ -116,20 +115,20 @@ public class RulesTest { ruleA.activateFor(item); ruleB.activateFor(item); - Assert.assertEquals(m("First counter not initialized correctly"), 0, counter1.get(item)); - Assert.assertEquals(m("Second counter not initialized correctly"), 0, counter2.get(item)); + assertEquals(0, counter1.get(item), "First counter not initialized correctly"); + assertEquals(0, counter2.get(item), "Second counter not initialized correctly"); setState(item, 5); - Assert.assertEquals(m("Change of item state should trigger the first rule"), 1, counter1.get(item)); - Assert.assertEquals(m("Change of item state should trigger the second rule"), 1, counter2.get(item)); + assertEquals(1, counter1.get(item), "Change of item state should trigger the first rule"); + assertEquals(1, counter2.get(item), "Change of item state should trigger the second rule"); setState(item, 5); - Assert.assertEquals(m("Set state to same value should not trigger the first rule"), 1, counter1.get(item)); - Assert.assertEquals(m("Set state to same value should not trigger the second rule"), 1, counter2.get(item)); + assertEquals(1, counter1.get(item), "Set state to same value should not trigger the first rule"); + assertEquals(1, counter2.get(item), "Set state to same value should not trigger the second rule"); setState(item, 3); - Assert.assertEquals(m("Change of item state should trigger the first rule"), 2, counter1.get(item)); - Assert.assertEquals(m("Change of item state should trigger the second rule"), 2, counter2.get(item)); + assertEquals(2, counter1.get(item), "Change of item state should trigger the first rule"); + assertEquals(2, counter2.get(item), "Change of item state should trigger the second rule"); } @Test @@ -137,7 +136,7 @@ public class RulesTest { TestUtils.ModelAndItem modelAndItem = createModelAndItem(4); Root root = modelAndItem.model.getRoot(); NumberItem item1 = modelAndItem.item; - NumberItem item2 = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 4, useUpdatingItem); + NumberItem item2 = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 4, true); Rule rule = new Rule(); CountingAction counter = new CountingAction(); @@ -148,47 +147,43 @@ public class RulesTest { rule.activateFor(item2); // Items: 4, 4. Expected counters: 0, 0. - Assert.assertEquals(m("Counter not initialized correctly for first item"), 0, counter.get(item1)); - Assert.assertEquals(m("Counter not initialized correctly for second item"), 0, counter.get(item2)); + assertEquals(0, counter.get(item1), "Counter not initialized correctly for first item"); + assertEquals(0, counter.get(item2), "Counter not initialized correctly for second item"); // Items: 5, 4. Expected counters: 1, 0. setState(item1, 5); - Assert.assertEquals(m("Change of first item state should trigger the rule once"), 1, counter.get(item1)); - Assert.assertEquals(m("Change of first item state should not trigger the rule for second item"), 0, counter.get(item2)); + assertEquals(1, counter.get(item1), "Change of first item state should trigger the rule once"); + assertEquals(0, counter.get(item2), "Change of first item state should not trigger the rule for second item"); // Items: 5, 4. Expected counters: 1, 0. setState(item1, 5); - Assert.assertEquals(m("Set state of first item to same value should not trigger the rule"), - 1, counter.get(item1)); - Assert.assertEquals(m("Change of first item state should not trigger the rule for second item"), 0, counter.get(item2)); + assertEquals(1, counter.get(item1), "Set state of first item to same value should not trigger the rule"); + assertEquals(0, counter.get(item2), "Change of first item state should not trigger the rule for second item"); // Items: 5, 3. Expected counters: 1, 1. setState(item2, 3); - Assert.assertEquals(m("Change of second item state should trigger the rule"), 1, counter.get(item2)); - Assert.assertEquals(m("Change of second item state should not trigger the rule for first item"), 1, counter.get(item1)); + assertEquals(1, counter.get(item2), "Change of second item state should trigger the rule"); + assertEquals(1, counter.get(item1), "Change of second item state should not trigger the rule for first item"); // Items: 5, 3. Expected counters: 1, 1. setState(item1, 5); - Assert.assertEquals(m("Set state of first item to same value should still not trigger the rule"), - 1, counter.get(item1)); - Assert.assertEquals(m("Change of first item state should still not trigger the rule for second item"), 1, counter.get(item2)); + assertEquals(1, counter.get(item1), "Set state of first item to same value should still not trigger the rule"); + assertEquals(1, counter.get(item2), "Change of first item state should still not trigger the rule for second item"); // Items: 6, 3. Expected counters: 2, 1. setState(item1, 6); - Assert.assertEquals(m("Set state of first item should trigger the rule"), - 2, counter.get(item1)); - Assert.assertEquals(m("Change of first item state should still not trigger the rule for second item"), 1, counter.get(item2)); + assertEquals(2, counter.get(item1), "Set state of first item should trigger the rule"); + assertEquals(1, counter.get(item2), "Change of first item state should still not trigger the rule for second item"); // Items: 6, 3. Expected counters: 2, 1. setState(item2, 3); - Assert.assertEquals(m("Set state of second item to same value should not trigger the rule"), - 1, counter.get(item2)); - Assert.assertEquals(m("Change of second item state should not trigger the rule for first item"), 2, counter.get(item1)); + assertEquals(1, counter.get(item2), "Set state of second item to same value should not trigger the rule"); + assertEquals(2, counter.get(item1), "Change of second item state should not trigger the rule for first item"); // Items: 6, 0. Expected counters: 2, 2. setState(item2, 0); - Assert.assertEquals(m("Change of second item state should trigger the rule"), 2, counter.get(item2)); - Assert.assertEquals(m("Change of second item state should not trigger the rule for first item"), 2, counter.get(item1)); + assertEquals(2, counter.get(item2), "Change of second item state should trigger the rule"); + assertEquals(2, counter.get(item1), "Change of second item state should not trigger the rule for first item"); } @Test @@ -204,15 +199,15 @@ public class RulesTest { rule.activateFor(item); - Assert.assertEquals(m("Counter not initialized correctly"), 0, counter.get(item)); + assertEquals(0, counter.get(item), "Counter not initialized correctly"); setState(item, 5); - Assert.assertEquals(m("Change of item state should trigger the rule"), 1, counter.get(item)); + assertEquals(1, counter.get(item), "Change of item state should trigger the rule"); rule.removeActivationOf(item); setState(item, 3); - Assert.assertEquals(m("Change of item state should not change the counter anymore"), 1, counter.get(item)); + assertEquals(1, counter.get(item), "Change of item state should not change the counter anymore"); } @Test @@ -231,22 +226,22 @@ public class RulesTest { root.addRule(rule); rule.activateFor(item); - Assert.assertEquals(m("Counter not initialized correctly"), 0, counter.get(item)); + assertEquals(0, counter.get(item), "Counter not initialized correctly"); setState(item, 3); - Assert.assertEquals(m("Change of item to 3 should not trigger the rule, check1 violated"), 0, counter.get(item)); + assertEquals(0, counter.get(item), "Change of item to 3 should not trigger the rule, check1 violated"); setState(item, 4); - Assert.assertEquals(m("Change of item to 4 should trigger the rule"), 1, counter.get(item)); + assertEquals(1, counter.get(item), "Change of item to 4 should trigger the rule"); setState(item, 5); - Assert.assertEquals(m("Change of item to 5 should trigger the rule"), 2, counter.get(item)); + assertEquals(2, counter.get(item), "Change of item to 5 should trigger the rule"); setState(item, 6); - Assert.assertEquals(m("Change of item to 6 should not trigger the rule, check2 violated"), 2, counter.get(item)); + assertEquals(2, counter.get(item), "Change of item to 6 should not trigger the rule, check2 violated"); setState(item, 7); - Assert.assertEquals(m("Change of item to 7 should not trigger the rule, check2 violated"), 2, counter.get(item)); + assertEquals(2, counter.get(item), "Change of item to 7 should not trigger the rule, check2 violated"); } @Test @@ -263,16 +258,16 @@ public class RulesTest { root.addRule(rule); rule.activateFor(item); - Assert.assertEquals(m("First counter not initialized correctly"), 0, counter1.get(item)); - Assert.assertEquals(m("Second counter not initialized correctly"), 0, counter2.get(item)); + assertEquals(0, counter1.get(item), "First counter not initialized correctly"); + assertEquals(0, counter2.get(item), "Second counter not initialized correctly"); setState(item, 3); - Assert.assertEquals(m("Change of item state should trigger the rule for first counter"), 1, counter1.get(item)); - Assert.assertEquals(m("Change of item state should trigger the rule for second counter"), 1, counter2.get(item)); + assertEquals(1, counter1.get(item), "Change of item state should trigger the rule for first counter"); + assertEquals(1, counter2.get(item), "Change of item state should trigger the rule for second counter"); setState(item, 3); - Assert.assertEquals(m("Change of item to same state should not trigger the rule for first counter"), 1, counter1.get(item)); - Assert.assertEquals(m("Change of item to same state should not trigger the rule for second counter"), 1, counter2.get(item)); + assertEquals(1, counter1.get(item), "Change of item to same state should not trigger the rule for first counter"); + assertEquals(1, counter2.get(item), "Change of item to same state should not trigger the rule for second counter"); } @Test @@ -280,7 +275,7 @@ public class RulesTest { TestUtils.ModelAndItem modelAndItem = createModelAndItem(2); Root root = modelAndItem.model.getRoot(); NumberItem item = modelAndItem.item; - NumberItem item2 = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 4, useUpdatingItem); + NumberItem item2 = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 4, true); Rule ruleA = new Rule(); CountingAction counter1 = new CountingAction(); @@ -297,25 +292,25 @@ public class RulesTest { ruleA.activateFor(item); ruleB.activateFor(item2); - Assert.assertEquals(m("First counter not initialized correctly for first item"), 0, counter1.get(item)); - Assert.assertEquals(m("First counter not initialized correctly for second item"), 0, counter1.get(item2)); - Assert.assertEquals(m("Second counter not initialized correctly for first item"), 0, counter2.get(item)); - Assert.assertEquals(m("Second counter not initialized correctly for second item"), 0, counter2.get(item2)); + assertEquals(0, counter1.get(item), "First counter not initialized correctly for first item"); + assertEquals(0, counter1.get(item2), "First counter not initialized correctly for second item"); + assertEquals(0, counter2.get(item), "Second counter not initialized correctly for first item"); + assertEquals(0, counter2.get(item2), "Second counter not initialized correctly for second item"); setState(item, 3); - Assert.assertEquals(m("Change of first item state should trigger the first rule"), 1, counter1.get(item)); - Assert.assertEquals(m("Change of first item state should trigger the second rule"), 1, counter2.get(item)); - Assert.assertEquals(m("Change of first item state should not trigger the second rule for second item"), 0, counter2.get(item2)); + assertEquals(1, counter1.get(item), "Change of first item state should trigger the first rule"); + assertEquals(1, counter2.get(item), "Change of first item state should trigger the second rule"); + assertEquals(0, counter2.get(item2), "Change of first item state should not trigger the second rule for second item"); setState(item, 3); - Assert.assertEquals(m("Change of item to same state should not trigger the first rule"), 1, counter1.get(item)); - Assert.assertEquals(m("Change of item to same state should not trigger the second rule"), 1, counter2.get(item)); - Assert.assertEquals(m("Change of first item state should not trigger the second rule for second item"), 0, counter2.get(item2)); + assertEquals(1, counter1.get(item), "Change of item to same state should not trigger the first rule"); + assertEquals(1, counter2.get(item), "Change of item to same state should not trigger the second rule"); + assertEquals(0, counter2.get(item2), "Change of first item state should not trigger the second rule for second item"); setState(item2, 7); - Assert.assertEquals(m("Change of second item state should not trigger the first rule"), 1, counter1.get(item)); - Assert.assertEquals(m("Change of second item state should not trigger the second rule for the first item"), 1, counter2.get(item)); - Assert.assertEquals(m("Change of second item state should trigger the second rule for the second item"), 1, counter2.get(item2)); + assertEquals(1, counter1.get(item), "Change of second item state should not trigger the first rule"); + assertEquals(1, counter2.get(item), "Change of second item state should not trigger the second rule for the first item"); + assertEquals(1, counter2.get(item2), "Change of second item state should trigger the second rule for the second item"); } @Test @@ -323,7 +318,7 @@ public class RulesTest { TestUtils.ModelAndItem modelAndItem = createModelAndItem(3); Root root = modelAndItem.model.getRoot(); NumberItem item = modelAndItem.item; - NumberItem item2 = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 4, useUpdatingItem); + NumberItem item2 = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 4, true); Rule rule = new Rule(); rule.addAction(new SetStateFromConstantStringAction(item2, "5")); @@ -332,13 +327,11 @@ public class RulesTest { root.addRule(rule); rule.activateFor(item); - Assert.assertEquals(m("Affected item not initialized correctly"), - 4, item2.asItemWithDoubleState().getState(), DELTA); + assertEquals(4, item2.asItemWithDoubleState().getState(), DELTA, "Affected item not initialized correctly"); setState(item, 25); - Assert.assertEquals(m("Change of item state should trigger the rule"), 1, counter.get(item)); - Assert.assertEquals(m("Change of item state should set the state of the affected item"), - 5, item2.asItemWithDoubleState().getState(), DELTA); + assertEquals(1, counter.get(item), "Change of item state should trigger the rule"); + assertEquals(5, item2.asItemWithDoubleState().getState(), DELTA, "Change of item state should set the state of the affected item"); } class ValuedStateProvider implements NewStateProvider { @@ -355,7 +348,7 @@ public class RulesTest { TestUtils.ModelAndItem modelAndItem = createModelAndItem(0); Root root = modelAndItem.model.getRoot(); NumberItem item = modelAndItem.item; - NumberItem item2 = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 3, useUpdatingItem); + NumberItem item2 = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 3, true); Rule rule = new Rule(); rule.addAction(new SetStateFromLambdaAction(item2, provider)); @@ -364,32 +357,27 @@ public class RulesTest { root.addRule(rule); rule.activateFor(item); - Assert.assertEquals(m("Affected item not initialized correctly"), - 3, item2.asItemWithDoubleState().getState(), DELTA); + assertEquals(3, item2.asItemWithDoubleState().getState(), DELTA, "Affected item not initialized correctly"); provider.value = 4; setState(item, 1); - Assert.assertEquals(m("Change of item state should trigger the rule"), 1, counter.get(item)); - Assert.assertEquals(m("Change of item state should set the state of the affected item"), - 4, item2.asItemWithDoubleState().getState(), DELTA); + assertEquals(1, counter.get(item), "Change of item state should trigger the rule"); + assertEquals(4, item2.asItemWithDoubleState().getState(), DELTA, "Change of item state should set the state of the affected item"); provider.value = 4; setState(item, 2); - Assert.assertEquals(m("Change of item state should trigger the rule"), 2, counter.get(item)); - Assert.assertEquals(m("Change of item state should set the state of the affected item"), - 4, item2.asItemWithDoubleState().getState(), DELTA); + assertEquals(2, counter.get(item), "Change of item state should trigger the rule"); + assertEquals(4, item2.asItemWithDoubleState().getState(), DELTA, "Change of item state should set the state of the affected item"); provider.value = 5; setState(item, 2); - Assert.assertEquals(m("Change of item to same state should not trigger the rule"), 2, counter.get(item)); - Assert.assertEquals(m("Change of item to same state should not set the state of the affected item"), - 4, item2.asItemWithDoubleState().getState(), DELTA); + assertEquals(2, counter.get(item), "Change of item to same state should not trigger the rule"); + assertEquals(4, item2.asItemWithDoubleState().getState(), DELTA, "Change of item to same state should not set the state of the affected item"); provider.value = 5; setState(item, 3); - Assert.assertEquals(m("Change of item state should trigger the rule"), 3, counter.get(item)); - Assert.assertEquals(m("Change of item state should set the state of the affected item"), - 5, item2.asItemWithDoubleState().getState(), DELTA); + assertEquals(3, counter.get(item), "Change of item state should trigger the rule"); + assertEquals(5, item2.asItemWithDoubleState().getState(), DELTA, "Change of item state should set the state of the affected item"); } @Test @@ -406,20 +394,20 @@ public class RulesTest { root.addRule(rule); rule.activateFor(item); - Assert.assertEquals(m("Counter not initialized correctly"), 0, counter.get(item)); - Assert.assertEquals(m("Affected item not initialized correctly"), "0", item2.getState()); + assertEquals(0, counter.get(item), "Counter not initialized correctly"); + assertEquals("0", item2.getState(), "Affected item not initialized correctly"); setState(item, 5); - Assert.assertEquals(m("Change of item state should trigger the rule"), 1, counter.get(item)); - Assert.assertEquals(m("Change of item state should set the state of the affected item"), "5.0", item2.getState()); + assertEquals(1, counter.get(item), "Change of item state should trigger the rule"); + assertEquals("5.0", item2.getState(), "Change of item state should set the state of the affected item"); setState(item, 5); - Assert.assertEquals(m("Change of item state should not trigger the rule"), 1, counter.get(item)); - Assert.assertEquals(m("Change of item state should not set the state of the affected item"), "5.0", item2.getState()); + assertEquals(1, counter.get(item), "Change of item state should not trigger the rule"); + assertEquals("5.0", item2.getState(), "Change of item state should not set the state of the affected item"); setState(item, 7); - Assert.assertEquals(m("Change of item state should trigger the rule"), 2, counter.get(item)); - Assert.assertEquals(m("Change of item state should set the state of the affected item"), "7.0", item2.getState()); + assertEquals(2, counter.get(item), "Change of item state should trigger the rule"); + assertEquals("7.0", item2.getState(), "Change of item state should set the state of the affected item"); } @Test @@ -427,7 +415,7 @@ public class RulesTest { TestUtils.ModelAndItem modelAndItem = createModelAndItem(3); Root root = modelAndItem.model.getRoot(); NumberItem item = modelAndItem.item; - NumberItem item2 = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 4, useUpdatingItem); + NumberItem item2 = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 4, true); StringItem affectedItem = addStringItem(root.getSmartHomeEntityModel(), "1"); Rule rule = new Rule(); @@ -444,49 +432,42 @@ public class RulesTest { root.addRule(rule); rule.activateFor(item); - Assert.assertEquals(m("Counter not initialized correctly"), 0, counter.get(item)); - Assert.assertEquals(m("Affected item not initialized correctly"), "1", - affectedItem.getState()); + assertEquals(0, counter.get(item), "Counter not initialized correctly"); + assertEquals("1", affectedItem.getState(), "Affected item not initialized correctly"); // 5 + 4 = 9 setState(item, 5); - Assert.assertEquals(m("Change of item state should trigger the rule"), 1, counter.get(item)); - Assert.assertEquals(m("Change of item state should set the state of the affected item"), - "9", affectedItem.getState()); + assertEquals(1, counter.get(item), "Change of item state should trigger the rule"); + assertEquals("9", affectedItem.getState(), "Change of item state should set the state of the affected item"); // still 5 + 4 = 9, as rule does not trigger for item2 setState(item2, 5); - Assert.assertEquals(m("Change of item2 state should not trigger the rule"), 1, counter.get(item)); - Assert.assertEquals(m("Change of item2 state should not set the state of the affected item"), - "9", affectedItem.getState()); + assertEquals(1, counter.get(item), "Change of item2 state should not trigger the rule"); + assertEquals("9", affectedItem.getState(), "Change of item2 state should not set the state of the affected item"); // still 5 + 4 = 9, as rule should not trigger setState(item, 5); - Assert.assertEquals(m("Change of item to same state should not trigger the rule"), 1, counter.get(item)); - Assert.assertEquals(m("Change of item to same state should not set the state of the affected item"), - "9", affectedItem.getState()); + assertEquals(1, counter.get(item), "Change of item to same state should not trigger the rule"); + assertEquals("9", affectedItem.getState(), "Change of item to same state should not set the state of the affected item"); // 7 + 5 = 12 setState(item, 7); - Assert.assertEquals(m("Change of item state should trigger the rule"), 2, counter.get(item)); - Assert.assertEquals(m("Change of item state should set the state of the affected item"), - "12", affectedItem.getState()); + assertEquals(2, counter.get(item), "Change of item state should trigger the rule"); + assertEquals("12", affectedItem.getState(), "Change of item state should set the state of the affected item"); // add new item to sum - NumberItem item3 = TestUtils.addItemTo(root.getSmartHomeEntityModel(), -4, useUpdatingItem); + NumberItem item3 = TestUtils.addItemTo(root.getSmartHomeEntityModel(), -4, true); action.addSourceItem(item3); // still 7 + 5 = 12, as rule should not trigger setState(item, 7); - Assert.assertEquals(m("Change of item to same state should not trigger the rule"), 2, counter.get(item)); - Assert.assertEquals(m("Change of item to same state should not set the state of the affected item"), - "12", affectedItem.getState()); + assertEquals(2, counter.get(item), "Change of item to same state should not trigger the rule"); + assertEquals("12", affectedItem.getState(), "Change of item to same state should not set the state of the affected item"); // 8 + 5 - 4 = 9 setState(item, 8); - Assert.assertEquals(m("Change of item state should trigger the rule"), 3, counter.get(item)); - Assert.assertEquals(m("Change of item state should set the state of the affected item"), - "9", affectedItem.getState()); + assertEquals(3, counter.get(item), "Change of item state should trigger the rule"); + assertEquals("9", affectedItem.getState(), "Change of item state should set the state of the affected item"); } @Test @@ -494,7 +475,7 @@ public class RulesTest { TestUtils.ModelAndItem modelAndItem = createModelAndItem(3); Root root = modelAndItem.model.getRoot(); NumberItem item = modelAndItem.item; - NumberItem affectedItem = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 4, useUpdatingItem); + NumberItem affectedItem = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 4, true); Rule rule = new Rule(); rule.addAction(new AddDoubleToStateAction(affectedItem, 2)); @@ -503,27 +484,23 @@ public class RulesTest { root.addRule(rule); rule.activateFor(item); - Assert.assertEquals(m("Counter not initialized correctly"), 0, counter.get(item)); - Assert.assertEquals(m("Affected item not initialized correctly"), - 4, affectedItem.getState(), DELTA); + assertEquals(0, counter.get(item), "Counter not initialized correctly"); + assertEquals(4, affectedItem.getState(), DELTA, "Affected item not initialized correctly"); // 4 + 2 = 6 setState(item, 5); - Assert.assertEquals(m("Change of item state should trigger the rule"), 1, counter.get(item)); - Assert.assertEquals(m("Change of item state should set the state of the affected item"), - 6, affectedItem.getState(), DELTA); + assertEquals(1, counter.get(item), "Change of item state should trigger the rule"); + assertEquals(6, affectedItem.getState(), DELTA, "Change of item state should set the state of the affected item"); // still 6 setState(item, 5); - Assert.assertEquals(m("Change of item to same state should not trigger the rule"), 1, counter.get(item)); - Assert.assertEquals(m("Change of item to same state should not set the state of the affected item"), - 6, affectedItem.getState(), DELTA); + assertEquals(1, counter.get(item), "Change of item to same state should not trigger the rule"); + assertEquals(6, affectedItem.getState(), DELTA, "Change of item to same state should not set the state of the affected item"); // 6 + 2 = 8 setState(item, -2); - Assert.assertEquals(m("Change of item state should trigger the rule"), 2, counter.get(item)); - Assert.assertEquals(m("Change of item state should set the state of the affected item"), - 8, affectedItem.getState(), DELTA); + assertEquals(2, counter.get(item), "Change of item state should trigger the rule"); + assertEquals(8, affectedItem.getState(), DELTA, "Change of item state should set the state of the affected item"); } @Test @@ -531,7 +508,7 @@ public class RulesTest { TestUtils.ModelAndItem modelAndItem = createModelAndItem(3); Root root = modelAndItem.model.getRoot(); NumberItem item = modelAndItem.item; - NumberItem affectedItem = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 4, useUpdatingItem); + NumberItem affectedItem = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 4, true); Rule rule = new Rule(); rule.addAction(new MultiplyDoubleToStateAction(affectedItem, 2)); @@ -540,27 +517,23 @@ public class RulesTest { root.addRule(rule); rule.activateFor(item); - Assert.assertEquals(m("Counter not initialized correctly"), 0, counter.get(item)); - Assert.assertEquals(m("Affected item not initialized correctly"), - 4, affectedItem.getState(), DELTA); + assertEquals(0, counter.get(item), "Counter not initialized correctly"); + assertEquals(4, affectedItem.getState(), DELTA, "Affected item not initialized correctly"); // 4 * 2 = 8 setState(item, 5); - Assert.assertEquals(m("Change of item state should trigger the rule"), 1, counter.get(item)); - Assert.assertEquals(m("Change of item state should set the state of the affected item"), - 8, affectedItem.getState(), DELTA); + assertEquals(1, counter.get(item), "Change of item state should trigger the rule"); + assertEquals(8, affectedItem.getState(), DELTA, "Change of item state should set the state of the affected item"); // still 8 setState(item, 5); - Assert.assertEquals(m("Change of item to same state should not trigger the rule"), 1, counter.get(item)); - Assert.assertEquals(m("Change of item to same state should not set the state of the affected item"), - 8, affectedItem.getState(), DELTA); + assertEquals(1, counter.get(item), "Change of item to same state should not trigger the rule"); + assertEquals(8, affectedItem.getState(), DELTA, "Change of item to same state should not set the state of the affected item"); // 8 * 2 = 16 setState(item, 0); - Assert.assertEquals(m("Change of item state should trigger the rule"), 2, counter.get(item)); - Assert.assertEquals(m("Change of item state should set the state of the affected item"), - 16, affectedItem.getState(), DELTA); + assertEquals(2, counter.get(item), "Change of item state should trigger the rule"); + assertEquals(16, affectedItem.getState(), DELTA, "Change of item state should set the state of the affected item"); } @Test @@ -568,8 +541,8 @@ public class RulesTest { TestUtils.ModelAndItem modelAndItem = createModelAndItem(3); Root root = modelAndItem.model.getRoot(); NumberItem item1 = modelAndItem.item; - NumberItem item2 = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 4, useUpdatingItem); - NumberItem affectedItem = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 5, useUpdatingItem); + NumberItem item2 = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 4, true); + NumberItem affectedItem = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 5, true); Rule ruleA = new Rule(); ruleA.addAction(new AddDoubleToStateAction(affectedItem, 2)); @@ -588,34 +561,30 @@ public class RulesTest { ruleA.activateFor(item1); ruleB.activateFor(item2); - Assert.assertEquals(m("CounterA not initialized correctly for first item"), 0, counterA.get(item1)); - Assert.assertEquals(m("CounterA not initialized correctly for second item"), 0, counterA.get(item2)); - Assert.assertEquals(m("CounterB not initialized correctly for first item"), 0, counterB.get(item1)); - Assert.assertEquals(m("CounterB not initialized correctly for second item"), 0, counterB.get(item2)); - Assert.assertEquals(m("Affected item not initialized correctly"), - 5, affectedItem.getState(), DELTA); + assertEquals(0, counterA.get(item1), "CounterA not initialized correctly for first item"); + assertEquals(0, counterA.get(item2), "CounterA not initialized correctly for second item"); + assertEquals(0, counterB.get(item1), "CounterB not initialized correctly for first item"); + assertEquals(0, counterB.get(item2), "CounterB not initialized correctly for second item"); + assertEquals(5, affectedItem.getState(), DELTA, "Affected item not initialized correctly"); // First, 5 + 2 = 7. Then, 7 * 3 = 21 setState(item1, 5); - Assert.assertEquals(m("Change of item state should trigger the ruleA"), 1, counterA.get(item1)); - Assert.assertEquals(m("Change of item state should also trigger the ruleB"), 1, counterB.get(item1)); - Assert.assertEquals(m("Change of item state should set the state of the affected item"), - 21, affectedItem.getState(), DELTA); + assertEquals(1, counterA.get(item1), "Change of item state should trigger the ruleA"); + assertEquals(1, counterB.get(item1), "Change of item state should also trigger the ruleB"); + assertEquals(21, affectedItem.getState(), DELTA, "Change of item state should set the state of the affected item"); // still 21 setState(item1, 5); - Assert.assertEquals(m("Change of item to same state should not trigger the ruleA"), 1, counterA.get(item1)); - Assert.assertEquals(m("Change of item to same state should not trigger the ruleB"), 1, counterB.get(item1)); - Assert.assertEquals(m("Change of item to same state should not set the state of the affected item"), - 21, affectedItem.getState(), DELTA); + assertEquals(1, counterA.get(item1), "Change of item to same state should not trigger the ruleA"); + assertEquals(1, counterB.get(item1), "Change of item to same state should not trigger the ruleB"); + assertEquals(21, affectedItem.getState(), DELTA, "Change of item to same state should not set the state of the affected item"); // Only, 21 * 3 = 63 setState(item2, 1); - Assert.assertEquals(m("Change of second item state should not trigger the ruleA"), 1, counterA.get(item1)); - Assert.assertEquals(m("Change of second item state should not trigger the ruleB for first item"), 1, counterB.get(item1)); - Assert.assertEquals(m("Change of second item state should trigger the ruleB for second item"), 1, counterB.get(item2)); - Assert.assertEquals(m("Change of second item state should set the state of the affected item"), - 63, affectedItem.getState(), DELTA); + assertEquals(1, counterA.get(item1), "Change of second item state should not trigger the ruleA"); + assertEquals(1, counterB.get(item1), "Change of second item state should not trigger the ruleB for first item"); + assertEquals(1, counterB.get(item2), "Change of second item state should trigger the ruleB for second item"); + assertEquals(63, affectedItem.getState(), DELTA, "Change of second item state should set the state of the affected item"); } @Test @@ -623,8 +592,8 @@ public class RulesTest { TestUtils.ModelAndItem modelAndItem = createModelAndItem(3); Root root = modelAndItem.model.getRoot(); NumberItem item1 = modelAndItem.item; - NumberItem item2 = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 4, useUpdatingItem); - NumberItem affectedItem = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 5, useUpdatingItem); + NumberItem item2 = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 4, true); + NumberItem affectedItem = TestUtils.addItemTo(root.getSmartHomeEntityModel(), 5, true); Rule rule = new Rule(); SetStateFromExpression action = new SetStateFromExpression(); @@ -638,35 +607,29 @@ public class RulesTest { root.addRule(rule); rule.activateFor(item1); - Assert.assertEquals(m("Counter not initialized correctly"), 0, counter.get(item1)); - Assert.assertEquals(m("Second item not initialized correctly"), - 4, item2.getState(), DELTA); - Assert.assertEquals(m("Affected item not initialized correctly"), - 5, affectedItem.getState(), DELTA); + assertEquals(0, counter.get(item1), "Counter not initialized correctly"); + assertEquals(4, item2.getState(), DELTA, "Second item not initialized correctly"); + assertEquals(5, affectedItem.getState(), DELTA, "Affected item not initialized correctly"); // 5 + 4 = 9 setState(item1, 5); - Assert.assertEquals(m("Change of item state should trigger the rule"), 1, counter.get(item1)); - Assert.assertEquals(m("Change of item state should set the state of the affected item"), - 9, affectedItem.getState(), DELTA); + assertEquals(1, counter.get(item1), "Change of item state should trigger the rule"); + assertEquals(9, affectedItem.getState(), DELTA, "Change of item state should set the state of the affected item"); // still 9 setState(item1, 5); - Assert.assertEquals(m("Change of item to same state should not trigger the rule"), 1, counter.get(item1)); - Assert.assertEquals(m("Change of item to same state should not set the state of the affected item"), - 9, affectedItem.getState(), DELTA); + assertEquals(1, counter.get(item1), "Change of item to same state should not trigger the rule"); + assertEquals(9, affectedItem.getState(), DELTA, "Change of item to same state should not set the state of the affected item"); // still 9 (changes of item2 do not trigger the rule) setState(item2, 1); - Assert.assertEquals(m("Change of second item to same state should not trigger the rule"), 1, counter.get(item1)); - Assert.assertEquals(m("Change of second item to same state should not set the state of the affected item"), - 9, affectedItem.getState(), DELTA); + assertEquals(1, counter.get(item1), "Change of second item to same state should not trigger the rule"); + assertEquals(9, affectedItem.getState(), DELTA, "Change of second item to same state should not set the state of the affected item"); // 0 + 1 = 1 setState(item1, 0); - Assert.assertEquals(m("Change of item state should trigger the rule"), 2, counter.get(item1)); - Assert.assertEquals(m("Change of item state should set the state of the affected item"), - 1, affectedItem.getState(), DELTA); + assertEquals(2, counter.get(item1), "Change of item state should trigger the rule"); + assertEquals(1, affectedItem.getState(), DELTA, "Change of item state should set the state of the affected item"); } @Test @@ -675,26 +638,26 @@ public class RulesTest { CountingAction counter = new CountingAction(); rule.addAction(counter); - Assert.assertEquals(m("Counter not initialized correctly"), 0, counter.get(null)); + assertEquals(0, counter.get(null), "Counter not initialized correctly"); ScheduledFuture f = rule.activateEvery(50, TimeUnit.MILLISECONDS); waitMillis(160); - Assert.assertTrue("Rule cron job could not be cancelled", f.cancel(true)); + assertTrue(f.cancel(true), "Rule cron job could not be cancelled"); // ----------------------- 160ms ----------------------- // + -- 50ms -- + -- 50ms -- + -- 50 ms -- + -- 10 ms -- // 4 times executed (+), with no initial delay - Assert.assertEquals(m("Rule was not executed four times"), 4, counter.get(null)); + assertEquals(4, counter.get(null), "Rule was not executed four times"); counter.reset(); - Assert.assertEquals(m("Counter not reset correctly"), 0, counter.get(null)); + assertEquals(0, counter.get(null), "Counter not reset correctly"); f = rule.activateEvery(80, 50, TimeUnit.MILLISECONDS); waitMillis(150); - Assert.assertTrue("Rule cron job could not be cancelled", f.cancel(true)); + assertTrue(f.cancel(true), "Rule cron job could not be cancelled"); // ------------------ 150ms ------------------ // ----- 80ms ----- + -- 50ms -- + -- 20 ms -- // 2 times executed (+), with given delay - Assert.assertEquals(m("Rule was not executed two times"), 2, counter.get(null)); + assertEquals(2, counter.get(null), "Rule was not executed two times"); } private static void waitMillis(int millis) { @@ -702,14 +665,10 @@ public class RulesTest { Thread.sleep(millis); } catch (InterruptedException e) { e.printStackTrace(); - Assert.fail("Sleeping was interrupted!"); + fail("Sleeping was interrupted!"); } } - private String m(String message) { - return message + " (Using " + name + ")"; - } - private StringItem addStringItem(SmartHomeEntityModel model, String initialValue) { StringItem item = new StringItem(); Group group = TestUtils.getDefaultGroup(model); @@ -720,28 +679,11 @@ public class RulesTest { } private TestUtils.ModelAndItem createModelAndItem(long initialValue) { - return TestUtils.createModelAndItem(initialValue, useUpdatingItem); + return TestUtils.createModelAndItem(initialValue, true); } private void setState(NumberItem item, long newState) { item.setState(newState); - if (!useUpdatingItem && item.hasItemObserver()) { - item.getItemObserver().apply(); - } - } - - @Parameterized.Parameter - public String name; - - @Parameterized.Parameter(1) - public boolean useUpdatingItem; - - @Parameterized.Parameters(name = "{0}") - public static Iterable<Object[]> getTests() { - return Arrays.asList(new Object[][] { -// {"Normal Item", false}, - {"Updating Item", true} - }); } } diff --git a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/jastadd_test/core/TupleHSBTest.java b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/jastadd_test/core/TupleHSBTest.java index b5be25e56f54a0b10bc1acb1547b21fe30c5671f..6976a52dd32ef2bbe7e5e5451afc64fcbd5deeaa 100644 --- a/eraser-base/src/test/java/de/tudresden/inf/st/eraser/jastadd_test/core/TupleHSBTest.java +++ b/eraser-base/src/test/java/de/tudresden/inf/st/eraser/jastadd_test/core/TupleHSBTest.java @@ -1,11 +1,11 @@ package de.tudresden.inf.st.eraser.jastadd_test.core; import de.tudresden.inf.st.eraser.jastadd.model.TupleHSB; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; /** * Testing the class {@link de.tudresden.inf.st.eraser.jastadd.model.TupleHSB}. @@ -32,18 +32,18 @@ public class TupleHSBTest { TupleHSB one = TupleHSB.of(1,2,3); TupleHSB two = TupleHSB.of(1,2,3); TupleHSB three = TupleHSB.of(99,99,99); - Assert.assertEquals(one, two); - Assert.assertNotEquals(one, three); - Assert.assertNotEquals(two, three); + assertEquals(one, two); + assertNotEquals(one, three); + assertNotEquals(two, three); TupleHSB oneEqualModuloHue = TupleHSB.of(361,2,3); - Assert.assertEquals(one, oneEqualModuloHue); + assertEquals(one, oneEqualModuloHue); TupleHSB bigSB = TupleHSB.of(50,100,100); TupleHSB biggerS = TupleHSB.of(50,123,100); TupleHSB biggerB = TupleHSB.of(50,123,6484); - Assert.assertEquals(bigSB, biggerS); - Assert.assertEquals(bigSB, biggerB); + assertEquals(bigSB, biggerS); + assertEquals(bigSB, biggerB); } @Test @@ -54,36 +54,36 @@ public class TupleHSBTest { TupleHSB oneDifferentBrightness = one.withDifferentBrightness(43); TupleHSB oneEqualModuloHue = one.withDifferentHue(721); - Assert.assertNotEquals(one, oneDifferentHue); - Assert.assertNotEquals(one, oneDifferentSaturation); - Assert.assertNotEquals(one, oneDifferentBrightness); - Assert.assertNotEquals(oneDifferentHue, oneDifferentSaturation); - Assert.assertNotEquals(oneDifferentHue, oneDifferentBrightness); - Assert.assertNotEquals(oneDifferentSaturation, oneDifferentBrightness); + assertNotEquals(one, oneDifferentHue); + assertNotEquals(one, oneDifferentSaturation); + assertNotEquals(one, oneDifferentBrightness); + assertNotEquals(oneDifferentHue, oneDifferentSaturation); + assertNotEquals(oneDifferentHue, oneDifferentBrightness); + assertNotEquals(oneDifferentSaturation, oneDifferentBrightness); - Assert.assertEquals(one, oneEqualModuloHue); + assertEquals(one, oneEqualModuloHue); } @Test public void testPrint() { TupleHSB one = TupleHSB.of(1,2,3); String expectedForOne = "1,2,3"; - Assert.assertEquals(expectedForOne, one.toString()); + assertEquals(expectedForOne, one.toString()); TupleHSB two = TupleHSB.of(341,92,555); String expectedForTwo = "341,92,100"; - Assert.assertEquals(expectedForTwo, two.toString()); + assertEquals(expectedForTwo, two.toString()); } @Test public void testParse() { String one = "3,2,1"; TupleHSB expectedForOne = TupleHSB.of(3, 2, 1); - Assert.assertEquals(expectedForOne, TupleHSB.parse(one)); + assertEquals(expectedForOne, TupleHSB.parse(one)); String two = "399,201,17"; TupleHSB expectedForTwo = TupleHSB.of(39, 100, 17); - Assert.assertEquals(expectedForTwo, TupleHSB.parse(two)); + assertEquals(expectedForTwo, TupleHSB.parse(two)); } @Test @@ -92,18 +92,18 @@ public class TupleHSBTest { TupleHSB two = TupleHSB.of(50,123,100); TupleHSB clone = one.clone(); - Assert.assertEquals(one, clone); - Assert.assertNotEquals(one, two); - Assert.assertNotEquals(clone, two); + assertEquals(one, clone); + assertNotEquals(one, two); + assertNotEquals(clone, two); } private void checkWithinBounds(TupleHSB hsb) { - Assert.assertThat(hsb.getHue(), greaterThanOrEqualTo(0)); - Assert.assertThat(hsb.getHue(), lessThanOrEqualTo(360)); - Assert.assertThat(hsb.getSaturation(), greaterThanOrEqualTo(0)); - Assert.assertThat(hsb.getSaturation(), lessThanOrEqualTo(100)); - Assert.assertThat(hsb.getBrightness(), greaterThanOrEqualTo(0)); - Assert.assertThat(hsb.getBrightness(), lessThanOrEqualTo(100)); + assertThat(hsb.getHue()).isGreaterThanOrEqualTo(0); + assertThat(hsb.getHue()).isLessThanOrEqualTo(360); + assertThat(hsb.getSaturation()).isGreaterThanOrEqualTo(0); + assertThat(hsb.getSaturation()).isLessThanOrEqualTo(100); + assertThat(hsb.getBrightness()).isGreaterThanOrEqualTo(0); + assertThat(hsb.getBrightness()).isLessThanOrEqualTo(100); } } diff --git a/eraser.spark/build.gradle b/eraser.spark/build.gradle index e4012910f534331674e6fef88ecff0202d00e97c..127435058c97e8edd94d75fc6f3cfd07720d15cf 100644 --- a/eraser.spark/build.gradle +++ b/eraser.spark/build.gradle @@ -1,12 +1,12 @@ plugins { id 'eraser.java-application-conventions' - id 'io.franzbecker.gradle-lombok' version '3.0.0' + id 'io.franzbecker.gradle-lombok' version "${gradle_lombok_version}" } dependencies { implementation project(':eraser-base') - implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.11.2' - implementation group: 'com.sparkjava', name: 'spark-core', version: '2.9.0' + implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: "${log4j_version}" + implementation group: 'com.sparkjava', name: 'spark-core', version: '2.9.3' } application.mainClass = 'de.tudresden.inf.st.eraser.spark.Application' diff --git a/feedbackloop.api/build.gradle b/feedbackloop.api/build.gradle index f4a30208fd328727ddfb07201b16d1093f8b70df..3e04a280611187df9be8e81ece074a9352dc2c13 100644 --- a/feedbackloop.api/build.gradle +++ b/feedbackloop.api/build.gradle @@ -1,6 +1,6 @@ plugins { id 'eraser.java-common-conventions' - id 'io.franzbecker.gradle-lombok' version '3.0.0' + id 'io.franzbecker.gradle-lombok' version "${gradle_lombok_version}" } dependencies { diff --git a/feedbackloop.execute/src/test/java/de/tudresden/inf/st/eraser/feedbackloop/execute/ExecuteImplTest.java b/feedbackloop.execute/src/test/java/de/tudresden/inf/st/eraser/feedbackloop/execute/ExecuteImplTest.java index 109ff59b56256e32b1aa4a53c10dfa690881f63f..1ea42c30dbce19cb979dfa4d19f8c52ae5cbf16e 100644 --- a/feedbackloop.execute/src/test/java/de/tudresden/inf/st/eraser/feedbackloop/execute/ExecuteImplTest.java +++ b/feedbackloop.execute/src/test/java/de/tudresden/inf/st/eraser/feedbackloop/execute/ExecuteImplTest.java @@ -4,11 +4,12 @@ import de.tudresden.inf.st.eraser.feedbackloop.api.Execute; import de.tudresden.inf.st.eraser.jastadd.model.*; import de.tudresden.inf.st.eraser.util.TestUtils; import de.tudresden.inf.st.eraser.util.TestUtils.ModelAndItem; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; +import static org.junit.jupiter.api.Assertions.*; + /** * Test updating items within the Execute component. * @@ -35,14 +36,14 @@ public class ExecuteImplTest { Execute execute = new ExecuteImpl(); execute.setKnowledgeBase(model.getRoot()); - Assert.assertEquals(0, numberItem.getState(), DELTA); - Assert.assertEquals(TupleHSB.of(0, 0, 0), lamp.getState()); + assertEquals(0, numberItem.getState(), DELTA); + assertEquals(TupleHSB.of(0, 0, 0), lamp.getState()); ItemUpdate preference = new ItemUpdateColor(lamp, TupleHSB.of(1, 2, 3)); execute.updateItems(Collections.singletonList(preference)); - Assert.assertEquals(3, numberItem.getState(), DELTA); - Assert.assertEquals(TupleHSB.of(1, 2, 3), lamp.getState()); + assertEquals(3, numberItem.getState(), DELTA); + assertEquals(TupleHSB.of(1, 2, 3), lamp.getState()); } @Test @@ -66,14 +67,14 @@ public class ExecuteImplTest { Execute execute = new ExecuteImpl(); execute.setKnowledgeBase(model.getRoot()); - Assert.assertFalse(button.getState()); - Assert.assertEquals(TupleHSB.of(0, 0, 0), lamp.getState()); + assertFalse(button.getState()); + assertEquals(TupleHSB.of(0, 0, 0), lamp.getState()); ItemUpdate preference = new ItemUpdateColor(lamp, TupleHSB.of(1, 2, 3)); execute.updateItems(Collections.singletonList(preference)); - Assert.assertTrue(button.getState()); - Assert.assertEquals(TupleHSB.of(1, 2, 3), lamp.getState()); + assertTrue(button.getState()); + assertEquals(TupleHSB.of(1, 2, 3), lamp.getState()); } @Test @@ -110,20 +111,20 @@ public class ExecuteImplTest { Execute execute = new ExecuteImpl(); execute.setKnowledgeBase(model.getRoot()); - Assert.assertEquals(0, numberItem.getState(), DELTA); - Assert.assertEquals("0", stringItem.getState()); - Assert.assertFalse(booleanItem.getState()); - Assert.assertEquals(TupleHSB.of(0, 0, 0), colorItem.getState()); - Assert.assertEquals(TupleHSB.of(0, 0, 0), lamp.getState()); + assertEquals(0, numberItem.getState(), DELTA); + assertEquals("0", stringItem.getState()); + assertFalse(booleanItem.getState()); + assertEquals(TupleHSB.of(0, 0, 0), colorItem.getState()); + assertEquals(TupleHSB.of(0, 0, 0), lamp.getState()); ItemUpdate preference = new ItemUpdateColor(lamp, TupleHSB.of(1, 2, 3)); execute.updateItems(Collections.singletonList(preference)); - Assert.assertEquals(3, numberItem.getState(), DELTA); - Assert.assertEquals("1,2,3", stringItem.getState()); - Assert.assertTrue(booleanItem.getState()); - Assert.assertEquals(TupleHSB.of(1, 2, 3), colorItem.getState()); - Assert.assertEquals(TupleHSB.of(1, 2, 3), lamp.getState()); + assertEquals(3, numberItem.getState(), DELTA); + assertEquals("1,2,3", stringItem.getState()); + assertTrue(booleanItem.getState()); + assertEquals(TupleHSB.of(1, 2, 3), colorItem.getState()); + assertEquals(TupleHSB.of(1, 2, 3), lamp.getState()); } } diff --git a/feedbackloop.learner_backup/build.gradle b/feedbackloop.learner_backup/build.gradle index b4800381bf8d804eaf716a98b09ff165dc77eae2..3cc29f284c90d32499bb2fae65ee82693d52bf39 100644 --- a/feedbackloop.learner_backup/build.gradle +++ b/feedbackloop.learner_backup/build.gradle @@ -1,14 +1,14 @@ plugins { id 'eraser.java-application-conventions' - id 'io.franzbecker.gradle-lombok' version '3.0.0' + id 'io.franzbecker.gradle-lombok' version "${gradle_lombok_version}" } dependencies { implementation project(':eraser-base') implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "${jackson_version}" implementation group: 'org.encog', name: 'encog-core', version: '3.4' - implementation group: 'com.opencsv', name: 'opencsv', version: '4.1' - implementation group: 'commons-io', name: 'commons-io', version: '2.5' + implementation group: 'com.opencsv', name: 'opencsv', version: '5.3' + implementation group: 'commons-io', name: 'commons-io', version: '2.8.0' implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: "${apache_httpcomponents_version}" implementation group: 'org.apache.httpcomponents', name: 'fluent-hc', version: "${apache_httpcomponents_version}" // https://mvnrepository.com/artifact/org.apache.spark/spark-mllib diff --git a/feedbackloop.learner_backup/src/test/java/de/tudresden/inf/st/eraser/feedbackloop/learner_backup/LearnerTest.java b/feedbackloop.learner_backup/src/test/java/de/tudresden/inf/st/eraser/feedbackloop/learner_backup/LearnerTest.java index 7457ed7ac8c4e81cc84104b39d9f965b4308da7d..51e2df578ab77fd2cc25868ccb9779b04cb76051 100644 --- a/feedbackloop.learner_backup/src/test/java/de/tudresden/inf/st/eraser/feedbackloop/learner_backup/LearnerTest.java +++ b/feedbackloop.learner_backup/src/test/java/de/tudresden/inf/st/eraser/feedbackloop/learner_backup/LearnerTest.java @@ -1,10 +1,10 @@ package de.tudresden.inf.st.eraser.feedbackloop.learner_backup; import de.tudresden.inf.st.eraser.jastadd.model.Item; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.net.MalformedURLException; @@ -34,7 +34,7 @@ public class LearnerTest { private static URL OCT_ACTIVITY_DATA; private LearnerSubjectUnderTest sut; - @BeforeClass + @BeforeAll public static void setData() throws MalformedURLException { ACTIVITY_CONFIG = resolveFromBaseURL("learner_activity_phone_and_watch.json"); LOADED_ACTIVITY_CONFIG = resolveFromBaseURL("loaded_learner_activity_phone_and_watch.json"); @@ -52,7 +52,7 @@ public class LearnerTest { return base.resolve(filename).toUri().toURL(); } - @Before + @BeforeEach public void initLearner() { sut = new LearnerSubjectUnderTest(); } @@ -62,7 +62,7 @@ public class LearnerTest { LearnerTestUtils.testLearner(sut, settingsActivities()); } - @Ignore + @Disabled("Was ignored before") @Test public void testPreferences() throws IOException { LearnerTestUtils.testLearner(sut, settingsPreferences()); @@ -80,7 +80,7 @@ public class LearnerTest { .setConfigURL(LOADED_PREFERENCE_CONFIG)); } - @Ignore // takes longer than 10min + @Disabled("takes longer than 10min") @Test public void testOctoberActivities() throws IOException { LearnerTestUtils.testLearner(sut, settingsActivities() @@ -88,7 +88,7 @@ public class LearnerTest { .setDataURL(OCT_ACTIVITY_DATA)); } - @Ignore // not working currently + @Disabled("not working currently") @Test public void testLoadedOctoberActivities() throws IOException { LearnerTestUtils.testLearner(sut, settingsActivities() diff --git a/feedbackloop.learner_backup/src/test/java/de/tudresden/inf/st/eraser/feedbackloop/learner_backup/LearnerTestUtils.java b/feedbackloop.learner_backup/src/test/java/de/tudresden/inf/st/eraser/feedbackloop/learner_backup/LearnerTestUtils.java index 5f693e299c2090614a23c2ecaa2974f3ff52a4c0..fe32a87d0339b3461a2c268711a22554c75b6545 100644 --- a/feedbackloop.learner_backup/src/test/java/de/tudresden/inf/st/eraser/feedbackloop/learner_backup/LearnerTestUtils.java +++ b/feedbackloop.learner_backup/src/test/java/de/tudresden/inf/st/eraser/feedbackloop/learner_backup/LearnerTestUtils.java @@ -23,8 +23,8 @@ import java.util.stream.Stream; import static de.tudresden.inf.st.eraser.feedbackloop.learner_backup.LearnerTestConstants.COLOR_WEIGHTS; import static de.tudresden.inf.st.eraser.feedbackloop.learner_backup.LearnerTestConstants.MAX_COLOR_DIFFERENCE; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Utility methods to keep test code clean. @@ -144,13 +144,14 @@ public class LearnerTestUtils { } MachineLearningResult result = sut.decoder.classify(); // check if only one item is to be updated - assertEquals("Not one item update!", 1, result.getNumItemUpdate()); + assertEquals(1, result.getNumItemUpdate(), "Not one item update!"); ItemUpdate update = result.getItemUpdate(0); // check that the output item is to be updated - assertEquals("Output item not to be updated!", settings.getOutputItemProvider().get(), update.getItem()); + assertEquals(settings.getOutputItemProvider().get(), update.getItem(), + "Output item not to be updated!"); update.apply(); // check if the correct new state was set - assertThat("No target values found in this row!", targetValues, not(empty())); + assertThat(targetValues).isNotEmpty(); String expected = settings.getExpectedOutput().apply(targetValues); String actual = settings.getStateOfOutputItem().apply(update.getItem()); if (settings.getCheckUpdate().assertEquals(expected, actual)) { @@ -168,10 +169,10 @@ public class LearnerTestUtils { } finally { sut.shutdown(); } - assertThat(correct + wrong, greaterThan(0)); + assertThat(correct + wrong).isGreaterThan(0); double accuracy = correct * 1.0 / (correct + wrong); logger.info("Accuracy: {}", accuracy); - assertThat(accuracy, greaterThan(LearnerTestConstants.MIN_ACCURACY)); + assertThat(accuracy).isGreaterThan(LearnerTestConstants.MIN_ACCURACY); } private static CSVReader createCSVReader(Reader reader, LearnerTestSettings settings) { diff --git a/feedbackloop.learner_backup/src/test/java/de/tudresden/inf/st/eraser/feedbackloop/learner_backup/LearnerTestUtilsTest.java b/feedbackloop.learner_backup/src/test/java/de/tudresden/inf/st/eraser/feedbackloop/learner_backup/LearnerTestUtilsTest.java index 49209f2e2ca16a58c8f516f061f31d464c11870b..f1267de0e9f42fe8f86f33108aae7b66012876bc 100644 --- a/feedbackloop.learner_backup/src/test/java/de/tudresden/inf/st/eraser/feedbackloop/learner_backup/LearnerTestUtilsTest.java +++ b/feedbackloop.learner_backup/src/test/java/de/tudresden/inf/st/eraser/feedbackloop/learner_backup/LearnerTestUtilsTest.java @@ -1,12 +1,12 @@ package de.tudresden.inf.st.eraser.feedbackloop.learner_backup; import de.tudresden.inf.st.eraser.jastadd.model.TupleHSB; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; /** * Tests for the utility methods. @@ -79,9 +79,13 @@ public class LearnerTestUtilsTest { String reference = referenceColors[referenceIndex]; boolean expectedToBeSimilar = expectedValues[referenceIndex].contains("x"); String message = String.format("%s iss%s expected to be similar to %s, but %s!", - target, expectedToBeSimilar ? "" : " not", reference, expectedToBeSimilar ? "differs" : "it was"); - assertEquals(message, expectedToBeSimilar, - LearnerTestUtils.colorSimilar(colors.get(reference).toString(), colors.get(target).toString())); + target, expectedToBeSimilar ? "" : " not", + reference, expectedToBeSimilar ? "differs" : "it was"); + assertEquals(expectedToBeSimilar, + LearnerTestUtils.colorSimilar( + colors.get(reference).toString(), + colors.get(target).toString()), + message); } } } diff --git a/gradle.properties b/gradle.properties index 8dfaf2b21cba4862b382e4bb5d7a3173956f99d0..7e890a083c617c251c1a24316ea846144a7f08d9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,6 @@ -jackson_version = 2.9.8 -apache_httpcomponents_version = 4.5.8 +jackson_version = 2.12.0-rc2 +apache_httpcomponents_version = 4.5.13 +log4j_version = 2.14.0 +gradle_lombok_version = 4.0.0 +openscv_version = 5.3 +jupiter_version = 5.7.0 diff --git a/integration/build.gradle b/integration/build.gradle index 1317bea5f88fd9341768b1cfef08dd925ecbfc93..2b68d31294f3fa08506e73d568b66ecbb11adb63 100644 --- a/integration/build.gradle +++ b/integration/build.gradle @@ -4,7 +4,7 @@ plugins { dependencies { implementation project(':eraser-base') - implementation group: 'com.opencsv', name: 'opencsv', version: '3.8' + implementation group: 'com.opencsv', name: 'opencsv', version: "${openscv_version}" } application.mainClass = 'de.tudresden.inf.st.eraser.integration.IntegrationMain' diff --git a/integration/src/main/java/de/tudresden/inf/st/eraser/integration/IntegrationMain.java b/integration/src/main/java/de/tudresden/inf/st/eraser/integration/IntegrationMain.java index 61c7d67b77f0630894436a26e74e6f8e6557a3ca..af8462acfc90e56d0b596b2bde2322478510aa5c 100644 --- a/integration/src/main/java/de/tudresden/inf/st/eraser/integration/IntegrationMain.java +++ b/integration/src/main/java/de/tudresden/inf/st/eraser/integration/IntegrationMain.java @@ -1,6 +1,9 @@ package de.tudresden.inf.st.eraser.integration; +import com.opencsv.CSVParser; +import com.opencsv.CSVParserBuilder; import com.opencsv.CSVReader; +import com.opencsv.CSVReaderBuilder; import de.tudresden.inf.st.eraser.Main; import de.tudresden.inf.st.eraser.deserializer.ASTNodeDeserializer; import de.tudresden.inf.st.eraser.jastadd.model.*; @@ -47,8 +50,14 @@ public class IntegrationMain { mqttRoot.setHostByName(host); // columns: time,topic,qos,message try (InputStreamReader inputStreamReader = new InputStreamReader(inputStream); - CSVReader reader = new CSVReader(inputStreamReader, ',', '"', 1); - MQTTSender sender = mqttRoot.getMqttSender()) { + CSVReader reader = new CSVReaderBuilder(inputStreamReader) + .withCSVParser(new CSVParserBuilder() + .withSeparator(',') + .withQuoteChar('"') + .build()) + .withSkipLines(1) + .build(); + MQTTSender sender = mqttRoot.getMqttSender()){ if (!sender.isConnected()) { String msg = "MQTT sender is not connected, aborting to avoid waits at publish calls"; logger.error(msg); @@ -70,7 +79,7 @@ public class IntegrationMain { throw new RuntimeException(e); } }); - } catch (Exception e) { + } catch(Exception e){ e.printStackTrace(); } }); @@ -127,11 +136,15 @@ public class IntegrationMain { } public static QoS getQoSEnum(String qos) { - switch(qos) { - case "0": return QoS.AT_MOST_ONCE; - case "1": return QoS.AT_LEAST_ONCE; - case "2": return QoS.EXACTLY_ONCE; - default: throw new IllegalArgumentException("Invalid QoS: " + qos); + switch (qos) { + case "0": + return QoS.AT_MOST_ONCE; + case "1": + return QoS.AT_LEAST_ONCE; + case "2": + return QoS.EXACTLY_ONCE; + default: + throw new IllegalArgumentException("Invalid QoS: " + qos); } }