From 4669d9bc67c51f48421b7118da750fe0011183d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Kir=C3=A1ly?= Date: Fri, 8 Dec 2023 12:10:06 +0100 Subject: [PATCH] Implement SonarCloud quality suggestions #159 --- .../api/model/XmlFieldInstance.java | 10 ++--- .../api/model/XmlFieldInstanceTest.java | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/gwdg/metadataqa/api/model/XmlFieldInstance.java b/src/main/java/de/gwdg/metadataqa/api/model/XmlFieldInstance.java index 5f21727f..5710cceb 100644 --- a/src/main/java/de/gwdg/metadataqa/api/model/XmlFieldInstance.java +++ b/src/main/java/de/gwdg/metadataqa/api/model/XmlFieldInstance.java @@ -72,18 +72,14 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (!(obj instanceof XmlFieldInstance)) + if (!(obj instanceof XmlFieldInstance)) return false; if (this == obj) return true; final XmlFieldInstance other = (XmlFieldInstance) obj; - if ( !Objects.equals(this.value, other.value) - || !Objects.equals(this.language, other.language)) { - return false; - } - - return true; + return Objects.equals(this.value, other.value) + && Objects.equals(this.language, other.language); } } diff --git a/src/test/java/de/gwdg/metadataqa/api/model/XmlFieldInstanceTest.java b/src/test/java/de/gwdg/metadataqa/api/model/XmlFieldInstanceTest.java index 1e829768..a2e3d791 100644 --- a/src/test/java/de/gwdg/metadataqa/api/model/XmlFieldInstanceTest.java +++ b/src/test/java/de/gwdg/metadataqa/api/model/XmlFieldInstanceTest.java @@ -5,6 +5,30 @@ public class XmlFieldInstanceTest extends TestCase { + @Test + public void test_isEmpty_1() { + XmlFieldInstance x = new XmlFieldInstance("test"); + assertFalse(x.isEmpty()); + } + + @Test + public void test_isEmpty_2() { + XmlFieldInstance x = new XmlFieldInstance(null, "en"); + assertFalse(x.isEmpty()); + } + + @Test + public void test_isEmpty_3() { + XmlFieldInstance x = new XmlFieldInstance(null); + assertTrue(x.isEmpty()); + } + + @Test + public void test_isEmpty_4() { + XmlFieldInstance x = new XmlFieldInstance(null, null); + assertTrue(x.isEmpty()); + } + @Test public void testToString_noLang() { XmlFieldInstance x = new XmlFieldInstance("test"); @@ -60,4 +84,19 @@ public void testEquals_4() { assertFalse(a.equals(b)); assertFalse(b.equals(a)); } + + @Test + public void testEquals_5() { + XmlFieldInstance a = new XmlFieldInstance("test"); + assertTrue(a.equals(a)); + assertTrue(a.equals(a)); + } + + @Test + public void testEquals_6() { + XmlFieldInstance a = new XmlFieldInstance("test"); + String b = "test"; + assertFalse(a.equals(b)); + assertFalse(b.equals(a)); + } } \ No newline at end of file