From 8ee92bd67408243380bc11e7cf9db2db98522c3b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 04:11:20 +0000 Subject: [PATCH 1/6] Initial plan From ad6511d4cc8f1f45b5f2513a38a4dc079edc385d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 04:19:16 +0000 Subject: [PATCH 2/6] Add test cases to enhance coverage for ThrowableFunction and FileExtensionFilter Co-authored-by: mercyblitz <533114+mercyblitz@users.noreply.github.com> --- .../io/filter/FileExtensionFilterTest.java | 17 +++++++++++ .../lang/function/ThrowableFunctionTest.java | 30 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/io/filter/FileExtensionFilterTest.java b/microsphere-java-core/src/test/java/io/microsphere/io/filter/FileExtensionFilterTest.java index 5a3b1f671..9f724957e 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/io/filter/FileExtensionFilterTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/io/filter/FileExtensionFilterTest.java @@ -60,4 +60,21 @@ void testMatches() { assertTrue(this.instance.matches("txt", false)); assertTrue(this.instance.matches("TXT", false)); } + + @Test + void testOfWithDotPrefixedExtension() throws IOException { + FileExtensionFilter dotPrefixedFilter = of(".txt"); + File testFile = createTempFile("test", ".txt"); + assertTrue(dotPrefixedFilter.accept(testFile)); + testFile.deleteOnExit(); + } + + @Test + void testAcceptFilenameFilter() throws IOException { + File tmpDir = new File(JAVA_IO_TMPDIR); + File testFile = createTempFile("test", ".txt"); + assertTrue(this.instance.accept(tmpDir, testFile.getName())); + assertFalse(this.instance.accept(tmpDir, "file.xml")); + testFile.deleteOnExit(); + } } \ No newline at end of file diff --git a/microsphere-java-core/src/test/java/io/microsphere/lang/function/ThrowableFunctionTest.java b/microsphere-java-core/src/test/java/io/microsphere/lang/function/ThrowableFunctionTest.java index 3f619c490..3be2e987c 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/lang/function/ThrowableFunctionTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/lang/function/ThrowableFunctionTest.java @@ -74,9 +74,39 @@ void testCompose() throws Throwable { assertEquals(1, stringToInteger.compose(function).apply("1")); } + @Test + void testComposeWithNullBefore() { + assertThrows(IllegalArgumentException.class, () -> function.compose(null)); + } + @Test void testAndThen() throws Throwable { assertEquals(1, function.andThen(stringToInteger).apply("1")); } + @Test + void testAndThenWithNullAfter() { + assertThrows(IllegalArgumentException.class, () -> function.andThen(null)); + } + + @Test + void testExecute1WithCustomHandlerReturningFallback() { + assertEquals("fallback", throwableFunction.execute("For testing", (t, e) -> "fallback")); + } + + @Test + void testExecute2WithNullFunction() { + assertThrows(NullPointerException.class, () -> execute("test", null)); + } + + @Test + void testExecute3WithNullFunction() { + assertThrows(IllegalArgumentException.class, () -> execute("test", null, (t, e) -> t)); + } + + @Test + void testExecute3WithNullExceptionHandler() { + assertThrows(IllegalArgumentException.class, () -> execute("test", function, null)); + } + } From 0fcccbbe18908915a4eeae9ec9aa80a9ff6cbe68 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 04:39:55 +0000 Subject: [PATCH 3/6] Add test cases to enhance coverage for JSONArray, JSONObject, StandardFileWatchService, and ArtifactDetector Co-authored-by: mercyblitz <533114+mercyblitz@users.noreply.github.com> --- .../classloading/ArtifactDetectorTest.java | 14 +++++ .../io/StandardFileWatchServiceTest.java | 48 ++++++++++++++ .../io/microsphere/json/JSONArrayTest.java | 62 +++++++++++++++++++ .../io/microsphere/json/JSONObjectTest.java | 51 +++++++++++++++ 4 files changed, 175 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/classloading/ArtifactDetectorTest.java b/microsphere-java-core/src/test/java/io/microsphere/classloading/ArtifactDetectorTest.java index efb90f837..5fa93f64a 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/classloading/ArtifactDetectorTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/classloading/ArtifactDetectorTest.java @@ -54,4 +54,18 @@ void testDetectOnEmptySet() { ArtifactDetector instance = new ArtifactDetector(null); assertTrue(instance.detect(emptySet()).isEmpty()); } + + @Test + void testDetectWithIncludedJdkLibraries() { + ArtifactDetector instance = new ArtifactDetector(); + List artifacts = instance.detect(true); + assertNotNull(artifacts); + } + + @Test + void testDetectWithExcludedJdkLibraries() { + ArtifactDetector instance = new ArtifactDetector(); + List artifacts = instance.detect(false); + assertNotNull(artifacts); + } } diff --git a/microsphere-java-core/src/test/java/io/microsphere/io/StandardFileWatchServiceTest.java b/microsphere-java-core/src/test/java/io/microsphere/io/StandardFileWatchServiceTest.java index 721d0c541..f31c4e5f0 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/io/StandardFileWatchServiceTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/io/StandardFileWatchServiceTest.java @@ -52,6 +52,7 @@ import static io.microsphere.util.ArrayUtils.ofArray; import static io.microsphere.util.ClassLoaderUtils.getResource; import static io.microsphere.util.ExceptionUtils.wrap; +import static io.microsphere.collection.Lists.ofList; import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.file.Files.copy; import static java.nio.file.Files.write; @@ -265,4 +266,51 @@ private void async(ThrowableAction task) { } } + @Test + void testIsStartedBeforeStart() { + StandardFileWatchService fileWatchService = new StandardFileWatchService(); + assertFalse(fileWatchService.isStarted()); + } + + @Test + void testCloseWithoutStart() throws Exception { + StandardFileWatchService fileWatchService = new StandardFileWatchService(); + assertFalse(fileWatchService.isStarted()); + fileWatchService.close(); + assertFalse(fileWatchService.isStarted()); + } + + @Test + void testWatchWithMultipleListeners() throws Exception { + AtomicReference fileReference = new AtomicReference<>(); + + try (StandardFileWatchService fileWatchService = new StandardFileWatchService()) { + + FileChangedListener listener1 = new FileChangedListener() { + @Override + public void onFileCreated(FileChangedEvent event) { + fileReference.set(event.getFile()); + } + }; + + FileChangedListener listener2 = new LoggingFileChangedListener(); + + fileWatchService.watch(this.testDir, ofList(listener1, listener2), CREATED); + + fileWatchService.start(); + + assertTrue(fileWatchService.isStarted()); + + File testFile = createRandomFile(testDir); + + while (!testFile.equals(fileReference.get())) { + // spin + } + + fileWatchService.stop(); + + assertFalse(fileWatchService.isStarted()); + } + } + } diff --git a/microsphere-java-core/src/test/java/io/microsphere/json/JSONArrayTest.java b/microsphere-java-core/src/test/java/io/microsphere/json/JSONArrayTest.java index 4947aa4b4..c1b36ae30 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/json/JSONArrayTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/json/JSONArrayTest.java @@ -446,4 +446,66 @@ void testHashCode() { assertEquals(jsonArray.hashCode(), jsonArray.hashCode()); assertEquals(ofList(1, 2, 3).hashCode(), jsonArray.hashCode()); } + + @Test + void testPutDoubleOnInvalidValue() { + assertThrows(JSONException.class, () -> jsonArray.put(NaN)); + assertThrows(JSONException.class, () -> jsonArray.put(Double.POSITIVE_INFINITY)); + assertThrows(JSONException.class, () -> jsonArray.put(Double.NEGATIVE_INFINITY)); + } + + @Test + void testPutDoubleWithIndexOnInvalidValue() { + assertThrows(JSONException.class, () -> jsonArray.put(0, NaN)); + assertThrows(JSONException.class, () -> jsonArray.put(0, Double.POSITIVE_INFINITY)); + assertThrows(JSONException.class, () -> jsonArray.put(0, Double.NEGATIVE_INFINITY)); + } + + @Test + void testOptBooleanWithFallback() { + jsonArray.put(true); + jsonArray.put("false"); + assertTrue(jsonArray.optBoolean(0, false)); + assertFalse(jsonArray.optBoolean(1, true)); + assertTrue(jsonArray.optBoolean(2, true)); + assertFalse(jsonArray.optBoolean(-1, false)); + } + + @Test + void testOptDoubleWithFallback() throws JSONException { + jsonArray.put(1.0); + jsonArray.put("not-a-number"); + assertEquals(1.0, jsonArray.optDouble(0, 99.0)); + assertEquals(99.0, jsonArray.optDouble(1, 99.0)); + assertEquals(99.0, jsonArray.optDouble(2, 99.0)); + assertEquals(99.0, jsonArray.optDouble(-1, 99.0)); + } + + @Test + void testOptIntWithFallback() throws JSONException { + jsonArray.put(42); + jsonArray.put("not-a-number"); + assertEquals(42, jsonArray.optInt(0, 99)); + assertEquals(99, jsonArray.optInt(1, 99)); + assertEquals(99, jsonArray.optInt(2, 99)); + assertEquals(99, jsonArray.optInt(-1, 99)); + } + + @Test + void testOptLongWithFallback() throws JSONException { + jsonArray.put(42L); + jsonArray.put("not-a-number"); + assertEquals(42L, jsonArray.optLong(0, 99L)); + assertEquals(99L, jsonArray.optLong(1, 99L)); + assertEquals(99L, jsonArray.optLong(2, 99L)); + assertEquals(99L, jsonArray.optLong(-1, 99L)); + } + + @Test + void testOptStringWithFallback() { + jsonArray.put("Hello"); + assertEquals("Hello", jsonArray.optString(0, "default")); + assertEquals("default", jsonArray.optString(1, "default")); + assertEquals("default", jsonArray.optString(-1, "default")); + } } \ No newline at end of file diff --git a/microsphere-java-core/src/test/java/io/microsphere/json/JSONObjectTest.java b/microsphere-java-core/src/test/java/io/microsphere/json/JSONObjectTest.java index 27577d142..65d9c398c 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/json/JSONObjectTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/json/JSONObjectTest.java @@ -538,6 +538,57 @@ void testNULLToString() { assertEquals("null", NULL.toString()); } + @Test + void testPutDoubleOnInvalidValue() { + assertThrows(JSONException.class, () -> jsonObject.put("value", NaN)); + assertThrows(JSONException.class, () -> jsonObject.put("value", POSITIVE_INFINITY)); + assertThrows(JSONException.class, () -> jsonObject.put("value", NEGATIVE_INFINITY)); + } + + @Test + void testOptBooleanWithFallback() throws JSONException { + jsonObject.put("value", TRUE); + assertEquals(true, jsonObject.optBoolean("value", false)); + assertEquals(false, jsonObject.optBoolean("missing", false)); + assertEquals(true, jsonObject.optBoolean("missing", true)); + } + + @Test + void testOptDoubleWithFallback() throws JSONException { + jsonObject.put("value", Double.valueOf(1.0)); + assertEquals(1.0, jsonObject.optDouble("value", 99.0)); + assertEquals(99.0, jsonObject.optDouble("missing", 99.0)); + } + + @Test + void testOptIntWithFallback() throws JSONException { + jsonObject.put("value", Integer.valueOf(42)); + assertEquals(42, jsonObject.optInt("value", 99)); + assertEquals(99, jsonObject.optInt("missing", 99)); + } + + @Test + void testOptLongWithFallback() throws JSONException { + jsonObject.put("value", Long.valueOf(42L)); + assertEquals(42L, jsonObject.optLong("value", 99L)); + assertEquals(99L, jsonObject.optLong("missing", 99L)); + } + + @Test + void testOptStringWithFallback() throws JSONException { + jsonObject.put("name", "Mercy"); + assertEquals("Mercy", jsonObject.optString("name", "default")); + assertEquals("default", jsonObject.optString("missing", "default")); + } + + @Test + void testWriteTo() throws JSONException { + jsonObject.put("name", "Mercy").put("age", 18); + JSONStringer stringer = new JSONStringer(); + jsonObject.writeTo(stringer); + assertEquals("{\"name\":\"Mercy\",\"age\":18}", stringer.toString()); + } + void assertWrap(Object object) { assertEquals(object, wrap(object)); } From 2d1195f07c00bac62b0e0fb3a738042db5beeeeb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 05:04:32 +0000 Subject: [PATCH 4/6] Add test cases to enhance coverage for AbstractConverter, AbstractDeque, StringToIterableConverter, and AbstractURLClassPathHandle Co-authored-by: mercyblitz <533114+mercyblitz@users.noreply.github.com> --- .../AbstractURLClassPathHandleTest.java | 10 ++ .../collection/AbstractDequeTest.java | 40 ++++++ .../convert/AbstractConverterTest.java | 22 ++++ .../StringToIterableConverterTest.java | 124 ++++++++++++++++++ 4 files changed, 196 insertions(+) create mode 100644 microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToIterableConverterTest.java diff --git a/microsphere-java-core/src/test/java/io/microsphere/classloading/AbstractURLClassPathHandleTest.java b/microsphere-java-core/src/test/java/io/microsphere/classloading/AbstractURLClassPathHandleTest.java index 6a1e12c1c..112764087 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/classloading/AbstractURLClassPathHandleTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/classloading/AbstractURLClassPathHandleTest.java @@ -43,4 +43,14 @@ abstract class AbstractURLClassPathHandleTest extends BaseURLClassPathHandleTest void testGetPriority() { assertEquals(DEFAULT_PRIORITY, handle.getPriority()); } + + @Test + void testSetPriority() { + int newPriority = 42; + handle.setPriority(newPriority); + assertEquals(newPriority, handle.getPriority()); + // Restore default priority + handle.setPriority(DEFAULT_PRIORITY); + assertEquals(DEFAULT_PRIORITY, handle.getPriority()); + } } diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/AbstractDequeTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/AbstractDequeTest.java index 1361b351e..7e6ba5eb5 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/AbstractDequeTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/AbstractDequeTest.java @@ -197,4 +197,44 @@ void testSize() { deque.poll(); assertEquals(0, deque.size()); } + + @Test + void testRemoveFirstOccurrenceWithMultipleOccurrences() { + TestDeque multiDeque = new TestDeque<>(); + multiDeque.add("A"); + multiDeque.add("B"); + multiDeque.add("A"); + // removeFirstOccurrence delegates to remove(o) in AbstractDeque which removes the first occurrence + assertTrue(multiDeque.removeFirstOccurrence("A")); + assertEquals(2, multiDeque.size()); + // "B" and the second "A" should remain, in order + Iterator it = multiDeque.iterator(); + assertEquals("B", it.next()); + assertEquals("A", it.next()); + assertFalse(it.hasNext()); + } + + @Test + void testOfferAndPollSequence() { + TestDeque multiDeque = new TestDeque<>(); + assertTrue(multiDeque.offer("X")); + assertTrue(multiDeque.offer("Y")); + assertTrue(multiDeque.offer("Z")); + // offer delegates to offerLast; poll delegates to pollFirst (FIFO) + assertEquals("X", multiDeque.poll()); + assertEquals("Y", multiDeque.poll()); + assertEquals("Z", multiDeque.poll()); + assertNull(multiDeque.poll()); + } + + @Test + void testPushAndPop() { + TestDeque multiDeque = new TestDeque<>(); + multiDeque.push("X"); + multiDeque.push("Y"); + // push delegates to addFirst (LIFO) + assertEquals("Y", multiDeque.pop()); + assertEquals("X", multiDeque.pop()); + assertThrows(NoSuchElementException.class, () -> multiDeque.pop()); + } } \ No newline at end of file diff --git a/microsphere-java-core/src/test/java/io/microsphere/convert/AbstractConverterTest.java b/microsphere-java-core/src/test/java/io/microsphere/convert/AbstractConverterTest.java index 08b924c4a..28eb8e1fe 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/convert/AbstractConverterTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/convert/AbstractConverterTest.java @@ -25,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * {@link AbstractConverter} Test @@ -102,4 +103,25 @@ void testEquals() { assertNotEquals(this.converter, StringToBooleanConverter.INSTANCE); assertNotEquals(this.converter, ObjectToStringConverter.INSTANCE); } + + @Test + void testHashCode() { + AbstractConverter another = createConverter(); + assertEquals(this.converter.hashCode(), another.hashCode()); + assertNotEquals(this.converter.hashCode(), StringToBooleanConverter.INSTANCE.hashCode()); + assertNotEquals(this.converter.hashCode(), ObjectToStringConverter.INSTANCE.hashCode()); + } + + @Test + void testResolvePriority() { + // When resolvePriority() returns a non-null value, getPriority() returns that value + AbstractConverter converter = new AbstractConverter() { + @Override + protected Integer doConvert(String source) { + return Integer.parseInt(source); + } + }; + // The priority is derived from the type hierarchy and must be negative + assertTrue(converter.getPriority() < 0); + } } diff --git a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToIterableConverterTest.java b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToIterableConverterTest.java new file mode 100644 index 000000000..d1ef1e2e8 --- /dev/null +++ b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToIterableConverterTest.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.microsphere.convert.multiple; + +import io.microsphere.convert.StringConverter; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import static java.lang.Integer.MAX_VALUE; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * {@link StringToIterableConverter} Test + * + * @author Mercy + * @see StringToIterableConverter + * @since 1.0.0 + */ +class StringToIterableConverterTest { + + private StringToCollectionConverter converter; + + @BeforeEach + void setUp() { + converter = new StringToCollectionConverter(); + } + + @Test + void testAccept() { + assertTrue(converter.accept(String.class, Collection.class)); + assertTrue(converter.accept(String.class, List.class)); + assertTrue(converter.accept(String.class, Set.class)); + assertFalse(converter.accept(String.class, String.class)); + assertFalse(converter.accept(null, null)); + } + + @Test + void testConvert() { + Collection result = (Collection) converter.convert("1,2,3", Collection.class, Integer.class); + assertNotNull(result); + assertEquals(3, result.size()); + assertTrue(result.contains(1)); + assertTrue(result.contains(2)); + assertTrue(result.contains(3)); + + Collection strResult = (Collection) converter.convert("a,b", Collection.class, String.class); + assertNotNull(strResult); + assertEquals(2, strResult.size()); + assertTrue(strResult.contains("a")); + assertTrue(strResult.contains("b")); + } + + @Test + void testConvertOnNoStringConverter() { + // No StringConverter registered for Object.class → returns null + assertNull(converter.convert(new String[]{"a"}, 1, Collection.class, Object.class)); + } + + @Test + void testConvertOnNonCollectionIterable() { + // When createMultiValue returns a non-Collection Iterable, the elements are not added; + // the iterable is returned as-is once a StringConverter is found for the element type. + StringToIterableConverter iterableConverter = new StringToIterableConverter() { + @Override + protected Iterable createMultiValue(int size, Class multiValueType) { + return Collections::emptyIterator; + } + }; + + Object result = iterableConverter.convert(new String[]{"1", "2"}, 2, Iterable.class, Integer.class); + assertNotNull(result); + } + + @Test + void testGetStringConverter() { + // Integer has a registered StringConverter + Optional intConverter = converter.getStringConverter(Integer.class); + assertTrue(intConverter.isPresent()); + + // Object.class has no registered StringConverter + Optional objectConverter = converter.getStringConverter(Object.class); + assertFalse(objectConverter.isPresent()); + } + + @Test + void testGetSupportedType() { + assertEquals(Collection.class, converter.getSupportedType()); + } + + @Test + void testGetPriority() { + // Collection has 1 interface level above Iterable, so level=1 → priority = MAX_VALUE - 1 + assertEquals(MAX_VALUE - 1, converter.getPriority()); + } + + @Test + void testGetSourceType() { + assertEquals(String.class, converter.getSourceType()); + } +} From fd30f1ff6cfb976b1a70165f3e81560f076fd9e7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 07:04:42 +0000 Subject: [PATCH 5/6] Add test cases to enhance coverage for Sets, Lists, Maps, and ReflectionUtils Co-authored-by: mercyblitz <533114+mercyblitz@users.noreply.github.com> --- .../io/microsphere/collection/ListsTest.java | 9 ++++ .../io/microsphere/collection/MapsTest.java | 19 +++++++ .../io/microsphere/collection/SetsTest.java | 9 ++++ .../StringToIterableConverterTest.java | 4 ++ .../reflect/ReflectionUtilsTest.java | 50 +++++++++++++++++++ 5 files changed, 91 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/ListsTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/ListsTest.java index 5cce7323f..375751aeb 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/ListsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/ListsTest.java @@ -7,6 +7,7 @@ import static io.microsphere.collection.Lists.ofList; import static java.util.Collections.emptyList; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * {@link Lists} Test @@ -77,4 +78,12 @@ void testOfList() { assertEquals(emptyList(), ofList(TEST_NULL_OBJECT_ARRAY)); assertEquals(of(1, 2, 3), ofList(1, 2, 3)); } + + @Test + void testOfListImmutability() { + assertThrows(UnsupportedOperationException.class, () -> ofList().add("x")); + assertThrows(UnsupportedOperationException.class, () -> ofList(1).add(2)); + assertThrows(UnsupportedOperationException.class, () -> ofList(1, 2).remove(0)); + assertThrows(UnsupportedOperationException.class, () -> ofList(1, 2, 3).clear()); + } } \ No newline at end of file diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/MapsTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/MapsTest.java index 5205f2710..0ec9c6c59 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/MapsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/MapsTest.java @@ -11,6 +11,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * {@link Maps} Test @@ -186,4 +187,22 @@ void testMapOfOnEmptyEntries() { Map map = Maps.ofMap(new Map.Entry[0]); assertSame(emptyMap(), map); } + + @Test + void testOfMapOnSingleEntry() { + Map.Entry entry = ofEntry("A", 1); + Map map = Maps.ofMap(entry); + assertEquals(1, map.size()); + assertEquals(1, map.get("A")); + assertNull(map.get("B")); + assertOfMap(map); + } + + @Test + void testOfMapImmutability() { + assertThrows(UnsupportedOperationException.class, () -> ofMap().put("k", "v")); + assertThrows(UnsupportedOperationException.class, () -> ofMap("A", 1).put("B", 2)); + assertThrows(UnsupportedOperationException.class, () -> ofMap("A", 1, "B", 2).remove("A")); + assertThrows(UnsupportedOperationException.class, () -> ofMap("A", 1, "B", 2, "C", 3).clear()); + } } \ No newline at end of file diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/SetsTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/SetsTest.java index afdabee1c..521663ae2 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/SetsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/SetsTest.java @@ -7,6 +7,7 @@ import static io.microsphere.collection.Sets.ofSet; import static java.util.Collections.emptySet; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * {@link Sets} Test @@ -77,4 +78,12 @@ void testOfSet() { assertEquals(emptySet(), ofSet(TEST_NULL_OBJECT_ARRAY)); assertEquals(of(1, 2, 3), ofSet(1, 2, 3)); } + + @Test + void testOfSetImmutability() { + assertThrows(UnsupportedOperationException.class, () -> ofSet().add("x")); + assertThrows(UnsupportedOperationException.class, () -> ofSet(1).add(2)); + assertThrows(UnsupportedOperationException.class, () -> ofSet(1, 2).remove(1)); + assertThrows(UnsupportedOperationException.class, () -> ofSet(1, 2, 3).clear()); + } } \ No newline at end of file diff --git a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToIterableConverterTest.java b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToIterableConverterTest.java index d1ef1e2e8..cc42d91ac 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToIterableConverterTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToIterableConverterTest.java @@ -36,8 +36,12 @@ /** * {@link StringToIterableConverter} Test * + *

Tests the abstract {@link StringToIterableConverter} behavior using + * {@link StringToCollectionConverter} as the concrete implementation.

+ * * @author Mercy * @see StringToIterableConverter + * @see StringToCollectionConverter * @since 1.0.0 */ class StringToIterableConverterTest { diff --git a/microsphere-java-core/src/test/java/io/microsphere/reflect/ReflectionUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/reflect/ReflectionUtilsTest.java index 8060c6a43..0d639d66c 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/reflect/ReflectionUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/reflect/ReflectionUtilsTest.java @@ -10,6 +10,12 @@ import static io.microsphere.collection.Lists.ofList; import static io.microsphere.reflect.ReflectionUtils.INACCESSIBLE_OBJECT_EXCEPTION_CLASS; import static io.microsphere.reflect.ReflectionUtils.INACCESSIBLE_OBJECT_EXCEPTION_CLASS_NAME; +import static io.microsphere.reflect.ReflectionUtils.STACK_WALKER_CLASS; +import static io.microsphere.reflect.ReflectionUtils.STACK_WALKER_CLASS_NAME; +import static io.microsphere.reflect.ReflectionUtils.STACK_WALKER_STACK_FRAME_CLASS; +import static io.microsphere.reflect.ReflectionUtils.STACK_WALKER_STACK_FRAME_CLASS_NAME; +import static io.microsphere.reflect.ReflectionUtils.SUN_REFLECT_REFLECTION_CLASS; +import static io.microsphere.reflect.ReflectionUtils.SUN_REFLECT_REFLECTION_CLASS_NAME; import static io.microsphere.reflect.ReflectionUtils.getCallerClass; import static io.microsphere.reflect.ReflectionUtils.getCallerClassInSunReflectReflection; import static io.microsphere.reflect.ReflectionUtils.getCallerClassName; @@ -28,6 +34,7 @@ import static java.util.Arrays.asList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -144,6 +151,49 @@ void testIsInaccessibleObjectException() { assertTrue(isInaccessibleObjectException(INACCESSIBLE_OBJECT_EXCEPTION_CLASS_NAME)); } + @Test + void testReadFieldsAsMapOnNull() { + assertTrue(readFieldsAsMap(null).isEmpty()); + } + + @Test + void testConstants() { + assertEquals("sun.reflect.Reflection", SUN_REFLECT_REFLECTION_CLASS_NAME); + assertEquals("java.lang.StackWalker", STACK_WALKER_CLASS_NAME); + assertEquals("java.lang.StackWalker$StackFrame", STACK_WALKER_STACK_FRAME_CLASS_NAME); + assertEquals("java.lang.reflect.InaccessibleObjectException", INACCESSIBLE_OBJECT_EXCEPTION_CLASS_NAME); + } + + @Test + void testStackWalkerClassAvailability() { + if (testCurrentJavaVersion("<", JAVA_VERSION_9)) { + assertNull(STACK_WALKER_CLASS); + assertNull(STACK_WALKER_STACK_FRAME_CLASS); + } else { + assertNotNull(STACK_WALKER_CLASS); + assertNotNull(STACK_WALKER_STACK_FRAME_CLASS); + } + } + + @Test + void testSunReflectReflectionClassAvailability() { + boolean supported = isSupportedSunReflectReflection(); + if (supported) { + assertNotNull(SUN_REFLECT_REFLECTION_CLASS); + } + // On JDK 9+, sun.reflect.Reflection#getCallerClass(int) was removed, + // so isSupportedSunReflectReflection() returns false even though the class may exist + } + + @Test + void testGetCallerClassInSunReflectReflectionWithOffset() { + if (isSupportedSunReflectReflection()) { + assertNotNull(getCallerClassInSunReflectReflection(0)); + } else { + assertNull(getCallerClassInSunReflectReflection(0)); + } + } + static class T extends Data { private T self; From af5d740f8158c23cf337c059435881d42530fc28 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 07:12:09 +0000 Subject: [PATCH 6/6] Update JUnit Jupiter from 5.14.2 to 5.14.3 on Maven profile java8-16 Co-authored-by: mercyblitz <533114+mercyblitz@users.noreply.github.com> --- microsphere-java-parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-parent/pom.xml b/microsphere-java-parent/pom.xml index 7e44ed37b..6dd2b30be 100644 --- a/microsphere-java-parent/pom.xml +++ b/microsphere-java-parent/pom.xml @@ -152,7 +152,7 @@ 5.3.39 - 5.14.2 + 5.14.3 4.11.0