From a1cf8ea28728ab848b1cbfc50e915d499f565354 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 27 Apr 2026 15:09:35 +0000 Subject: [PATCH 1/3] Add unit tests for ArrayUtils, Preconditions and ExtendedSafeRunner This commit improves code coverage for utility classes in the org.moreunit.core bundle. Added: - ArrayUtilsTest.java - PreconditionsTest.java - ExtendedSafeRunnerTest.java The tests cover various scenarios including success paths and error/exception handling. Co-authored-by: RoiSoleil <3462260+RoiSoleil@users.noreply.github.com> --- .../moreunit/core/util/ArrayUtilsTest.java | 22 +++ .../core/util/ExtendedSafeRunnerTest.java | 78 +++++++++ .../moreunit/core/util/PreconditionsTest.java | 154 ++++++++++++++++++ 3 files changed, 254 insertions(+) create mode 100644 org.moreunit.core.test/test/org/moreunit/core/util/ArrayUtilsTest.java create mode 100644 org.moreunit.core.test/test/org/moreunit/core/util/ExtendedSafeRunnerTest.java create mode 100644 org.moreunit.core.test/test/org/moreunit/core/util/PreconditionsTest.java diff --git a/org.moreunit.core.test/test/org/moreunit/core/util/ArrayUtilsTest.java b/org.moreunit.core.test/test/org/moreunit/core/util/ArrayUtilsTest.java new file mode 100644 index 00000000..1b51afc5 --- /dev/null +++ b/org.moreunit.core.test/test/org/moreunit/core/util/ArrayUtilsTest.java @@ -0,0 +1,22 @@ +package org.moreunit.core.util; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +public class ArrayUtilsTest +{ + @Test + public void array_should_return_elements() + { + String[] strings = ArrayUtils.array("a", "b", "c"); + assertThat(strings).containsExactly("a", "b", "c"); + } + + @Test + public void array_should_return_empty_array_when_no_arguments() + { + Object[] objects = ArrayUtils.array(); + assertThat(objects).isEmpty(); + } +} diff --git a/org.moreunit.core.test/test/org/moreunit/core/util/ExtendedSafeRunnerTest.java b/org.moreunit.core.test/test/org/moreunit/core/util/ExtendedSafeRunnerTest.java new file mode 100644 index 00000000..a3fc8a1b --- /dev/null +++ b/org.moreunit.core.test/test/org/moreunit/core/util/ExtendedSafeRunnerTest.java @@ -0,0 +1,78 @@ +package org.moreunit.core.util; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; +import org.moreunit.core.util.ExtendedSafeRunner.GenericRunnable; + +public class ExtendedSafeRunnerTest +{ + @Test + public void applyTo_should_execute_code_and_return_result() + { + ExtendedSafeRunner runner = new ExtendedSafeRunner(); + String result = runner.applyTo("input", new GenericRunnable() + { + @Override + public String run(String element) throws Exception + { + return element.toUpperCase(); + } + + @Override + public void handleException(Throwable throwable, String element) + { + } + }); + + assertThat(result).isEqualTo("INPUT"); + } + + @Test + public void applyTo_iterable_should_execute_code_for_each_element() + { + ExtendedSafeRunner runner = new ExtendedSafeRunner(); + Iterable results = runner.applyTo(Arrays.asList("a", "b"), new GenericRunnable() + { + @Override + public String run(String element) throws Exception + { + return element.toUpperCase(); + } + + @Override + public void handleException(Throwable throwable, String element) + { + } + }); + + assertThat(results).containsExactly("A", "B"); + } + + @Test + public void applyTo_should_handle_exception() + { + ExtendedSafeRunner runner = new ExtendedSafeRunner(); + final boolean[] exceptionHandled = { false }; + + runner.applyTo("input", new GenericRunnable() + { + @Override + public String run(String element) throws Exception + { + throw new RuntimeException("failed"); + } + + @Override + public void handleException(Throwable throwable, String element) + { + exceptionHandled[0] = true; + } + }); + + assertThat(exceptionHandled[0]).isTrue(); + } +} diff --git a/org.moreunit.core.test/test/org/moreunit/core/util/PreconditionsTest.java b/org.moreunit.core.test/test/org/moreunit/core/util/PreconditionsTest.java new file mode 100644 index 00000000..00e541f6 --- /dev/null +++ b/org.moreunit.core.test/test/org/moreunit/core/util/PreconditionsTest.java @@ -0,0 +1,154 @@ +package org.moreunit.core.util; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import org.junit.Test; + +public class PreconditionsTest +{ + @Test + public void checkNotNull_should_return_reference_when_not_null() + { + String ref = "abc"; + assertThat(Preconditions.checkNotNull(ref)).isSameAs(ref); + } + + @Test(expected = NullPointerException.class) + public void checkNotNull_should_throw_exception_when_null() + { + Preconditions.checkNotNull(null); + } + + @Test + public void checkNotNull_with_message_should_return_reference_when_not_null() + { + String ref = "abc"; + assertThat(Preconditions.checkNotNull(ref, "error")).isSameAs(ref); + } + + @Test + public void checkNotNull_with_message_should_throw_exception_with_message_when_null() + { + try + { + Preconditions.checkNotNull(null, "custom error"); + fail("Should have thrown NullPointerException"); + } + catch (NullPointerException e) + { + assertThat(e.getMessage()).isEqualTo("custom error"); + } + } + + @Test + public void checkArgument_should_do_nothing_when_true() + { + Preconditions.checkArgument(true); + } + + @Test(expected = IllegalArgumentException.class) + public void checkArgument_should_throw_exception_when_false() + { + Preconditions.checkArgument(false); + } + + @Test + public void checkArgument_with_message_should_do_nothing_when_true() + { + Preconditions.checkArgument(true, "error"); + } + + @Test + public void checkArgument_with_message_should_throw_exception_with_message_when_false() + { + try + { + Preconditions.checkArgument(false, "custom error"); + fail("Should have thrown IllegalArgumentException"); + } + catch (IllegalArgumentException e) + { + assertThat(e.getMessage()).isEqualTo("custom error"); + } + } + + @Test + public void checkState_should_do_nothing_when_true() + { + Preconditions.checkState(true, "error"); + } + + @Test + public void checkState_should_throw_exception_with_message_when_false() + { + try + { + Preconditions.checkState(false, "custom error"); + fail("Should have thrown IllegalStateException"); + } + catch (IllegalStateException e) + { + assertThat(e.getMessage()).isEqualTo("custom error"); + } + } + + @Test + public void checkNotNullOrEmpty_should_return_collection_when_not_null_nor_empty() + { + List list = Arrays.asList("a"); + assertThat(Preconditions.checkNotNullOrEmpty(list)).isSameAs(list); + } + + @Test(expected = NullPointerException.class) + public void checkNotNullOrEmpty_should_throw_NPE_when_null() + { + Preconditions.checkNotNullOrEmpty(null); + } + + @Test(expected = IllegalArgumentException.class) + public void checkNotNullOrEmpty_should_throw_IAE_when_empty() + { + Preconditions.checkNotNullOrEmpty(new ArrayList()); + } + + @Test + public void checkNotNullOrEmpty_with_message_should_return_collection_when_not_null_nor_empty() + { + List list = Arrays.asList("a"); + assertThat(Preconditions.checkNotNullOrEmpty(list, "error")).isSameAs(list); + } + + @Test + public void checkNotNullOrEmpty_with_message_should_throw_NPE_with_message_when_null() + { + try + { + Preconditions.checkNotNullOrEmpty(null, "custom error"); + fail("Should have thrown NullPointerException"); + } + catch (NullPointerException e) + { + assertThat(e.getMessage()).isEqualTo("custom error"); + } + } + + @Test + public void checkNotNullOrEmpty_with_message_should_throw_IAE_with_message_when_empty() + { + try + { + Preconditions.checkNotNullOrEmpty(new ArrayList(), "custom error"); + fail("Should have thrown IllegalArgumentException"); + } + catch (IllegalArgumentException e) + { + assertThat(e.getMessage()).isEqualTo("custom error"); + } + } +} From 7f7744ef76a4397032055c81e826bcb30e8d1716 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 27 Apr 2026 15:22:03 +0000 Subject: [PATCH 2/3] Add unit tests for ArrayUtils, Preconditions and ExtendedSafeRunner This commit improves code coverage for utility classes in the org.moreunit.core bundle. Changes: - Added ArrayUtilsTest.java - Added PreconditionsTest.java (covering all methods and exception cases) - Added ExtendedSafeRunnerTest.java (including exception handling) - Improved StringsTest.java with coverage for emptyArray() These tests ensure that core utilities are robust and well-verified. Co-authored-by: RoiSoleil <3462260+RoiSoleil@users.noreply.github.com> --- .../test/org/moreunit/core/util/ExtendedSafeRunnerTest.java | 2 ++ .../test/org/moreunit/core/util/StringsTest.java | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/org.moreunit.core.test/test/org/moreunit/core/util/ExtendedSafeRunnerTest.java b/org.moreunit.core.test/test/org/moreunit/core/util/ExtendedSafeRunnerTest.java index a3fc8a1b..772b169a 100644 --- a/org.moreunit.core.test/test/org/moreunit/core/util/ExtendedSafeRunnerTest.java +++ b/org.moreunit.core.test/test/org/moreunit/core/util/ExtendedSafeRunnerTest.java @@ -70,6 +70,8 @@ public String run(String element) throws Exception public void handleException(Throwable throwable, String element) { exceptionHandled[0] = true; + assertThat(element).isEqualTo("input"); + assertThat(throwable.getMessage()).isEqualTo("failed"); } }); diff --git a/org.moreunit.core.test/test/org/moreunit/core/util/StringsTest.java b/org.moreunit.core.test/test/org/moreunit/core/util/StringsTest.java index ec4b2d97..6e90c0fa 100644 --- a/org.moreunit.core.test/test/org/moreunit/core/util/StringsTest.java +++ b/org.moreunit.core.test/test/org/moreunit/core/util/StringsTest.java @@ -127,4 +127,10 @@ public void join_should_join_given_strings_whith_given_separator() throws Except assertThat(Strings.join(",", "1", "2", "3")).isEqualTo("1,2,3"); assertThat(Strings.join(" -> ", "aBc", "2", "DEf")).isEqualTo("aBc -> 2 -> DEf"); } + + @Test + public void emptyArray_should_return_empty_array() + { + assertThat(Strings.emptyArray()).isEmpty(); + } } From 08ee1d4028106ad962e560576e88a2e70bb9190f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 27 Apr 2026 15:34:46 +0000 Subject: [PATCH 3/3] Add unit tests for ArrayUtils, Preconditions, ExtendedSafeRunner and StringConstants This commit improves code coverage for utility classes in the org.moreunit.core bundle. Changes: - Added ArrayUtilsTest.java - Added PreconditionsTest.java (covering all methods and exception cases) - Added ExtendedSafeRunnerTest.java (including exception handling) - Added StringConstantsTest.java - Improved StringsTest.java with coverage for emptyArray() - Improved StringLengthComparatorTest.java with more precise assertions These tests ensure that core utilities are robust and well-verified. Co-authored-by: RoiSoleil <3462260+RoiSoleil@users.noreply.github.com> --- .../core/util/StringConstantsTest.java | 18 ++++++++++++++++++ .../core/util/StringLengthComparatorTest.java | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 org.moreunit.core.test/test/org/moreunit/core/util/StringConstantsTest.java diff --git a/org.moreunit.core.test/test/org/moreunit/core/util/StringConstantsTest.java b/org.moreunit.core.test/test/org/moreunit/core/util/StringConstantsTest.java new file mode 100644 index 00000000..f88953e6 --- /dev/null +++ b/org.moreunit.core.test/test/org/moreunit/core/util/StringConstantsTest.java @@ -0,0 +1,18 @@ +package org.moreunit.core.util; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +public class StringConstantsTest +{ + @Test + public void constants_should_have_expected_values() + { + assertThat(StringConstants.DOT).isEqualTo("."); + assertThat(StringConstants.EMPTY_STRING).isEqualTo(""); + assertThat(StringConstants.NEWLINE).isEqualTo(System.getProperty("line.separator")); + assertThat(StringConstants.SLASH).isEqualTo("/"); + assertThat(StringConstants.WILDCARD).isEqualTo("*"); + } +} diff --git a/org.moreunit.core.test/test/org/moreunit/core/util/StringLengthComparatorTest.java b/org.moreunit.core.test/test/org/moreunit/core/util/StringLengthComparatorTest.java index be2f769b..fbb9dd91 100644 --- a/org.moreunit.core.test/test/org/moreunit/core/util/StringLengthComparatorTest.java +++ b/org.moreunit.core.test/test/org/moreunit/core/util/StringLengthComparatorTest.java @@ -15,7 +15,7 @@ public void should_return_positive_integer_when_first_has_greater_length_than_se @Test public void should_return_negative_integer_when_second_has_greater_length_than_first_parameter() throws Exception { - assertThat(new StringLengthComparator().compare("", "Long")).isLessThanOrEqualTo(0); + assertThat(new StringLengthComparator().compare("", "Long")).isLessThan(0); } @Test