From: Mateusz Warowny Date: Fri, 27 Oct 2023 13:01:35 +0000 (+0200) Subject: JAL-4313 Patch AnnotationsMatcher to match nulls X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=614e136583b401b4273d92723fec158d84d4cb52;p=jalview.git JAL-4313 Patch AnnotationsMatcher to match nulls --- diff --git a/test/jalview/testutils/AnnotationsMatcher.java b/test/jalview/testutils/AnnotationsMatcher.java index aa86d90..cc64d27 100644 --- a/test/jalview/testutils/AnnotationsMatcher.java +++ b/test/jalview/testutils/AnnotationsMatcher.java @@ -35,6 +35,10 @@ public class AnnotationsMatcher extends TypeSafeMatcher 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 diff --git a/test/jalview/testutils/AnnotationsMatcherTest.java b/test/jalview/testutils/AnnotationsMatcherTest.java index 732329b..3fbdab6 100644 --- a/test/jalview/testutils/AnnotationsMatcherTest.java +++ b/test/jalview/testutils/AnnotationsMatcherTest.java @@ -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() {