From 674fafd9fc3c75e46cbb73dc3c413e0cbc83b187 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Tue, 6 Jun 2017 09:33:52 +0300 Subject: [PATCH] Enhancements to modelled tests * Added an assertion for long strings * Unique test descriptions even though they are similarly named * equals and hashCode for ModelledSTSTest refs #7277 Change-Id: I25bb7a96291050a81e9346e78306a67666b87877 --- .../META-INF/MANIFEST.MF | 1 + .../scl/Junit/Assert.scl | 5 ++ .../scl/runtime/utils/AssertionUtils.java | 16 +++++ .../junit/v2/ModelledSTSTestRunner.java | 3 +- .../tests/modelled/utils/ModelledSTSTest.java | 62 ++++++++++++++++++- 5 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/utils/AssertionUtils.java diff --git a/bundles/org.simantics.scl.runtime/META-INF/MANIFEST.MF b/bundles/org.simantics.scl.runtime/META-INF/MANIFEST.MF index 32ac1e0a6..aec2f1b85 100644 --- a/bundles/org.simantics.scl.runtime/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.scl.runtime/META-INF/MANIFEST.MF @@ -19,6 +19,7 @@ Export-Package: org.simantics.scl.runtime, org.simantics.scl.runtime.string, org.simantics.scl.runtime.tuple, org.simantics.scl.runtime.unification, + org.simantics.scl.runtime.utils, org.simantics.scl.runtime.xml Require-Bundle: org.junit;bundle-version="4.12.0";resolution:=optional, gnu.trove3;bundle-version="3.0.0", diff --git a/bundles/org.simantics.scl.runtime/scl/Junit/Assert.scl b/bundles/org.simantics.scl.runtime/scl/Junit/Assert.scl index 6b0cd2d02..411bcecb3 100644 --- a/bundles/org.simantics.scl.runtime/scl/Junit/Assert.scl +++ b/bundles/org.simantics.scl.runtime/scl/Junit/Assert.scl @@ -1,3 +1,6 @@ +importJava "org.simantics.scl.runtime.utils.AssertionUtils" where + assertMultiLineStringEquals :: String -> String -> String -> () + importJava "org.junit.Assert" where @JavaName assertEquals @private @@ -5,6 +8,8 @@ importJava "org.junit.Assert" where @JavaName assertEquals @private assertLongsEquals :: String -> Long -> Long -> () + @JavaName assertEquals + assertObjectsEquals :: String -> a -> a -> () assertTrue :: String -> Boolean -> () assertFalse :: String -> Boolean -> () diff --git a/bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/utils/AssertionUtils.java b/bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/utils/AssertionUtils.java new file mode 100644 index 000000000..1af7133d1 --- /dev/null +++ b/bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/utils/AssertionUtils.java @@ -0,0 +1,16 @@ +package org.simantics.scl.runtime.utils; + +import org.junit.Assert; + +public class AssertionUtils { + + public static void assertMultiLineStringEquals(String message, String expected, String actual) { + String[] expectedLines = expected.split("\\n"); + String[] actualLines = actual.split("\\n"); + for (int line = 0; line < expectedLines.length; line++) { + String expectedLine = expectedLines[line]; + String actualLine = actualLines[line]; + Assert.assertEquals(message + " Line [" + line + "]", expectedLine, actualLine); + } + } +} diff --git a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSTestRunner.java b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSTestRunner.java index 5f8ea6c16..06fd1a2da 100644 --- a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSTestRunner.java +++ b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSTestRunner.java @@ -5,7 +5,6 @@ import java.util.List; import org.junit.runner.Description; import org.junit.runner.Runner; -import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunNotifier; import org.simantics.tests.modelled.utils.ModelledSTSTest; import org.simantics.tests.modelled.utils.ModelledSTSTest.CommandSessionVariable; @@ -22,7 +21,7 @@ public class ModelledSTSTestRunner extends Runner { @Override public Description getDescription() { if (description == null) - description = Description.createTestDescription(ModelledSTSTestRunner.class, test.getName()); + description = Description.createTestDescription(ModelledSTSTestRunner.class.getName(), test.getName(), new Integer(test.hashCode())); return description; } diff --git a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSTest.java b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSTest.java index 6d9e4f4fe..33e4c25e2 100644 --- a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSTest.java +++ b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSTest.java @@ -8,7 +8,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.regex.Pattern; import org.simantics.scl.compiler.commands.CommandSession; import org.simantics.scl.compiler.commands.TestScriptExecutor; @@ -148,4 +147,65 @@ public class ModelledSTSTest { public boolean resolveDependency(String testDep) { return unresolvedDependencies.remove(testDep); } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((code == null) ? 0 : code.hashCode()); + result = prime * result + ((coverage == null) ? 0 : coverage.hashCode()); + result = prime * result + ((dependencies == null) ? 0 : dependencies.hashCode()); + result = prime * result + (ignored ? 1231 : 1237); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + priority; + result = prime * result + ((unresolvedDependencies == null) ? 0 : unresolvedDependencies.hashCode()); + result = prime * result + ((variables == null) ? 0 : variables.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ModelledSTSTest other = (ModelledSTSTest) obj; + if (code == null) { + if (other.code != null) + return false; + } else if (!code.equals(other.code)) + return false; + if (coverage == null) { + if (other.coverage != null) + return false; + } else if (!coverage.equals(other.coverage)) + return false; + if (dependencies == null) { + if (other.dependencies != null) + return false; + } else if (!dependencies.equals(other.dependencies)) + return false; + if (ignored != other.ignored) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (priority != other.priority) + return false; + if (unresolvedDependencies == null) { + if (other.unresolvedDependencies != null) + return false; + } else if (!unresolvedDependencies.equals(other.unresolvedDependencies)) + return false; + if (variables == null) { + if (other.variables != null) + return false; + } else if (!variables.equals(other.variables)) + return false; + return true; + } } -- 2.43.2