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 4d3e0e03..00000000 --- a/org.moreunit.core.test/src/org/moreunit/core/util/IOUtilsTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.moreunit.core.util; - -import static org.mockito.Mockito.*; - -import java.io.Closeable; -import java.io.IOException; - -import org.junit.jupiter.api.Test; - -class IOUtilsTest { - - @Test - void testCloseQuietlyWithNullArray() { - IOUtils.closeQuietly((Closeable[]) null); - // Should not throw an exception - } - - @Test - void testCloseQuietlyWithNullElement() { - IOUtils.closeQuietly(new Closeable[] { null }); - // Should not throw an exception - } - - @Test - void testCloseQuietlySuccess() throws IOException { - Closeable mockCloseable1 = mock(Closeable.class); - Closeable mockCloseable2 = mock(Closeable.class); - - IOUtils.closeQuietly(mockCloseable1, mockCloseable2); - - verify(mockCloseable1).close(); - verify(mockCloseable2).close(); - } - - @Test - void testCloseQuietlyWithException() throws IOException { - Closeable mockCloseable1 = mock(Closeable.class); - Closeable mockCloseable2 = mock(Closeable.class); - - doThrow(new IOException("Test exception")).when(mockCloseable1).close(); - - IOUtils.closeQuietly(mockCloseable1, mockCloseable2); - - verify(mockCloseable1).close(); - verify(mockCloseable2).close(); // Should still be called even if the first one throws - } -} 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 f5dcdf0f..00000000 --- a/org.moreunit.core.test/src/org/moreunit/core/util/ObjectsTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.moreunit.core.util; - -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(); - - // Different types - assertThat(Objects.equal("1", 1)).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])); - } -} 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