]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Enhancements to modelled tests 05/605/1
authorjsimomaa <jani.simomaa@gmail.com>
Tue, 6 Jun 2017 06:33:52 +0000 (09:33 +0300)
committerjsimomaa <jani.simomaa@gmail.com>
Tue, 6 Jun 2017 09:20:01 +0000 (12:20 +0300)
* 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

bundles/org.simantics.scl.runtime/META-INF/MANIFEST.MF
bundles/org.simantics.scl.runtime/scl/Junit/Assert.scl
bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/utils/AssertionUtils.java [new file with mode: 0644]
bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSTestRunner.java
bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSTest.java

index 32ac1e0a691afcc357e632057561211436dd83f6..aec2f1b850535e8e127a25d876d605a251d6d0be 100644 (file)
@@ -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",
index 6b0cd2d023239ee728f19b1e423ca3507bbb5482..411bcecb3693cb1ff47963ce7f609eff0e8d7b71 100644 (file)
@@ -1,3 +1,6 @@
+importJava "org.simantics.scl.runtime.utils.AssertionUtils" where
+    assertMultiLineStringEquals :: String -> String -> String -> <Proc> ()
+
 importJava "org.junit.Assert" where
     @JavaName assertEquals
     @private
@@ -5,6 +8,8 @@ importJava "org.junit.Assert" where
     @JavaName assertEquals
     @private
     assertLongsEquals :: String -> Long -> Long -> <Proc> ()
+    @JavaName assertEquals
+    assertObjectsEquals :: String -> a -> a -> <Proc> ()
     
     assertTrue :: String -> Boolean -> <Proc> ()
     assertFalse :: String -> Boolean -> <Proc> ()
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 (file)
index 0000000..1af7133
--- /dev/null
@@ -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);
+        }
+    }
+}
index 5f8ea6c16117fe90f4e4bad19b7095a54200e756..06fd1a2da0eb3e6331c3af44606f0f97643284f0 100644 (file)
@@ -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;
     }
 
index 6d9e4f4fece76c6cc9fe09e5e805735ff6c39206..33e4c25e2fc6b2f121bd3e6264a1ede8b3f09068 100644 (file)
@@ -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;
+    }
 }