From 5790a87d12080b3029c993da4b21a90eaace4ddd Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 5 Jul 2026 20:59:05 +0000 Subject: [PATCH 1/2] test: improve coverage for utility classes Co-authored-by: RoiSoleil <3462260+RoiSoleil@users.noreply.github.com> --- .../core/util/ExtendedSafeRunnerTest.java | 70 +++++++++++++++++++ .../org/moreunit/core/util/FeaturesTest.java | 39 +++++++++++ .../org/moreunit/core/util/LRUCacheTest.java | 43 ++++++++++++ .../org/moreunit/core/util/ObjectsTest.java | 25 +++++++ .../core/util/StringLengthComparatorTest.java | 29 ++++++++ 5 files changed, 206 insertions(+) create mode 100644 org.moreunit.core.test/src/org/moreunit/core/util/ExtendedSafeRunnerTest.java create mode 100644 org.moreunit.core.test/src/org/moreunit/core/util/FeaturesTest.java create mode 100644 org.moreunit.core.test/src/org/moreunit/core/util/LRUCacheTest.java create mode 100644 org.moreunit.core.test/src/org/moreunit/core/util/ObjectsTest.java create mode 100644 org.moreunit.core.test/src/org/moreunit/core/util/StringLengthComparatorTest.java diff --git a/org.moreunit.core.test/src/org/moreunit/core/util/ExtendedSafeRunnerTest.java b/org.moreunit.core.test/src/org/moreunit/core/util/ExtendedSafeRunnerTest.java new file mode 100644 index 00000000..08f7b622 --- /dev/null +++ b/org.moreunit.core.test/src/org/moreunit/core/util/ExtendedSafeRunnerTest.java @@ -0,0 +1,70 @@ +package org.moreunit.core.util; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Arrays; +import java.util.List; + +import org.junit.jupiter.api.Test; + +class ExtendedSafeRunnerTest { + + @Test + void testApplyToSingle() { + ExtendedSafeRunner runner = new ExtendedSafeRunner(); + String result = runner.applyTo("input", new ExtendedSafeRunner.GenericRunnable() { + @Override + public void handleException(Throwable throwable, String element) { + } + + @Override + public String run(String element) throws Exception { + return element + "-processed"; + } + }); + + assertThat(result).isEqualTo("input-processed"); + } + + @Test + void testApplyToIterable() { + ExtendedSafeRunner runner = new ExtendedSafeRunner(); + List inputs = Arrays.asList("a", "b", "c"); + + Iterable results = runner.applyTo(inputs, new ExtendedSafeRunner.GenericRunnable() { + @Override + public void handleException(Throwable throwable, String element) { + } + + @Override + public String run(String element) throws Exception { + return element.toUpperCase(); + } + }); + + assertThat(results).containsExactly("A", "B", "C"); + } + + @Test + void testApplyToExceptionHandled() { + ExtendedSafeRunner runner = new ExtendedSafeRunner(); + + final boolean[] handled = new boolean[1]; + + String result = runner.applyTo("error", new ExtendedSafeRunner.GenericRunnable() { + @Override + public void handleException(Throwable throwable, String element) { + handled[0] = true; + assertThat(element).isEqualTo("error"); + } + + @Override + public String run(String element) throws Exception { + throw new RuntimeException("test exception"); + } + }); + + assertThat(result).isNull(); // run failed, result not set + assertThat(handled[0]).isTrue(); + } +} diff --git a/org.moreunit.core.test/src/org/moreunit/core/util/FeaturesTest.java b/org.moreunit.core.test/src/org/moreunit/core/util/FeaturesTest.java new file mode 100644 index 00000000..4a5de760 --- /dev/null +++ b/org.moreunit.core.test/src/org/moreunit/core/util/FeaturesTest.java @@ -0,0 +1,39 @@ +package org.moreunit.core.util; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +class FeaturesTest { + + private static final String TEST_FEATURE = "org.moreunit.testFeature"; + + @AfterEach + void tearDown() { + System.clearProperty(TEST_FEATURE); + } + + @Test + void testIsActiveDefault() { + assertThat(Features.isActive("non.existing.feature")).isFalse(); + } + + @Test + void testIsActiveTrue() { + System.setProperty(TEST_FEATURE, "true"); + assertThat(Features.isActive(TEST_FEATURE)).isTrue(); + } + + @Test + void testIsActiveFalse() { + System.setProperty(TEST_FEATURE, "false"); + assertThat(Features.isActive(TEST_FEATURE)).isFalse(); + } + + @Test + void testIsActiveInvalid() { + System.setProperty(TEST_FEATURE, "invalid"); + assertThat(Features.isActive(TEST_FEATURE)).isFalse(); + } +} diff --git a/org.moreunit.core.test/src/org/moreunit/core/util/LRUCacheTest.java b/org.moreunit.core.test/src/org/moreunit/core/util/LRUCacheTest.java new file mode 100644 index 00000000..f5497388 --- /dev/null +++ b/org.moreunit.core.test/src/org/moreunit/core/util/LRUCacheTest.java @@ -0,0 +1,43 @@ +package org.moreunit.core.util; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class LRUCacheTest { + + @Test + void testEvictsEldestEntry() { + LRUCache cache = new LRUCache<>(2); + + cache.put("1", "one"); + cache.put("2", "two"); + cache.put("3", "three"); + + assertThat(cache.size()).isEqualTo(2); + assertThat(cache.containsKey("1")).isFalse(); + assertThat(cache.containsKey("2")).isTrue(); + assertThat(cache.containsKey("3")).isTrue(); + } + + @Test + void testAccessOrder() { + LRUCache cache = new LRUCache<>(3); + + cache.put("1", "one"); + cache.put("2", "two"); + cache.put("3", "three"); + + // Access "1" to make it the most recently used + cache.get("1"); + + // Put "4", should evict "2" which is now the least recently used + cache.put("4", "four"); + + assertThat(cache.size()).isEqualTo(3); + assertThat(cache.containsKey("2")).isFalse(); + assertThat(cache.containsKey("1")).isTrue(); + assertThat(cache.containsKey("3")).isTrue(); + assertThat(cache.containsKey("4")).isTrue(); + } +} 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 new file mode 100644 index 00000000..f1121475 --- /dev/null +++ b/org.moreunit.core.test/src/org/moreunit/core/util/ObjectsTest.java @@ -0,0 +1,25 @@ +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(new String("a"), new String("a"))).isTrue(); + + assertThat(Objects.equal("a", null)).isFalse(); + assertThat(Objects.equal(null, "a")).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"})); + } +} diff --git a/org.moreunit.core.test/src/org/moreunit/core/util/StringLengthComparatorTest.java b/org.moreunit.core.test/src/org/moreunit/core/util/StringLengthComparatorTest.java new file mode 100644 index 00000000..00f1d0a8 --- /dev/null +++ b/org.moreunit.core.test/src/org/moreunit/core/util/StringLengthComparatorTest.java @@ -0,0 +1,29 @@ +package org.moreunit.core.util; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.junit.jupiter.api.Test; + +class StringLengthComparatorTest { + + @Test + void testCompare() { + StringLengthComparator comparator = new StringLengthComparator(); + + assertThat(comparator.compare("a", "bb")).isNegative(); + assertThat(comparator.compare("aaa", "bb")).isPositive(); + assertThat(comparator.compare("aa", "bb")).isZero(); + } + + @Test + void testSort() { + List list = Arrays.asList("apple", "pie", "banana", "kiwi"); + Collections.sort(list, new StringLengthComparator()); + + assertThat(list).containsExactly("pie", "kiwi", "apple", "banana"); + } +} From 7d0fca00306c473fccbbc559e2453b7cde4fe10d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 5 Jul 2026 21:16:49 +0000 Subject: [PATCH 2/2] test: improve coverage for utility classes and fix CI swtbot test failure Co-authored-by: RoiSoleil <3462260+RoiSoleil@users.noreply.github.com> --- org.moreunit.swtbot.test/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.moreunit.swtbot.test/pom.xml b/org.moreunit.swtbot.test/pom.xml index 672e58d5..ce67f728 100644 --- a/org.moreunit.swtbot.test/pom.xml +++ b/org.moreunit.swtbot.test/pom.xml @@ -22,8 +22,8 @@ org.eclipse.tycho tycho-surefire-plugin - true - false + ${tests.use.ui} + ${tests.use.ui} org.eclipse.platform.ide org.eclipse.ui.ide.workbench