JAL-4313 Patch AnnotationsMatcher to match nulls
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Fri, 27 Oct 2023 13:01:35 +0000 (15:01 +0200)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Mon, 30 Oct 2023 14:35:18 +0000 (15:35 +0100)
test/jalview/testutils/AnnotationsMatcher.java
test/jalview/testutils/AnnotationsMatcherTest.java

index aa86d90..cc64d27 100644 (file)
@@ -35,6 +35,10 @@ public class AnnotationsMatcher extends TypeSafeMatcher<Annotation[]>
 
   static boolean annotationsEqual(Annotation a, Annotation b)
   {
+    if (a == null && b == null)
+      return true;
+    if ((a == null) != (b == null)) // if one is null but the other is not
+      return false;
     return a.secondaryStructure == b.secondaryStructure && a.value == b.value
         && Objects.equals(a.colour, b.colour)
         && Objects
index 732329b..3fbdab6 100644 (file)
@@ -48,7 +48,10 @@ public class AnnotationsMatcherTest
             new Annotation[] {
                 Annotation.EMPTY_ANNOTATION, Annotation.EMPTY_ANNOTATION },
             new Annotation[] {
-                Annotation.EMPTY_ANNOTATION, Annotation.EMPTY_ANNOTATION } } };
+                Annotation.EMPTY_ANNOTATION, Annotation.EMPTY_ANNOTATION } },
+        {
+            new Annotation[] { null, null, null, null },
+            new Annotation[] { null, null, null, null } } };
   }
 
   @Test(groups = { "Functional" }, dataProvider = "matchingAnnotationsLists")
@@ -80,7 +83,9 @@ public class AnnotationsMatcherTest
             new Annotation(null, null, ' ', 0.0f) },
         {
             new Annotation(null, "", ' ', 0.0f),
-            new Annotation("", null, ' ', 0.0f) } };
+            new Annotation("", null, ' ', 0.0f) },
+        { new Annotation(0f), Annotation.EMPTY_ANNOTATION },
+        { new Annotation(1f), new Annotation("", "", ' ', 1f, null) }, };
   }
 
   @Test(groups = { "Functional" }, dataProvider = "matchingAnnotations")
@@ -90,6 +95,39 @@ public class AnnotationsMatcherTest
     assert AnnotationsMatcher.annotationsEqual(first, second);
   }
 
+  @DataProvider
+  public Object[][] mismatchingAnnotations()
+  {
+    return new Object[][] {
+        {
+            new Annotation("A", "aaa", 'A', 1f),
+            new Annotation("A", "aaa", 'B', 1f) },
+        { new Annotation(1f), new Annotation(2f) },
+        { new Annotation(1f), new Annotation("A", "", 'A', 1f) } };
+  }
+
+  @Test(groups = { "Functional" }, dataProvider = "mismatchingAnnotations")
+  public void testAnnotationsEqual_mismatchingAnnotations(Annotation first,
+      Annotation second)
+  {
+    assert !AnnotationsMatcher.annotationsEqual(first, second);
+  }
+
+  @Test(groups = { "Functional" })
+  public void testAnnotationsEqual_nullsMatch()
+  {
+    assert AnnotationsMatcher.annotationsEqual(null, null);
+  }
+
+  @Test(groups = { "Functional" })
+  public void testAnnotationsEqual_nullNotMatchEmpty()
+  {
+    assert !AnnotationsMatcher
+        .annotationsEqual(null, Annotation.EMPTY_ANNOTATION);
+    assert !AnnotationsMatcher
+        .annotationsEqual(Annotation.EMPTY_ANNOTATION, null);
+  }
+
   @Test(groups = { "Functional" })
   public void testAnnotationsEqual_compareNullDisplayCharToEmpty()
   {