From b5b171e61e74e88558227a19cccb348941e221ac Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 23 Jul 2026 20:30:37 +0000 Subject: [PATCH 1/2] test: improve coverage for util classes Adds tests for Objects and IOUtils to improve coverage in org.moreunit.core.util. Co-authored-by: RoiSoleil <3462260+RoiSoleil@users.noreply.github.com> --- .../org/moreunit/core/util/IOUtilsTest.java | 40 ++++++++++--------- .../org/moreunit/core/util/ObjectsTest.java | 40 ++++--------------- 2 files changed, 29 insertions(+), 51 deletions(-) diff --git a/org.moreunit.core.test/src/org/moreunit/core/util/IOUtilsTest.java b/org.moreunit.core.test/src/org/moreunit/core/util/IOUtilsTest.java index 4d3e0e03..59ddac78 100644 --- a/org.moreunit.core.test/src/org/moreunit/core/util/IOUtilsTest.java +++ b/org.moreunit.core.test/src/org/moreunit/core/util/IOUtilsTest.java @@ -1,6 +1,8 @@ package org.moreunit.core.util; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import java.io.Closeable; import java.io.IOException; @@ -10,38 +12,38 @@ class IOUtilsTest { @Test - void testCloseQuietlyWithNullArray() { + void testCloseQuietly_withNullArray() { IOUtils.closeQuietly((Closeable[]) null); - // Should not throw an exception } @Test - void testCloseQuietlyWithNullElement() { - IOUtils.closeQuietly(new Closeable[] { null }); - // Should not throw an exception + void testCloseQuietly_withNullElements() { + IOUtils.closeQuietly(null, null); } @Test - void testCloseQuietlySuccess() throws IOException { - Closeable mockCloseable1 = mock(Closeable.class); - Closeable mockCloseable2 = mock(Closeable.class); + void testCloseQuietly_withValidElements() throws IOException { + Closeable c1 = mock(Closeable.class); + Closeable c2 = mock(Closeable.class); - IOUtils.closeQuietly(mockCloseable1, mockCloseable2); + IOUtils.closeQuietly(c1, c2); - verify(mockCloseable1).close(); - verify(mockCloseable2).close(); + verify(c1).close(); + verify(c2).close(); } @Test - void testCloseQuietlyWithException() throws IOException { - Closeable mockCloseable1 = mock(Closeable.class); - Closeable mockCloseable2 = mock(Closeable.class); + void testCloseQuietly_withExceptionOnClose() throws IOException { + Closeable c1 = mock(Closeable.class); + Closeable c2 = mock(Closeable.class); + Closeable c3 = mock(Closeable.class); - doThrow(new IOException("Test exception")).when(mockCloseable1).close(); + doThrow(new IOException("test")).when(c2).close(); - IOUtils.closeQuietly(mockCloseable1, mockCloseable2); + IOUtils.closeQuietly(c1, c2, c3); - verify(mockCloseable1).close(); - verify(mockCloseable2).close(); // Should still be called even if the first one throws + verify(c1).close(); + verify(c2).close(); + verify(c3).close(); } } diff --git a/org.moreunit.core.test/src/org/moreunit/core/util/ObjectsTest.java b/org.moreunit.core.test/src/org/moreunit/core/util/ObjectsTest.java index f5dcdf0f..6edbee1e 100644 --- a/org.moreunit.core.test/src/org/moreunit/core/util/ObjectsTest.java +++ b/org.moreunit.core.test/src/org/moreunit/core/util/ObjectsTest.java @@ -2,49 +2,25 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.util.Arrays; - import org.junit.jupiter.api.Test; class ObjectsTest { @Test void testEqual() { - // Same reference - String str = "test"; - assertThat(Objects.equal(str, str)).isTrue(); - - // Equal values - assertThat(Objects.equal(new String("test"), new String("test"))).isTrue(); - - // Both null assertThat(Objects.equal(null, null)).isTrue(); - } - - @Test - void testNotEqual() { - // One null - assertThat(Objects.equal("test", null)).isFalse(); - assertThat(Objects.equal(null, "test")).isFalse(); - - // Different values - assertThat(Objects.equal("test", "test2")).isFalse(); - assertThat(Objects.equal(1, 2)).isFalse(); + assertThat(Objects.equal("a", "a")).isTrue(); + assertThat(Objects.equal(Integer.valueOf(1), Integer.valueOf(1))).isTrue(); - // Different types - assertThat(Objects.equal("1", 1)).isFalse(); + assertThat(Objects.equal(null, "a")).isFalse(); + assertThat(Objects.equal("a", null)).isFalse(); + assertThat(Objects.equal("a", "b")).isFalse(); } @Test void testHash() { - Object obj1 = "test"; - Object obj2 = 123; - Object obj3 = null; - - assertThat(Objects.hash(obj1, obj2, obj3)).isEqualTo(Arrays.hashCode(new Object[] { obj1, obj2, obj3 })); - - assertThat(Objects.hash(obj1)).isEqualTo(Arrays.hashCode(new Object[] { obj1 })); - - assertThat(Objects.hash()).isEqualTo(Arrays.hashCode(new Object[0])); + assertThat(Objects.hash("a", "b")).isEqualTo(java.util.Arrays.hashCode(new Object[]{"a", "b"})); + assertThat(Objects.hash(null, "b")).isEqualTo(java.util.Arrays.hashCode(new Object[]{null, "b"})); + assertThat(Objects.hash()).isEqualTo(java.util.Arrays.hashCode(new Object[]{})); } } From 9b20ce3dbcb48cd4963d23b0db7dce44b777d397 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 23 Jul 2026 20:57:21 +0000 Subject: [PATCH 2/2] test: improve coverage for util classes Adds tests for Objects and IOUtils to improve coverage in org.moreunit.core.util. Co-authored-by: RoiSoleil <3462260+RoiSoleil@users.noreply.github.com> --- .../org/moreunit/core/util/IOUtilsTest.java | 49 ------------------- .../org/moreunit/core/util/ObjectsTest.java | 26 ---------- .../org/moreunit/core/util/IOUtilsTest.java | 37 ++++++++++++++ .../org/moreunit/core/util/ObjectsTest.java | 16 ++++++ patch_objects.diff | 33 +++++++++++++ 5 files changed, 86 insertions(+), 75 deletions(-) delete mode 100644 org.moreunit.core.test/src/org/moreunit/core/util/IOUtilsTest.java delete mode 100644 org.moreunit.core.test/src/org/moreunit/core/util/ObjectsTest.java create mode 100644 patch_objects.diff diff --git a/org.moreunit.core.test/src/org/moreunit/core/util/IOUtilsTest.java b/org.moreunit.core.test/src/org/moreunit/core/util/IOUtilsTest.java deleted file mode 100644 index 59ddac78..00000000 --- a/org.moreunit.core.test/src/org/moreunit/core/util/IOUtilsTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.moreunit.core.util; - -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -import java.io.Closeable; -import java.io.IOException; - -import org.junit.jupiter.api.Test; - -class IOUtilsTest { - - @Test - void testCloseQuietly_withNullArray() { - IOUtils.closeQuietly((Closeable[]) null); - } - - @Test - void testCloseQuietly_withNullElements() { - IOUtils.closeQuietly(null, null); - } - - @Test - void testCloseQuietly_withValidElements() throws IOException { - Closeable c1 = mock(Closeable.class); - Closeable c2 = mock(Closeable.class); - - IOUtils.closeQuietly(c1, c2); - - verify(c1).close(); - verify(c2).close(); - } - - @Test - void testCloseQuietly_withExceptionOnClose() throws IOException { - Closeable c1 = mock(Closeable.class); - Closeable c2 = mock(Closeable.class); - Closeable c3 = mock(Closeable.class); - - doThrow(new IOException("test")).when(c2).close(); - - IOUtils.closeQuietly(c1, c2, c3); - - verify(c1).close(); - verify(c2).close(); - verify(c3).close(); - } -} diff --git a/org.moreunit.core.test/src/org/moreunit/core/util/ObjectsTest.java b/org.moreunit.core.test/src/org/moreunit/core/util/ObjectsTest.java deleted file mode 100644 index 6edbee1e..00000000 --- a/org.moreunit.core.test/src/org/moreunit/core/util/ObjectsTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.moreunit.core.util; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.jupiter.api.Test; - -class ObjectsTest { - - @Test - void testEqual() { - assertThat(Objects.equal(null, null)).isTrue(); - assertThat(Objects.equal("a", "a")).isTrue(); - assertThat(Objects.equal(Integer.valueOf(1), Integer.valueOf(1))).isTrue(); - - assertThat(Objects.equal(null, "a")).isFalse(); - assertThat(Objects.equal("a", null)).isFalse(); - assertThat(Objects.equal("a", "b")).isFalse(); - } - - @Test - void testHash() { - assertThat(Objects.hash("a", "b")).isEqualTo(java.util.Arrays.hashCode(new Object[]{"a", "b"})); - assertThat(Objects.hash(null, "b")).isEqualTo(java.util.Arrays.hashCode(new Object[]{null, "b"})); - assertThat(Objects.hash()).isEqualTo(java.util.Arrays.hashCode(new Object[]{})); - } -} diff --git a/org.moreunit.core.test/test/org/moreunit/core/util/IOUtilsTest.java b/org.moreunit.core.test/test/org/moreunit/core/util/IOUtilsTest.java index e24cbd3b..7d639315 100644 --- a/org.moreunit.core.test/test/org/moreunit/core/util/IOUtilsTest.java +++ b/org.moreunit.core.test/test/org/moreunit/core/util/IOUtilsTest.java @@ -52,4 +52,41 @@ public void closeQuietly_should_swallow_IOExceptions() throws Exception // then: no exception = success } + + @Test + public void closeQuietly_should_ignore_null_array() throws Exception + { + // when + closeQuietly((Closeable[]) null); + + // then: no exception = success + } + + @Test + public void closeQuietly_should_ignore_null_varargs_elements() throws Exception + { + // when + closeQuietly(null, null); + + // then: no exception = success + } + + @Test + public void closeQuietly_should_continue_closing_remaining_resources_on_exception() throws Exception + { + // given + Closeable c1 = mock(Closeable.class); + Closeable c2 = mock(Closeable.class); + Closeable c3 = mock(Closeable.class); + + doThrow(new IOException()).when(c2).close(); + + // when + closeQuietly(c1, c2, c3); + + // then + verify(c1, times(1)).close(); + verify(c2, times(1)).close(); + verify(c3, times(1)).close(); + } } diff --git a/org.moreunit.core.test/test/org/moreunit/core/util/ObjectsTest.java b/org.moreunit.core.test/test/org/moreunit/core/util/ObjectsTest.java index a777f997..3dc644c8 100644 --- a/org.moreunit.core.test/test/org/moreunit/core/util/ObjectsTest.java +++ b/org.moreunit.core.test/test/org/moreunit/core/util/ObjectsTest.java @@ -33,4 +33,20 @@ public void unequal_objects_should_be_seen_as_such() throws Exception assertFalse(Objects.equal("abc", "aBc")); assertFalse(Objects.equal(95, 94)); } + + @Test + public void testHash() { + org.junit.jupiter.api.Assertions.assertEquals( + java.util.Arrays.hashCode(new Object[]{"a", "b"}), + Objects.hash("a", "b") + ); + org.junit.jupiter.api.Assertions.assertEquals( + java.util.Arrays.hashCode(new Object[]{null, "b"}), + Objects.hash(null, "b") + ); + org.junit.jupiter.api.Assertions.assertEquals( + java.util.Arrays.hashCode(new Object[]{}), + Objects.hash() + ); + } } diff --git a/patch_objects.diff b/patch_objects.diff new file mode 100644 index 00000000..e7bc59ff --- /dev/null +++ b/patch_objects.diff @@ -0,0 +1,33 @@ +<<<<<<< SEARCH + @Test + public void unequal_objects_should_be_seen_as_such() throws Exception + { + assertFalse(Objects.equal("abc", "aBc")); + assertFalse(Objects.equal(95, 94)); + } +} +======= + @Test + public void unequal_objects_should_be_seen_as_such() throws Exception + { + assertFalse(Objects.equal("abc", "aBc")); + assertFalse(Objects.equal(95, 94)); + } + + @Test + public void testHash() { + org.junit.jupiter.api.Assertions.assertEquals( + java.util.Arrays.hashCode(new Object[]{"a", "b"}), + Objects.hash("a", "b") + ); + org.junit.jupiter.api.Assertions.assertEquals( + java.util.Arrays.hashCode(new Object[]{null, "b"}), + Objects.hash(null, "b") + ); + org.junit.jupiter.api.Assertions.assertEquals( + java.util.Arrays.hashCode(new Object[]{}), + Objects.hash() + ); + } +} +>>>>>>> REPLACE