From cb35b2f96ed0a2198f0d42e9c9e46210b118e2b9 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 12:09:21 +0800 Subject: [PATCH 001/115] Update IOUtilsTest.java --- .../src/test/java/io/microsphere/io/IOUtilsTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/io/IOUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/io/IOUtilsTest.java index 33195eb03..83f97ee77 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/io/IOUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/io/IOUtilsTest.java @@ -90,4 +90,16 @@ public void testClose() { destroy(); close(new FastByteArrayOutputStream(0)); } + + @Test + public void testCloseOnNull() { + close(null); + } + + @Test + public void testCloseOnIOException() { + close(() -> { + throw new IOException("For testing"); + }); + } } \ No newline at end of file From dd30b49bb9d9c525666a554a16370f3c560d40ac Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 12:09:24 +0800 Subject: [PATCH 002/115] Update FastByteArrayInputStreamTest.java --- .../java/io/microsphere/io/FastByteArrayInputStreamTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/io/FastByteArrayInputStreamTest.java b/microsphere-java-core/src/test/java/io/microsphere/io/FastByteArrayInputStreamTest.java index b1e3832e1..46afab79f 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/io/FastByteArrayInputStreamTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/io/FastByteArrayInputStreamTest.java @@ -50,10 +50,12 @@ public void testRead() { assertEquals('l', inputStream.read()); assertEquals('l', inputStream.read()); assertEquals('o', inputStream.read()); + assertEquals(-1, inputStream.read()); assertEquals('l', inputStream2.read()); assertEquals('l', inputStream2.read()); assertEquals('o', inputStream2.read()); + assertEquals(-1, inputStream2.read()); } @Test From 96d54fa1a33479cfe0fe5d758da2c85121be0f06 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 13:31:32 +0800 Subject: [PATCH 003/115] Update DelegatingURLConnectionTest.java --- .../net/DelegatingURLConnectionTest.java | 246 ++++++++++++++++-- 1 file changed, 227 insertions(+), 19 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/DelegatingURLConnectionTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/DelegatingURLConnectionTest.java index c82a96b35..e2106d1b9 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/DelegatingURLConnectionTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/DelegatingURLConnectionTest.java @@ -17,13 +17,21 @@ package io.microsphere.net; import io.microsphere.io.IOUtils; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.io.IOException; import java.net.URL; import java.net.URLConnection; +import java.util.List; +import java.util.Map; +import static java.lang.System.currentTimeMillis; 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; @@ -35,6 +43,12 @@ */ public class DelegatingURLConnectionTest { + private static final String CONTENT_LENGTH_HEADER_NAME = "content-length"; + + private static final String LAST_MODIFIED_HEADER_NAME = "last-modified"; + + private static final String NOT_EXISTS_HEADER_NAME = "not-exists"; + private URL url; private URLConnection delegate; @@ -42,41 +56,142 @@ public class DelegatingURLConnectionTest { private DelegatingURLConnection urlConnection; @BeforeEach - public void before() throws Exception { + public void init() throws Exception { URL baseURL = getClass().getProtectionDomain().getCodeSource().getLocation(); this.url = new URL(baseURL.toString() + "META-INF/test.properties"); this.delegate = url.openConnection(); this.urlConnection = new DelegatingURLConnection(this.delegate); } + @AfterEach + public void destroy() { + } + + @Test + public void testConnect() throws IOException { + this.urlConnection.connect(); + } + + @Test + public void testSetConnectTimeout() { + this.urlConnection.setConnectTimeout(100); + } + + @Test + public void testGetConnectTimeout() { + testSetConnectTimeout(); + assertEquals(100, this.urlConnection.getConnectTimeout()); + } + + @Test + public void testSetReadTimeout() { + this.urlConnection.setReadTimeout(200); + } + @Test - public void testStatus() throws Exception { + public void testGetReadTimeout() { + testSetReadTimeout(); + assertEquals(200, this.urlConnection.getReadTimeout()); + } + + @Test + public void testGetURL() { assertEquals(url, urlConnection.getURL()); + } - urlConnection.setConnectTimeout(1); - assertEquals(1, urlConnection.getConnectTimeout()); + @Test + public void testGetContentLength() { + assertEquals(19, urlConnection.getContentLength()); + } - urlConnection.setAllowUserInteraction(true); - assertTrue(urlConnection.getAllowUserInteraction()); + @Test + public void testGetContentLengthLong() { + assertEquals(19, urlConnection.getContentLengthLong()); + } - urlConnection.setDefaultUseCaches(true); - assertTrue(urlConnection.getDefaultUseCaches()); + @Test + public void testGetContentType() { + assertEquals("content/unknown", urlConnection.getContentType()); + } - urlConnection.setDoInput(true); - assertTrue(urlConnection.getDoInput()); + @Test + public void testGetContentEncoding() { + assertNull(urlConnection.getContentEncoding()); + } - urlConnection.setDoOutput(true); - assertTrue(urlConnection.getDoOutput()); + @Test + public void testGetExpiration() { + assertEquals(0, urlConnection.getExpiration()); + } - long now = System.currentTimeMillis(); - urlConnection.setIfModifiedSince(now); - assertEquals(now, urlConnection.getIfModifiedSince()); + @Test + public void testGetDate() { + assertEquals(0, urlConnection.getDate()); + } - urlConnection.setReadTimeout(2); - assertEquals(2, urlConnection.getReadTimeout()); + @Test + public void testGetLastModified() { + assertFalse(urlConnection.getLastModified() > currentTimeMillis()); + } - urlConnection.setUseCaches(true); - assertTrue(urlConnection.getUseCaches()); + @Test + public void testGetHeaderField() { + assertNull(urlConnection.getHeaderField(NOT_EXISTS_HEADER_NAME)); + assertEquals("19", urlConnection.getHeaderField(CONTENT_LENGTH_HEADER_NAME)); + assertNotNull(urlConnection.getHeaderField(LAST_MODIFIED_HEADER_NAME)); + } + + @Test + public void testGetHeaderFields() { + assertTrue(urlConnection.getHeaderFields().isEmpty()); + } + + @Test + public void testGetHeaderFieldInt() { + assertEquals(19, urlConnection.getHeaderFieldInt(CONTENT_LENGTH_HEADER_NAME, 10)); + assertEquals(1, urlConnection.getHeaderFieldInt(NOT_EXISTS_HEADER_NAME, 1)); + } + + @Test + public void testGetHeaderFieldLong() { + assertEquals(19, urlConnection.getHeaderFieldLong(CONTENT_LENGTH_HEADER_NAME, 10)); + assertEquals(1, urlConnection.getHeaderFieldLong(NOT_EXISTS_HEADER_NAME, 1)); + } + + @Test + public void testGetHeaderFieldDate() { + long now = currentTimeMillis(); + assertTrue(now > urlConnection.getHeaderFieldDate(LAST_MODIFIED_HEADER_NAME, now)); + assertEquals(now, urlConnection.getHeaderFieldDate(NOT_EXISTS_HEADER_NAME, now)); + } + + @Test + public void testGetHeaderFieldKey() { + assertEquals(CONTENT_LENGTH_HEADER_NAME, urlConnection.getHeaderFieldKey(0)); + assertEquals(LAST_MODIFIED_HEADER_NAME, urlConnection.getHeaderFieldKey(1)); + assertNull(urlConnection.getHeaderFieldKey(2)); + } + + @Test + public void testGetHeaderFieldWithInt() { + assertEquals("19", urlConnection.getHeaderField(0)); + assertNotNull(urlConnection.getHeaderField(1)); + assertNull(urlConnection.getHeaderFieldKey(2)); + } + + @Test + public void testGetContent() throws IOException { + urlConnection.getContent(); + } + + @Test + public void testGetContentWithClassArray() throws IOException { + urlConnection.getContent(new Class[0]); + } + + @Test + public void testGetPermission() throws IOException { + assertNotNull(urlConnection.getPermission()); } @Test @@ -91,4 +206,97 @@ public void testGetOutputStream() throws Exception { assertThrows(Exception.class, urlConnection::getOutputStream); } + @Test + public void testToString() { + assertNotNull(urlConnection.toString()); + } + + @Test + public void testSetDoInput() { + urlConnection.setDoInput(true); + } + + @Test + public void testGetDoInput() { + testSetDoInput(); + assertTrue(urlConnection.getDoInput()); + } + + @Test + public void testSetDoOutput() { + urlConnection.setDoOutput(true); + } + + @Test + public void testGetDoOutput() { + testSetDoOutput(); + assertTrue(urlConnection.getDoOutput()); + } + + @Test + public void testSetAllowUserInteraction() { + urlConnection.setAllowUserInteraction(true); + } + + @Test + public void testGetAllowUserInteraction() { + testSetAllowUserInteraction(); + assertTrue(urlConnection.getAllowUserInteraction()); + } + + @Test + public void testSetUseCaches() { + urlConnection.setUseCaches(true); + } + + @Test + public void testGetUseCaches() { + testSetUseCaches(); + assertTrue(urlConnection.getUseCaches()); + } + + @Test + public void testSetIfModifiedSince() { + long now = currentTimeMillis(); + urlConnection.setIfModifiedSince(now); + } + + @Test + public void testGetIfModifiedSince() { + testSetIfModifiedSince(); + assertTrue(currentTimeMillis() >= urlConnection.getIfModifiedSince()); + } + + @Test + public void testSetDefaultUseCaches() { + urlConnection.setDefaultUseCaches(true); + } + + @Test + public void testGetDefaultUseCaches() { + urlConnection.setDefaultUseCaches(true); + assertTrue(urlConnection.getDefaultUseCaches()); + } + + @Test + public void testSetRequestProperty() { + urlConnection.setRequestProperty("key-1", "value-1"); + } + + @Test + public void testAddRequestProperty() { + urlConnection.addRequestProperty("key-1", "value-1-1"); + urlConnection.addRequestProperty("key-2", "value-2"); + } + + @Test + public void testGetRequestProperty() { + assertNull(urlConnection.getRequestProperty("key-1")); + } + + @Test + public void testGetRequestProperties() { + Map> requestProperties = urlConnection.getRequestProperties(); + assertNotNull(requestProperties); + } } From 0806662976da8f8073ccd0b025d4e2fab1755ed5 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 13:52:36 +0800 Subject: [PATCH 004/115] Update CompositeURLStreamHandlerFactory.java --- .../io/microsphere/net/CompositeURLStreamHandlerFactory.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/CompositeURLStreamHandlerFactory.java b/microsphere-java-core/src/main/java/io/microsphere/net/CompositeURLStreamHandlerFactory.java index 1e13cecdc..f999a9471 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/CompositeURLStreamHandlerFactory.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/CompositeURLStreamHandlerFactory.java @@ -112,8 +112,6 @@ private void sortFactories(List factories) { @Override public String toString() { - String sb = "CompositeURLStreamHandlerFactory{" + "factories=" + factories + - '}'; - return sb; + return "CompositeURLStreamHandlerFactory{" + "factories=" + factories + '}'; } } From acf0cd23f2f0a049e4c3b4d3bb7a0ebda6c74d74 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 13:52:38 +0800 Subject: [PATCH 005/115] Create CompositeURLStreamHandlerFactoryTest.java --- .../CompositeURLStreamHandlerFactoryTest.java | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 microsphere-java-core/src/test/java/io/microsphere/net/CompositeURLStreamHandlerFactoryTest.java diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/CompositeURLStreamHandlerFactoryTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/CompositeURLStreamHandlerFactoryTest.java new file mode 100644 index 000000000..06fff7d14 --- /dev/null +++ b/microsphere-java-core/src/test/java/io/microsphere/net/CompositeURLStreamHandlerFactoryTest.java @@ -0,0 +1,76 @@ +package io.microsphere.net; + +import io.microsphere.lang.Prioritized; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.net.URLStreamHandler; +import java.net.URLStreamHandlerFactory; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * {@link CompositeURLStreamHandlerFactory} Test + * + * @author Mercy + * @see CompositeURLStreamHandlerFactory + * @since 1.0.0 + */ +public class CompositeURLStreamHandlerFactoryTest { + + private StandardURLStreamHandlerFactory factory; + + private CompositeURLStreamHandlerFactory compositeFactory; + + @BeforeEach + public void init() { + factory = new StandardURLStreamHandlerFactory(); + compositeFactory = new CompositeURLStreamHandlerFactory(); + compositeFactory.addURLStreamHandlerFactory(factory); + } + + @Test + public void testCreateURLStreamHandler() { + URLStreamHandler handler = compositeFactory.createURLStreamHandler("file"); + assertNotNull(handler); + } + + @Test + public void testAddURLStreamHandlerFactory() { + compositeFactory.addURLStreamHandlerFactory(compositeFactory); + } + + @Test + public void testAddURLStreamHandlerFactoryOnNull() { + compositeFactory.addURLStreamHandlerFactory(null); + } + + @Test + public void testAddURLStreamHandlerFactoryOnComposite() { + CompositeURLStreamHandlerFactory newCompositeFactory = new CompositeURLStreamHandlerFactory(); + newCompositeFactory.addURLStreamHandlerFactory(factory); + compositeFactory.addURLStreamHandlerFactory(newCompositeFactory); + } + + @Test + public void testGetFactories() { + testAddURLStreamHandlerFactoryOnComposite(); + List factories = compositeFactory.getFactories(); + assertEquals(1, factories.size()); + assertTrue(factories.contains(factory)); + } + + @Test + public void testGetComparator() { + assertSame(Prioritized.COMPARATOR, compositeFactory.getComparator()); + } + + @Test + public void testTestToString() { + assertNotNull(compositeFactory.toString()); + } +} \ No newline at end of file From 05f2535f6ab044a9110cb75b8ff44d451b73523a Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 13:55:01 +0800 Subject: [PATCH 006/115] Create DelegatingURLStreamHandlerFactoryTest.java --- ...DelegatingURLStreamHandlerFactoryTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 microsphere-java-core/src/test/java/io/microsphere/net/DelegatingURLStreamHandlerFactoryTest.java diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/DelegatingURLStreamHandlerFactoryTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/DelegatingURLStreamHandlerFactoryTest.java new file mode 100644 index 000000000..d0869e641 --- /dev/null +++ b/microsphere-java-core/src/test/java/io/microsphere/net/DelegatingURLStreamHandlerFactoryTest.java @@ -0,0 +1,37 @@ +package io.microsphere.net; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; + +/** + * {@link DelegatingURLStreamHandlerFactory Test} + * + * @author Mercy + * @see DelegatingURLStreamHandlerFactory + * @since 1.0.0 + */ +public class DelegatingURLStreamHandlerFactoryTest { + + private StandardURLStreamHandlerFactory delegate; + + private DelegatingURLStreamHandlerFactory factory; + + @BeforeEach + public void init() { + this.delegate = new StandardURLStreamHandlerFactory(); + this.factory = new DelegatingURLStreamHandlerFactory(this.delegate); + } + + @Test + public void testCreateURLStreamHandler() { + assertNotNull(this.factory.createURLStreamHandler("file")); + } + + @Test + public void testGetDelegate() { + assertSame(this.delegate, this.factory.getDelegate()); + } +} \ No newline at end of file From 1c4bed260ebc358a8313680c8b54308c93485a87 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 13:57:43 +0800 Subject: [PATCH 007/115] Update DelegatingURLStreamHandlerFactory.java --- .../microsphere/net/DelegatingURLStreamHandlerFactory.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/DelegatingURLStreamHandlerFactory.java b/microsphere-java-core/src/main/java/io/microsphere/net/DelegatingURLStreamHandlerFactory.java index 654087a03..86f5f9fbd 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/DelegatingURLStreamHandlerFactory.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/DelegatingURLStreamHandlerFactory.java @@ -19,6 +19,8 @@ import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; +import static io.microsphere.util.Assert.assertNotNull; + /** * Delegating {@link URLStreamHandlerFactory} * @@ -30,9 +32,7 @@ public class DelegatingURLStreamHandlerFactory implements URLStreamHandlerFactor private final URLStreamHandlerFactory delegate; public DelegatingURLStreamHandlerFactory(URLStreamHandlerFactory delegate) { - if (delegate == null) { - throw new NullPointerException("The 'delegate' argument must not be null!"); - } + assertNotNull(delegate, () -> "The 'delegate' argument must not be null!"); this.delegate = delegate; } From 8191f59ba06f662d1849acc06d1355c772f62384 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 13:58:10 +0800 Subject: [PATCH 008/115] Update DelegatingURLStreamHandlerFactoryTest.java --- .../net/DelegatingURLStreamHandlerFactoryTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/DelegatingURLStreamHandlerFactoryTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/DelegatingURLStreamHandlerFactoryTest.java index d0869e641..095c5680f 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/DelegatingURLStreamHandlerFactoryTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/DelegatingURLStreamHandlerFactoryTest.java @@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * {@link DelegatingURLStreamHandlerFactory Test} @@ -25,6 +26,11 @@ public void init() { this.factory = new DelegatingURLStreamHandlerFactory(this.delegate); } + @Test + public void testConstructorOnNull() { + assertThrows(IllegalArgumentException.class, () -> new DelegatingURLStreamHandlerFactory(null)); + } + @Test public void testCreateURLStreamHandler() { assertNotNull(this.factory.createURLStreamHandler("file")); From 3fe31de497aba8e2d6cd8867191bc0fd8c12a740 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 17:12:30 +0800 Subject: [PATCH 009/115] Update DelegatingURLConnectionTest.java --- .../java/io/microsphere/net/DelegatingURLConnectionTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/DelegatingURLConnectionTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/DelegatingURLConnectionTest.java index e2106d1b9..892630543 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/DelegatingURLConnectionTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/DelegatingURLConnectionTest.java @@ -143,7 +143,7 @@ public void testGetHeaderField() { @Test public void testGetHeaderFields() { - assertTrue(urlConnection.getHeaderFields().isEmpty()); + assertNotNull(urlConnection.getHeaderFields()); } @Test From 719f192b9252c821210ff9d116cce9847bf4a97f Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 17:49:47 +0800 Subject: [PATCH 010/115] Update ExtendableProtocolURLStreamHandler.java --- .../microsphere/net/ExtendableProtocolURLStreamHandler.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java b/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java index f799d2404..cf69743d3 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java @@ -39,6 +39,7 @@ import static io.microsphere.net.URLUtils.SUB_PROTOCOL_MATRIX_NAME; import static io.microsphere.net.URLUtils.buildMatrixString; import static io.microsphere.net.URLUtils.registerURLStreamHandler; +import static io.microsphere.text.FormatUtils.format; import static io.microsphere.util.StringUtils.isBlank; import static io.microsphere.util.StringUtils.split; import static java.net.Proxy.NO_PROXY; @@ -296,10 +297,7 @@ public final String getProtocol() { @Override public String toString() { - String sb = getClass().getName() + "{defaultPort=" + getDefaultPort() + - ",protocol=" + getProtocol() + - '}'; - return sb; + return format("{} {defaultPort = {} , protocol = '{}'}", getClass().getName(), getDefaultPort(), getProtocol()); } private static String resolveConventionProtocol(String packageName) { From 6bb6a8c211c60bb71f5daed5fd1e9441727a059f Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 18:00:25 +0800 Subject: [PATCH 011/115] Update ExtendableProtocolURLStreamHandlerTest.java --- ...xtendableProtocolURLStreamHandlerTest.java | 208 ++++++++++++++---- 1 file changed, 170 insertions(+), 38 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java index 16606eb10..ec9e189c2 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java @@ -16,20 +16,35 @@ */ package io.microsphere.net; -import io.microsphere.collection.SetUtils; import io.microsphere.net.console.Handler; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.InputStreamReader; import java.net.Proxy; import java.net.URL; +import java.util.List; import java.util.Properties; +import static io.microsphere.collection.ListUtils.newLinkedList; +import static io.microsphere.collection.ListUtils.ofList; +import static io.microsphere.collection.SetUtils.ofSet; +import static io.microsphere.net.ExtendableProtocolURLStreamHandler.appendHandlePackage; +import static io.microsphere.net.ExtendableProtocolURLStreamHandler.getHandlePackages; +import static io.microsphere.net.ExtendableProtocolURLStreamHandler.getHandlePackagesPropertyValue; +import static io.microsphere.net.URLUtils.toExternalForm; +import static java.net.Proxy.NO_PROXY; +import static java.util.Collections.emptyList; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * {@link ExtendableProtocolURLStreamHandler} Test @@ -39,6 +54,27 @@ */ public class ExtendableProtocolURLStreamHandlerTest { + private static final String TEST_URL = "console://localhost:12345/abc"; + + private static final String TEST_URL_WITH_SP = "console:text://localhost:12345/abc"; + + private static final String TEST_URL_WITH_SP_PARAMS = TEST_URL_WITH_SP + ";ref=top?n=1"; + + private static final String TEST_URL_WITH_SP_PARAMS_HASH = TEST_URL_WITH_SP_PARAMS + "#hash"; + + private ExtendableProtocolURLStreamHandler handler; + + @BeforeEach + public void init() { + // Handler for "console" protocol + handler = new Handler(); + } + + @AfterEach + public void destroy() { + } + + @Test public void testConstructorWithProtocolArg() { assertTestHandler("test-1"); @@ -51,42 +87,6 @@ private void assertTestHandler(String protocol) { assertEquals(protocol, handler.getProtocol()); } - - @Test - public void testConsoleProtocol() throws Throwable { - Handler handler = new Handler(); - assertEquals(SetUtils.of("io.microsphere.net"), ExtendableProtocolURLStreamHandler.getHandlePackages()); - assertEquals("io.microsphere.net", ExtendableProtocolURLStreamHandler.getHandlePackagesPropertyValue()); - - String spec = "console:text://localhost:12345/abc;ref=top?n=1#hash"; - URL url = new URL(spec); - assertSame(url.openStream(), handler.openConnection(url).getInputStream()); - assertEquals(spec, url.toString()); - - spec = "console:text://localhost:12345/abc;ref=top?n=1"; - url = new URL(spec); - assertSame(url.openStream(), handler.openConnection(url).getInputStream()); - assertEquals(spec, url.toString()); - - spec = "console:text://localhost:12345/abc?n=1"; - url = new URL(spec); - assertSame(url.openStream(), handler.openConnection(url).getInputStream()); - assertEquals(spec, url.toString()); - - spec = "console:text://localhost:12345/abc"; - url = new URL(spec); - assertSame(url.openStream(), handler.openConnection(url).getInputStream()); - assertEquals(spec, url.toString()); - - spec = "console://localhost:12345/abc"; - url = new URL(spec); - assertSame(url.openStream(), handler.openConnection(url).getInputStream()); - assertEquals(spec, url.toString()); - - assertEquals("console", handler.getProtocol()); - - } - @Test public void testClassPathProtocol() throws Throwable { io.microsphere.net.classpath.Handler handler = new io.microsphere.net.classpath.Handler(); @@ -110,7 +110,6 @@ public void testClassPathProtocol() throws Throwable { url = new URL("classpath:META-INF/services/io.microsphere.event.EventListener"); assertNotNull(url.openConnection(Proxy.NO_PROXY)); - assertEquals("classpath", handler.getProtocol()); } @Test @@ -121,4 +120,137 @@ public void testClassPathProtocolOnResourceNotFound() { url.openStream(); }); } + + + @Test + public void testGetHandlePackages() { + assertEquals(ofSet("io.microsphere.net"), getHandlePackages()); + } + + @Test + public void testGetHandlePackagesPropertyValue() { + assertEquals("io.microsphere.net", getHandlePackagesPropertyValue()); + } + + @Test + public void testAppendHandlePackage() { + appendHandlePackage("io.microsphere.lang"); + assertEquals(ofSet("io.microsphere.net", "io.microsphere"), getHandlePackages()); + assertEquals("io.microsphere.net|io.microsphere", getHandlePackagesPropertyValue()); + } + + @Test + public void testInit() { + handler.init(); + } + + @Test + public void testInitSubProtocolURLConnectionFactories() { + List factories = emptyList(); + List copy = newLinkedList(factories); + handler.initSubProtocolURLConnectionFactories(copy); + assertEquals(copy, factories); + } + + @Test + public void testOpenConnection() throws IOException { + + URL url = new URL(TEST_URL); + assertSame(url.openStream(), handler.openConnection(url, NO_PROXY).getInputStream()); + assertEquals(TEST_URL, url.toString()); + + url = new URL(TEST_URL_WITH_SP); + assertSame(url.openStream(), handler.openConnection(url, NO_PROXY).getInputStream()); + assertEquals(TEST_URL_WITH_SP, url.toString()); + } + + @Test + public void testTestOpenConnection() throws IOException { + String spec = TEST_URL_WITH_SP_PARAMS; + URL url = new URL(spec); + assertSame(url.openStream(), handler.openConnection(url).getInputStream()); + assertEquals(spec, url.toString()); + + spec = TEST_URL_WITH_SP_PARAMS_HASH; + url = new URL(spec); + assertSame(url.openStream(), handler.openConnection(url).getInputStream()); + assertEquals(spec, url.toString()); + } + + @Test + public void testOpenFallbackConnection() throws IOException { + assertNull(handler.openFallbackConnection(null, null)); + } + + @Test + public void testEquals() throws IOException { + assertTrue(handler.equals(new URL(TEST_URL), new URL(TEST_URL))); + assertTrue(handler.equals(new URL(TEST_URL_WITH_SP), new URL(TEST_URL_WITH_SP))); + assertTrue(handler.equals(new URL(TEST_URL_WITH_SP_PARAMS), new URL(TEST_URL_WITH_SP_PARAMS))); + assertTrue(handler.equals(new URL(TEST_URL_WITH_SP_PARAMS_HASH), new URL(TEST_URL_WITH_SP_PARAMS_HASH))); + assertFalse(handler.equals(new URL(TEST_URL), new URL(TEST_URL_WITH_SP))); + assertFalse(handler.equals(new URL(TEST_URL), new URL(TEST_URL_WITH_SP_PARAMS))); + assertFalse(handler.equals(new URL(TEST_URL), new URL(TEST_URL_WITH_SP_PARAMS_HASH))); + } + + @Test + public void testHashCode() throws IOException { + assertEquals(handler.hashCode(new URL(TEST_URL)), new URL(TEST_URL).hashCode()); + assertEquals(handler.hashCode(new URL(TEST_URL_WITH_SP)), new URL(TEST_URL_WITH_SP).hashCode()); + assertEquals(handler.hashCode(new URL(TEST_URL_WITH_SP_PARAMS)), new URL(TEST_URL_WITH_SP_PARAMS).hashCode()); + assertEquals(handler.hashCode(new URL(TEST_URL_WITH_SP_PARAMS_HASH)), new URL(TEST_URL_WITH_SP_PARAMS_HASH).hashCode()); + assertNotEquals(handler.hashCode(new URL(TEST_URL)), new URL(TEST_URL_WITH_SP).hashCode()); + assertNotEquals(handler.hashCode(new URL(TEST_URL)), new URL(TEST_URL_WITH_SP_PARAMS).hashCode()); + assertNotEquals(handler.hashCode(new URL(TEST_URL)), new URL(TEST_URL_WITH_SP_PARAMS_HASH).hashCode()); + } + + @Test + public void testHostsEqual() throws IOException { + assertTrue(handler.hostsEqual(new URL(TEST_URL), new URL(TEST_URL))); + assertTrue(handler.hostsEqual(new URL(TEST_URL), new URL(TEST_URL_WITH_SP))); + assertTrue(handler.hostsEqual(new URL(TEST_URL), new URL(TEST_URL_WITH_SP_PARAMS))); + assertTrue(handler.hostsEqual(new URL(TEST_URL), new URL(TEST_URL_WITH_SP_PARAMS_HASH))); + } + + @Test + public void testToExternalForm() throws IOException { + assertEquals(handler.toExternalForm(new URL(TEST_URL)), toExternalForm(new URL(TEST_URL))); + assertEquals(handler.toExternalForm(new URL(TEST_URL_WITH_SP)), toExternalForm(new URL(TEST_URL_WITH_SP))); + assertEquals(handler.toExternalForm(new URL(TEST_URL_WITH_SP_PARAMS)), toExternalForm(new URL(TEST_URL_WITH_SP_PARAMS))); + assertEquals(handler.toExternalForm(new URL(TEST_URL_WITH_SP_PARAMS_HASH)), toExternalForm(new URL(TEST_URL_WITH_SP_PARAMS_HASH))); + } + + @Test + public void testResolveSubProtocols() throws IOException { + assertEquals(emptyList(), handler.resolveSubProtocols(new URL(TEST_URL))); + assertEquals(ofList("text"), handler.resolveSubProtocols(new URL(TEST_URL_WITH_SP))); + assertEquals(ofList("text"), handler.resolveSubProtocols(new URL(TEST_URL_WITH_SP_PARAMS))); + assertEquals(ofList("text"), handler.resolveSubProtocols(new URL(TEST_URL_WITH_SP_PARAMS_HASH))); + } + + @Test + public void testResolveAuthority() throws IOException { + assertEquals("localhost:12345", handler.resolveAuthority(new URL(TEST_URL))); + assertEquals("localhost:12345", handler.resolveAuthority(new URL(TEST_URL_WITH_SP))); + assertEquals("localhost:12345", handler.resolveAuthority(new URL(TEST_URL_WITH_SP_PARAMS))); + assertEquals("localhost:12345", handler.resolveAuthority(new URL(TEST_URL_WITH_SP_PARAMS_HASH))); + } + + @Test + public void testResolvePath() throws IOException { + assertEquals("/abc", handler.resolvePath(new URL(TEST_URL))); + assertEquals("/abc", handler.resolvePath(new URL(TEST_URL_WITH_SP))); + assertEquals("/abc", handler.resolvePath(new URL(TEST_URL_WITH_SP_PARAMS))); + assertEquals("/abc", handler.resolvePath(new URL(TEST_URL_WITH_SP_PARAMS_HASH))); + } + + @Test + public void testGetProtocol() { + assertEquals("console", handler.getProtocol()); + } + + @Test + public void testToString() { + assertEquals("io.microsphere.net.console.Handler {defaultPort = -1 , protocol = 'console'}", handler.toString()); + } } From 3e2d828d66a5c2c00ad89fc153f0a09c712680f8 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 19:39:09 +0800 Subject: [PATCH 012/115] Update ExtendableProtocolURLStreamHandler.java --- .../net/ExtendableProtocolURLStreamHandler.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java b/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java index cf69743d3..1aca96478 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java @@ -311,28 +311,27 @@ private static void assertConventions(Class type) { assertPackage(type); } - private static void assertClassTopLevel(Class type) { + static void assertClassTopLevel(Class type) { if (type.isLocalClass() || type.isAnonymousClass() || type.isMemberClass()) { - throw new IllegalStateException("The implementation " + type + " must be the top level"); + throw new IllegalArgumentException("The implementation " + type + " must be the top level"); } } - private static void assertClassName(Class type) { + static void assertClassName(Class type) { String simpleClassName = type.getSimpleName(); - String className = HANDLER_CONVENTION_CLASS_NAME; - if (!Objects.equals(className, simpleClassName)) { - throw new IllegalStateException("The implementation class must name '" + className + "', actual : '" + simpleClassName + "'"); + if (!HANDLER_CONVENTION_CLASS_NAME.equals(simpleClassName)) { + throw new IllegalArgumentException("The implementation class must name '" + HANDLER_CONVENTION_CLASS_NAME + "', actual : '" + simpleClassName + "'"); } } - private static void assertPackage(Class type) { + static void assertPackage(Class type) { String className = type.getName(); if (className.indexOf(DOT_CHAR) < 0) { - throw new IllegalStateException("The Handler class must not be present at the top package!"); + throw new IllegalArgumentException("The Handler class must not be present at the top package!"); } String packagePrefix = DEFAULT_HANDLER_PACKAGE_PREFIX; if (className.startsWith(packagePrefix)) { - throw new IllegalStateException("The Handler class must not be present in the builtin package : '" + packagePrefix + "'"); + throw new IllegalArgumentException("The Handler class must not be present in the builtin package : '" + packagePrefix + "'"); } } From 760377097e7fb5eafb032695287b3af3d2d3bc3e Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 19:39:17 +0800 Subject: [PATCH 013/115] Update ExtendableProtocolURLStreamHandlerTest.java --- ...xtendableProtocolURLStreamHandlerTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java index ec9e189c2..932168b9e 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java @@ -32,9 +32,13 @@ import static io.microsphere.collection.ListUtils.ofList; import static io.microsphere.collection.SetUtils.ofSet; import static io.microsphere.net.ExtendableProtocolURLStreamHandler.appendHandlePackage; +import static io.microsphere.net.ExtendableProtocolURLStreamHandler.assertClassName; +import static io.microsphere.net.ExtendableProtocolURLStreamHandler.assertClassTopLevel; +import static io.microsphere.net.ExtendableProtocolURLStreamHandler.assertPackage; import static io.microsphere.net.ExtendableProtocolURLStreamHandler.getHandlePackages; import static io.microsphere.net.ExtendableProtocolURLStreamHandler.getHandlePackagesPropertyValue; import static io.microsphere.net.URLUtils.toExternalForm; +import static io.microsphere.util.ClassLoaderUtils.resolveClass; import static java.net.Proxy.NO_PROXY; import static java.util.Collections.emptyList; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -74,6 +78,38 @@ public void init() { public void destroy() { } + @Test + public void testAssertClassTopLevelOnLocalClass() { + class LocalClass extends ExtendableProtocolURLStreamHandler { + + } + assertThrows(IllegalArgumentException.class, () -> assertClassTopLevel(LocalClass.class)); + } + + @Test + public void testAssertClassTopLevelOnMemberClass() { + assertThrows(IllegalArgumentException.class, () -> assertClassTopLevel(MemberClass.class)); + } + + @Test + public void testAssertClassTopLevelOnAnonymousClass() { + assertThrows(IllegalArgumentException.class, () -> + assertClassTopLevel(new ExtendableProtocolURLStreamHandler() { + }.getClass())); + } + + @Test + public void testAssertClassNameOnWrongClassName() { + assertThrows(IllegalArgumentException.class, () -> assertClassName(MemberClass.class)); + } + + @Test + public void testAssertPackageOnSunHandlerClass() { + Class handler = resolveClass("sun.net.www.protocol.file.Handler"); + if (handler != null) { + assertThrows(IllegalArgumentException.class, () -> assertPackage(handler)); + } + } @Test public void testConstructorWithProtocolArg() { @@ -253,4 +289,7 @@ public void testGetProtocol() { public void testToString() { assertEquals("io.microsphere.net.console.Handler {defaultPort = -1 , protocol = 'console'}", handler.toString()); } + + private static class MemberClass extends ExtendableProtocolURLStreamHandler { + } } From d627b2076f3437d112997bf588ea7be0704e5ff3 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 20:01:05 +0800 Subject: [PATCH 014/115] Update ExtendableProtocolURLStreamHandler.java --- .../net/ExtendableProtocolURLStreamHandler.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java b/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java index 1aca96478..6e8f6f52c 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Objects; import java.util.Set; +import java.util.function.Consumer; import static io.microsphere.collection.SetUtils.of; import static io.microsphere.constants.SymbolConstants.COLON_CHAR; @@ -145,6 +146,15 @@ private void initSubProtocolURLConnectionFactories() { protected void initSubProtocolURLConnectionFactories(List factories) { } + /** + * Customize {@link SubProtocolURLConnectionFactory SubProtocolURLConnectionFactories} + * + * @param factoriesCustomizer the customizer for collection of {@link SubProtocolURLConnectionFactory SubProtocolURLConnectionFactories} + */ + public void customizeSubProtocolURLConnectionFactories(Consumer> factoriesCustomizer) { + factoriesCustomizer.accept(this.factories); + } + @Override protected final URLConnection openConnection(URL u) throws IOException { return openConnection(u, NO_PROXY); From 3b20ba0aae1b2596153828ee42ac1e3844701fea Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 20:01:09 +0800 Subject: [PATCH 015/115] Update ExtendableProtocolURLStreamHandlerTest.java --- ...xtendableProtocolURLStreamHandlerTest.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java index 932168b9e..8731ecb62 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java @@ -190,27 +190,28 @@ public void testInitSubProtocolURLConnectionFactories() { @Test public void testOpenConnection() throws IOException { - URL url = new URL(TEST_URL); assertSame(url.openStream(), handler.openConnection(url, NO_PROXY).getInputStream()); assertEquals(TEST_URL, url.toString()); + } - url = new URL(TEST_URL_WITH_SP); + @Test + public void testOpenConnectionWithProxy() throws IOException { + ExtendableProtocolURLStreamHandler handler = new TestHandler("console"); + handler.customizeSubProtocolURLConnectionFactories(factories -> { + factories.add(new ConsoleSubProtocolURLConnectionFactory()); + }); + URL url = new URL(TEST_URL_WITH_SP); assertSame(url.openStream(), handler.openConnection(url, NO_PROXY).getInputStream()); assertEquals(TEST_URL_WITH_SP, url.toString()); - } - @Test - public void testTestOpenConnection() throws IOException { - String spec = TEST_URL_WITH_SP_PARAMS; - URL url = new URL(spec); + url = new URL(TEST_URL_WITH_SP_PARAMS); assertSame(url.openStream(), handler.openConnection(url).getInputStream()); - assertEquals(spec, url.toString()); + assertEquals(TEST_URL_WITH_SP_PARAMS, url.toString()); - spec = TEST_URL_WITH_SP_PARAMS_HASH; - url = new URL(spec); + url = new URL(TEST_URL_WITH_SP_PARAMS); assertSame(url.openStream(), handler.openConnection(url).getInputStream()); - assertEquals(spec, url.toString()); + assertEquals(TEST_URL_WITH_SP_PARAMS, url.toString()); } @Test From 5b5084695762edbe9bfcf0185ac6e74589939e3d Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 22:09:02 +0800 Subject: [PATCH 016/115] Update Handler.java --- .../src/main/java/io/microsphere/net/classpath/Handler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/classpath/Handler.java b/microsphere-java-core/src/main/java/io/microsphere/net/classpath/Handler.java index 57c352397..7cfafd331 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/classpath/Handler.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/classpath/Handler.java @@ -39,7 +39,7 @@ public class Handler extends ExtendableProtocolURLStreamHandler { @Override - protected URLConnection openConnection(URL u, Proxy proxy) throws IOException { + public URLConnection openConnection(URL u, Proxy proxy) throws IOException { String authority = u.getAuthority(); String path = u.getPath(); From 591f883888e834309344b05e90ee25209f759414 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 22:09:11 +0800 Subject: [PATCH 017/115] Create Handler.java --- .../java/io/microsphere/net/test/Handler.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 microsphere-java-core/src/test/java/io/microsphere/net/test/Handler.java diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/test/Handler.java b/microsphere-java-core/src/test/java/io/microsphere/net/test/Handler.java new file mode 100644 index 000000000..6cce71957 --- /dev/null +++ b/microsphere-java-core/src/test/java/io/microsphere/net/test/Handler.java @@ -0,0 +1,37 @@ +/* + * 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.net.test; + +import io.microsphere.net.ExtendableProtocolURLStreamHandler; + +/** + * Test {@link ExtendableProtocolURLStreamHandler} + * + * @author Mercy + * @since 1.0.0 + */ +public class Handler extends ExtendableProtocolURLStreamHandler { + + public Handler() { + super(); + } + + public Handler(String protocol) { + super(protocol); + } + +} From f96c5825b00144f8effe0b583af692131a1f083b Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 22:09:15 +0800 Subject: [PATCH 018/115] Delete TestHandler.java --- .../java/io/microsphere/net/TestHandler.java | 41 ------------------- 1 file changed, 41 deletions(-) delete mode 100644 microsphere-java-core/src/test/java/io/microsphere/net/TestHandler.java diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/TestHandler.java b/microsphere-java-core/src/test/java/io/microsphere/net/TestHandler.java deleted file mode 100644 index c6b9c3b78..000000000 --- a/microsphere-java-core/src/test/java/io/microsphere/net/TestHandler.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.net; - -import java.io.IOException; -import java.net.Proxy; -import java.net.URL; -import java.net.URLConnection; - -/** - * Test {@link ExtendableProtocolURLStreamHandler} - * - * @author Mercy - * @since 1.0.0 - */ -public class TestHandler extends ExtendableProtocolURLStreamHandler { - - public TestHandler(String protocol) { - super(protocol); - } - - @Override - protected URLConnection openFallbackConnection(URL url, Proxy proxy) throws IOException { - return null; - } - -} From e4cf2565a9619b42d643a9e3caf9f4dbd3a619cf Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 22:09:18 +0800 Subject: [PATCH 019/115] Create HandlerTest.java --- .../io/microsphere/net/test/HandlerTest.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 microsphere-java-core/src/test/java/io/microsphere/net/test/HandlerTest.java diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/test/HandlerTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/test/HandlerTest.java new file mode 100644 index 000000000..5ff4242de --- /dev/null +++ b/microsphere-java-core/src/test/java/io/microsphere/net/test/HandlerTest.java @@ -0,0 +1,66 @@ +/* + * 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.net.test; + +import io.microsphere.net.AbstractExtendableProtocolURLStreamHandlerTest; +import io.microsphere.net.ExtendableProtocolURLStreamHandler; + +import java.io.IOException; +import java.net.Proxy; +import java.net.URL; + +import static org.junit.jupiter.api.Assertions.assertNull; + +/** + * {link Handler} Test for "test" protocol + * + * @author Mercy + * @see AbstractExtendableProtocolURLStreamHandlerTest + * @since 1.0.0 + */ +public class HandlerTest extends AbstractExtendableProtocolURLStreamHandlerTest { + + private static final String TEST_URL = "test:////META-INF/test.properties"; + + private static final String TEST_URL_WITH_SP = "test:text:////META-INF/test.properties"; + + @Override + protected ExtendableProtocolURLStreamHandler createHandler() { + return new Handler(); + } + + @Override + protected String getTestURL() { + return TEST_URL; + } + + @Override + protected String getTestURLWithSP() { + return TEST_URL_WITH_SP; + } + + @Override + protected void testOpenConnection(URL url) throws IOException { + assertNull(url.openConnection()); + } + + @Override + protected void testOpenConnection(URL url, Proxy proxy) throws IOException { + assertNull(url.openConnection(proxy)); + assertNull(this.handler.openConnection(url, proxy)); + } +} From fa5916aa04bf0214c2dbcc6c698294028e65553b Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 22:09:21 +0800 Subject: [PATCH 020/115] Update ExtendableProtocolURLStreamHandlerTest.java --- ...xtendableProtocolURLStreamHandlerTest.java | 105 ++++-------------- 1 file changed, 23 insertions(+), 82 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java index 8731ecb62..260a30381 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java @@ -16,17 +16,14 @@ */ package io.microsphere.net; -import io.microsphere.net.console.Handler; +import io.microsphere.net.test.Handler; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.IOException; -import java.io.InputStreamReader; -import java.net.Proxy; import java.net.URL; import java.util.List; -import java.util.Properties; import static io.microsphere.collection.ListUtils.newLinkedList; import static io.microsphere.collection.ListUtils.ofList; @@ -38,13 +35,13 @@ import static io.microsphere.net.ExtendableProtocolURLStreamHandler.getHandlePackages; import static io.microsphere.net.ExtendableProtocolURLStreamHandler.getHandlePackagesPropertyValue; import static io.microsphere.net.URLUtils.toExternalForm; +import static io.microsphere.net.console.HandlerTest.TEST_CONSOLE_URL_WITH_SP; import static io.microsphere.util.ClassLoaderUtils.resolveClass; import static java.net.Proxy.NO_PROXY; import static java.util.Collections.emptyList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -58,19 +55,15 @@ */ public class ExtendableProtocolURLStreamHandlerTest { - private static final String TEST_URL = "console://localhost:12345/abc"; + private static final String TEST_URL = "test://localhost:12345/abc"; - private static final String TEST_URL_WITH_SP = "console:text://localhost:12345/abc"; - - private static final String TEST_URL_WITH_SP_PARAMS = TEST_URL_WITH_SP + ";ref=top?n=1"; - - private static final String TEST_URL_WITH_SP_PARAMS_HASH = TEST_URL_WITH_SP_PARAMS + "#hash"; + private static final String TEST_URL_WITH_SP = "test:text://localhost:12345/abc"; private ExtendableProtocolURLStreamHandler handler; @BeforeEach public void init() { - // Handler for "console" protocol + // Handler for "test" protocol handler = new Handler(); } @@ -81,7 +74,6 @@ public void destroy() { @Test public void testAssertClassTopLevelOnLocalClass() { class LocalClass extends ExtendableProtocolURLStreamHandler { - } assertThrows(IllegalArgumentException.class, () -> assertClassTopLevel(LocalClass.class)); } @@ -93,9 +85,8 @@ public void testAssertClassTopLevelOnMemberClass() { @Test public void testAssertClassTopLevelOnAnonymousClass() { - assertThrows(IllegalArgumentException.class, () -> - assertClassTopLevel(new ExtendableProtocolURLStreamHandler() { - }.getClass())); + assertThrows(IllegalArgumentException.class, () -> assertClassTopLevel(new ExtendableProtocolURLStreamHandler() { + }.getClass())); } @Test @@ -119,45 +110,10 @@ public void testConstructorWithProtocolArg() { } private void assertTestHandler(String protocol) { - ExtendableProtocolURLStreamHandler handler = new TestHandler(protocol); + ExtendableProtocolURLStreamHandler handler = new Handler(protocol); assertEquals(protocol, handler.getProtocol()); } - @Test - public void testClassPathProtocol() throws Throwable { - io.microsphere.net.classpath.Handler handler = new io.microsphere.net.classpath.Handler(); - URL url = new URL("classpath://META-INF/test.properties"); - Properties properties = new Properties(); - properties.load(new InputStreamReader(url.openStream(), "UTF-8")); - assertEquals("测试名称", properties.get("name")); - - url = new URL("classpath:////META-INF/services/io.microsphere.event.EventListener"); - assertNotNull(url.openStream()); - - url = new URL("classpath:///META-INF/services/io.microsphere.event.EventListener"); - assertNotNull(url.openStream()); - - url = new URL("classpath://META-INF/services/io.microsphere.event.EventListener"); - assertNotNull(url.openStream()); - - url = new URL("classpath:/META-INF/services/io.microsphere.event.EventListener"); - assertNotNull(url.openConnection()); - - url = new URL("classpath:META-INF/services/io.microsphere.event.EventListener"); - assertNotNull(url.openConnection(Proxy.NO_PROXY)); - - } - - @Test - public void testClassPathProtocolOnResourceNotFound() { - assertThrows(IOException.class, () -> { - new io.microsphere.net.classpath.Handler(); - URL url = new URL("classpath://META-INF/not-found.res"); - url.openStream(); - }); - } - - @Test public void testGetHandlePackages() { assertEquals(ofSet("io.microsphere.net"), getHandlePackages()); @@ -191,27 +147,30 @@ public void testInitSubProtocolURLConnectionFactories() { @Test public void testOpenConnection() throws IOException { URL url = new URL(TEST_URL); - assertSame(url.openStream(), handler.openConnection(url, NO_PROXY).getInputStream()); + assertNull(url.openConnection()); assertEquals(TEST_URL, url.toString()); } + @Test + public void testCustomizeSubProtocolURLConnectionFactories() { + handler.customizeSubProtocolURLConnectionFactories(factories -> { + factories.add(new CompositeSubProtocolURLConnectionFactory()); + }); + } + @Test public void testOpenConnectionWithProxy() throws IOException { - ExtendableProtocolURLStreamHandler handler = new TestHandler("console"); handler.customizeSubProtocolURLConnectionFactories(factories -> { factories.add(new ConsoleSubProtocolURLConnectionFactory()); }); + URL url = new URL(TEST_URL_WITH_SP); - assertSame(url.openStream(), handler.openConnection(url, NO_PROXY).getInputStream()); + assertNull(url.openConnection(NO_PROXY)); assertEquals(TEST_URL_WITH_SP, url.toString()); - url = new URL(TEST_URL_WITH_SP_PARAMS); - assertSame(url.openStream(), handler.openConnection(url).getInputStream()); - assertEquals(TEST_URL_WITH_SP_PARAMS, url.toString()); - - url = new URL(TEST_URL_WITH_SP_PARAMS); - assertSame(url.openStream(), handler.openConnection(url).getInputStream()); - assertEquals(TEST_URL_WITH_SP_PARAMS, url.toString()); + url = new URL(TEST_CONSOLE_URL_WITH_SP); + assertSame(url.openConnection(NO_PROXY).getInputStream(), handler.openConnection(url, NO_PROXY).getInputStream()); + assertEquals(TEST_CONSOLE_URL_WITH_SP, url.toString()); } @Test @@ -223,72 +182,54 @@ public void testOpenFallbackConnection() throws IOException { public void testEquals() throws IOException { assertTrue(handler.equals(new URL(TEST_URL), new URL(TEST_URL))); assertTrue(handler.equals(new URL(TEST_URL_WITH_SP), new URL(TEST_URL_WITH_SP))); - assertTrue(handler.equals(new URL(TEST_URL_WITH_SP_PARAMS), new URL(TEST_URL_WITH_SP_PARAMS))); - assertTrue(handler.equals(new URL(TEST_URL_WITH_SP_PARAMS_HASH), new URL(TEST_URL_WITH_SP_PARAMS_HASH))); assertFalse(handler.equals(new URL(TEST_URL), new URL(TEST_URL_WITH_SP))); - assertFalse(handler.equals(new URL(TEST_URL), new URL(TEST_URL_WITH_SP_PARAMS))); - assertFalse(handler.equals(new URL(TEST_URL), new URL(TEST_URL_WITH_SP_PARAMS_HASH))); } @Test public void testHashCode() throws IOException { assertEquals(handler.hashCode(new URL(TEST_URL)), new URL(TEST_URL).hashCode()); assertEquals(handler.hashCode(new URL(TEST_URL_WITH_SP)), new URL(TEST_URL_WITH_SP).hashCode()); - assertEquals(handler.hashCode(new URL(TEST_URL_WITH_SP_PARAMS)), new URL(TEST_URL_WITH_SP_PARAMS).hashCode()); - assertEquals(handler.hashCode(new URL(TEST_URL_WITH_SP_PARAMS_HASH)), new URL(TEST_URL_WITH_SP_PARAMS_HASH).hashCode()); assertNotEquals(handler.hashCode(new URL(TEST_URL)), new URL(TEST_URL_WITH_SP).hashCode()); - assertNotEquals(handler.hashCode(new URL(TEST_URL)), new URL(TEST_URL_WITH_SP_PARAMS).hashCode()); - assertNotEquals(handler.hashCode(new URL(TEST_URL)), new URL(TEST_URL_WITH_SP_PARAMS_HASH).hashCode()); } @Test public void testHostsEqual() throws IOException { assertTrue(handler.hostsEqual(new URL(TEST_URL), new URL(TEST_URL))); assertTrue(handler.hostsEqual(new URL(TEST_URL), new URL(TEST_URL_WITH_SP))); - assertTrue(handler.hostsEqual(new URL(TEST_URL), new URL(TEST_URL_WITH_SP_PARAMS))); - assertTrue(handler.hostsEqual(new URL(TEST_URL), new URL(TEST_URL_WITH_SP_PARAMS_HASH))); } @Test public void testToExternalForm() throws IOException { assertEquals(handler.toExternalForm(new URL(TEST_URL)), toExternalForm(new URL(TEST_URL))); assertEquals(handler.toExternalForm(new URL(TEST_URL_WITH_SP)), toExternalForm(new URL(TEST_URL_WITH_SP))); - assertEquals(handler.toExternalForm(new URL(TEST_URL_WITH_SP_PARAMS)), toExternalForm(new URL(TEST_URL_WITH_SP_PARAMS))); - assertEquals(handler.toExternalForm(new URL(TEST_URL_WITH_SP_PARAMS_HASH)), toExternalForm(new URL(TEST_URL_WITH_SP_PARAMS_HASH))); } @Test public void testResolveSubProtocols() throws IOException { assertEquals(emptyList(), handler.resolveSubProtocols(new URL(TEST_URL))); assertEquals(ofList("text"), handler.resolveSubProtocols(new URL(TEST_URL_WITH_SP))); - assertEquals(ofList("text"), handler.resolveSubProtocols(new URL(TEST_URL_WITH_SP_PARAMS))); - assertEquals(ofList("text"), handler.resolveSubProtocols(new URL(TEST_URL_WITH_SP_PARAMS_HASH))); } @Test public void testResolveAuthority() throws IOException { assertEquals("localhost:12345", handler.resolveAuthority(new URL(TEST_URL))); assertEquals("localhost:12345", handler.resolveAuthority(new URL(TEST_URL_WITH_SP))); - assertEquals("localhost:12345", handler.resolveAuthority(new URL(TEST_URL_WITH_SP_PARAMS))); - assertEquals("localhost:12345", handler.resolveAuthority(new URL(TEST_URL_WITH_SP_PARAMS_HASH))); } @Test public void testResolvePath() throws IOException { assertEquals("/abc", handler.resolvePath(new URL(TEST_URL))); assertEquals("/abc", handler.resolvePath(new URL(TEST_URL_WITH_SP))); - assertEquals("/abc", handler.resolvePath(new URL(TEST_URL_WITH_SP_PARAMS))); - assertEquals("/abc", handler.resolvePath(new URL(TEST_URL_WITH_SP_PARAMS_HASH))); } @Test public void testGetProtocol() { - assertEquals("console", handler.getProtocol()); + assertEquals("test", handler.getProtocol()); } @Test public void testToString() { - assertEquals("io.microsphere.net.console.Handler {defaultPort = -1 , protocol = 'console'}", handler.toString()); + assertEquals("io.microsphere.net.test.Handler {defaultPort = -1 , protocol = 'test'}", handler.toString()); } private static class MemberClass extends ExtendableProtocolURLStreamHandler { From e01d579078391acc11f654d1316d79a3632d23c1 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 22:09:22 +0800 Subject: [PATCH 021/115] Create HandlerTest.java --- .../microsphere/net/console/HandlerTest.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 microsphere-java-core/src/test/java/io/microsphere/net/console/HandlerTest.java diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/console/HandlerTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/console/HandlerTest.java new file mode 100644 index 000000000..02435ca9e --- /dev/null +++ b/microsphere-java-core/src/test/java/io/microsphere/net/console/HandlerTest.java @@ -0,0 +1,70 @@ +/* + * 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.net.console; + +import io.microsphere.net.AbstractExtendableProtocolURLStreamHandlerTest; +import io.microsphere.net.ExtendableProtocolURLStreamHandler; + +import java.io.IOException; +import java.net.Proxy; +import java.net.URL; + +import static java.net.Proxy.NO_PROXY; +import static org.junit.jupiter.api.Assertions.assertSame; + +/** + * {@link Handler} Test for "console" protocol + * + * @author Mercy + * @see Handler + * @since 1.0.0 + */ +public class HandlerTest extends AbstractExtendableProtocolURLStreamHandlerTest { + + public static final String TEST_CONSOLE_URL = "console://localhost:12345/abc"; + + public static final String TEST_CONSOLE_URL_WITH_SP = "console:text://localhost:12345/abc"; + + public static final String TEST_CONSOLE_URL_WITH_SP_PARAMS = TEST_CONSOLE_URL_WITH_SP + ";ref=top?n=1"; + + public static final String TEST_CONSOLE_URL_WITH_SP_PARAMS_HASH = TEST_CONSOLE_URL_WITH_SP_PARAMS + "#hash"; + + @Override + protected ExtendableProtocolURLStreamHandler createHandler() { + return new Handler(); + } + + @Override + protected String getTestURL() { + return TEST_CONSOLE_URL; + } + + @Override + protected String getTestURLWithSP() { + return TEST_CONSOLE_URL_WITH_SP_PARAMS_HASH; + } + + @Override + protected void testOpenConnection(URL url) throws IOException { + assertSame(url.openStream(), this.handler.openConnection(url, NO_PROXY).getInputStream()); + } + + @Override + protected void testOpenConnection(URL url, Proxy proxy) throws IOException { + assertSame(url.openConnection(proxy).getInputStream(), this.handler.openConnection(url, proxy).getInputStream()); + } +} From 470ff23e032dc97a1eac08bcdc60ee2715032cfa Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 22:09:24 +0800 Subject: [PATCH 022/115] Create HandlerTest.java --- .../net/classpath/HandlerTest.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 microsphere-java-core/src/test/java/io/microsphere/net/classpath/HandlerTest.java diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/classpath/HandlerTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/classpath/HandlerTest.java new file mode 100644 index 000000000..1bcd04975 --- /dev/null +++ b/microsphere-java-core/src/test/java/io/microsphere/net/classpath/HandlerTest.java @@ -0,0 +1,79 @@ +/* + * 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.net.classpath; + +import io.microsphere.net.AbstractExtendableProtocolURLStreamHandlerTest; +import io.microsphere.net.ExtendableProtocolURLStreamHandler; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.net.Proxy; +import java.net.URL; + +import static io.microsphere.io.IOUtils.toByteArray; +import static java.net.Proxy.NO_PROXY; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * {@link Handler} Test for "classpath" protocol + * + * @author Mercy + * @see Handler + * @since 1.0.0 + */ +public class HandlerTest extends AbstractExtendableProtocolURLStreamHandlerTest { + + private static final String TEST_PROPERTIES_CLASSPATH_URL = "classpath://META-INF/test.properties"; + + private static final String EVENT_LISTENER_URL = "classpath:////META-INF/services/io.microsphere.event.EventListener"; + + private static final String NOT_FOUND_URL = "classpath://META-INF/not-found.res"; + + @Override + protected void testOpenConnection(URL url) throws IOException { + assertArrayEquals(toByteArray(url.openConnection().getInputStream()), toByteArray(handler.openConnection(url, NO_PROXY).getInputStream())); + } + + @Override + protected void testOpenConnection(URL url, Proxy proxy) throws IOException { + assertArrayEquals(toByteArray(url.openConnection(NO_PROXY).getInputStream()), toByteArray(handler.openConnection(url, NO_PROXY).getInputStream())); + } + + @Test + public void testOpenConnectionOnResourceNotFound() { + assertThrows(IOException.class, () -> { + URL url = new URL(NOT_FOUND_URL); + url.openStream(); + }); + } + + @Override + protected ExtendableProtocolURLStreamHandler createHandler() { + return new Handler(); + } + + @Override + protected String getTestURL() { + return TEST_PROPERTIES_CLASSPATH_URL; + } + + @Override + protected String getTestURLWithSP() { + return EVENT_LISTENER_URL; + } +} From 88e3be4d9d71c8ea44936b16bf7030ce8aadcfdd Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 22:09:26 +0800 Subject: [PATCH 023/115] Create AbstractExtendableProtocolURLStreamHandlerTest.java --- ...xtendableProtocolURLStreamHandlerTest.java | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 microsphere-java-core/src/test/java/io/microsphere/net/AbstractExtendableProtocolURLStreamHandlerTest.java diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/AbstractExtendableProtocolURLStreamHandlerTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/AbstractExtendableProtocolURLStreamHandlerTest.java new file mode 100644 index 000000000..b2768fc27 --- /dev/null +++ b/microsphere-java-core/src/test/java/io/microsphere/net/AbstractExtendableProtocolURLStreamHandlerTest.java @@ -0,0 +1,151 @@ +/* + * 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.net; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.net.Proxy; +import java.net.URL; +import java.util.List; + +import static io.microsphere.collection.ListUtils.newLinkedList; +import static io.microsphere.collection.SetUtils.ofSet; +import static io.microsphere.io.IOUtils.toByteArray; +import static io.microsphere.net.ExtendableProtocolURLStreamHandler.getHandlePackages; +import static io.microsphere.net.ExtendableProtocolURLStreamHandler.getHandlePackagesPropertyValue; +import static io.microsphere.text.FormatUtils.format; +import static io.microsphere.util.StringUtils.split; +import static java.net.Proxy.NO_PROXY; +import static java.util.Collections.emptyList; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +/** + * Abstract {@link ExtendableProtocolURLStreamHandler} Test + * + * @author Mercy + * @since 1.0.0 + */ +public abstract class AbstractExtendableProtocolURLStreamHandlerTest { + + protected ExtendableProtocolURLStreamHandler handler; + + protected URL testURL; + + protected URL testURLWithSP; + + @BeforeEach + public final void init() throws IOException { + handler = createHandler(); + this.testURL = new URL(getTestURL()); + this.testURLWithSP = new URL(getTestURLWithSP()); + } + + @AfterEach + public void destroy() { + } + + @Test + public final void testGetHandlePackages() { + assertEquals(ofSet(resolveHandlePackage(this.handler)), getHandlePackages()); + } + + @Test + public final void testGetHandlePackagesPropertyValue() { + assertEquals(resolveHandlePackage(this.handler), getHandlePackagesPropertyValue()); + } + + @Test + public final void testInit() { + handler.init(); + } + + @Test + public final void testInitSubProtocolURLConnectionFactories() { + List factories = emptyList(); + List copy = newLinkedList(factories); + handler.initSubProtocolURLConnectionFactories(copy); + assertEquals(copy, factories); + } + + @Test + public final void testCustomizeSubProtocolURLConnectionFactories() { + handler.customizeSubProtocolURLConnectionFactories(factories -> { + factories.add(new CompositeSubProtocolURLConnectionFactory()); + }); + } + + @Test + public void testOpenConnection() throws IOException { + testOpenConnection(testURL); + testOpenConnection(testURLWithSP); + } + + @Test + public void testOpenConnectionWithProxy() throws IOException { + testOpenConnection(testURL, NO_PROXY); + testOpenConnection(testURLWithSP, NO_PROXY); + } + + @Test + public void testOpenFallbackConnection() throws IOException { + assertNull(handler.openFallbackConnection(null, null)); + } + + @Test + public final void testGetProtocol() { + assertEquals(resolveProtocol(this.handler), handler.getProtocol()); + } + + @Test + public final void testToString() { + assertEquals(format("{} {defaultPort = -1 , protocol = '{}'}", handler.getClass().getName(), handler.getProtocol()), handler.toString()); + } + + protected abstract ExtendableProtocolURLStreamHandler createHandler(); + + protected abstract String getTestURL(); + + protected abstract String getTestURLWithSP(); + + protected String resolveHandlePackage(ExtendableProtocolURLStreamHandler handler) { + String packageName = handler.getClass().getPackage().getName(); + int lastIndex = packageName.lastIndexOf("."); + return packageName.substring(0, lastIndex); + } + + protected String resolveProtocol(ExtendableProtocolURLStreamHandler handler) { + String packageName = handler.getClass().getPackage().getName(); + String[] parts = split(packageName, "."); + return parts[parts.length - 1]; + } + + protected void testOpenConnection(URL url) throws IOException { + assertNotNull(url.openConnection()); + assertArrayEquals(toByteArray(url.openStream()), toByteArray(handler.openConnection(url).getInputStream())); + } + + protected void testOpenConnection(URL url, Proxy proxy) throws IOException { + assertNotNull(url.openConnection(proxy)); + assertArrayEquals(toByteArray(url.openConnection(proxy).getInputStream()), toByteArray(handler.openConnection(url, proxy).getInputStream())); + } +} From 4e54bd96e7dedad44abe96323bfdea40b9a5635f Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 22:09:29 +0800 Subject: [PATCH 024/115] Update ExtendableProtocolURLStreamHandler.java --- .../io/microsphere/net/ExtendableProtocolURLStreamHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java b/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java index 6e8f6f52c..58a994d8a 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java @@ -161,7 +161,7 @@ protected final URLConnection openConnection(URL u) throws IOException { } @Override - protected URLConnection openConnection(URL u, Proxy p) throws IOException { + public URLConnection openConnection(URL u, Proxy p) throws IOException { List subProtocols = resolveSubProtocols(u); URLConnection urlConnection = null; int size = factories.size(); From f332ddcd8fa5cf62aed0320916c3a43b5f609e81 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 22:14:03 +0800 Subject: [PATCH 025/115] Update AbstractExtendableProtocolURLStreamHandlerTest.java --- .../net/AbstractExtendableProtocolURLStreamHandlerTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/AbstractExtendableProtocolURLStreamHandlerTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/AbstractExtendableProtocolURLStreamHandlerTest.java index b2768fc27..85956ec53 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/AbstractExtendableProtocolURLStreamHandlerTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/AbstractExtendableProtocolURLStreamHandlerTest.java @@ -30,6 +30,7 @@ import static io.microsphere.io.IOUtils.toByteArray; import static io.microsphere.net.ExtendableProtocolURLStreamHandler.getHandlePackages; import static io.microsphere.net.ExtendableProtocolURLStreamHandler.getHandlePackagesPropertyValue; +import static io.microsphere.net.URLUtils.HANDLER_PACKAGES_PROPERTY_NAME; import static io.microsphere.text.FormatUtils.format; import static io.microsphere.util.StringUtils.split; import static java.net.Proxy.NO_PROXY; @@ -62,6 +63,7 @@ public final void init() throws IOException { @AfterEach public void destroy() { + System.getProperties().remove(HANDLER_PACKAGES_PROPERTY_NAME); } @Test From e642d7b68524bb824eefa37445193f5234ae5bbc Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Thu, 6 Mar 2025 22:14:06 +0800 Subject: [PATCH 026/115] Update ExtendableProtocolURLStreamHandlerTest.java --- .../microsphere/net/ExtendableProtocolURLStreamHandlerTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java index 260a30381..5cd7f8869 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java @@ -34,6 +34,7 @@ import static io.microsphere.net.ExtendableProtocolURLStreamHandler.assertPackage; import static io.microsphere.net.ExtendableProtocolURLStreamHandler.getHandlePackages; import static io.microsphere.net.ExtendableProtocolURLStreamHandler.getHandlePackagesPropertyValue; +import static io.microsphere.net.URLUtils.HANDLER_PACKAGES_PROPERTY_NAME; import static io.microsphere.net.URLUtils.toExternalForm; import static io.microsphere.net.console.HandlerTest.TEST_CONSOLE_URL_WITH_SP; import static io.microsphere.util.ClassLoaderUtils.resolveClass; @@ -69,6 +70,7 @@ public void init() { @AfterEach public void destroy() { + System.getProperties().remove(HANDLER_PACKAGES_PROPERTY_NAME); } @Test From c93119cddd385ace92734480566659a06aba2d25 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 7 Mar 2025 13:19:01 +0800 Subject: [PATCH 027/115] Update MutableURLStreamHandlerFactory.java --- .../net/MutableURLStreamHandlerFactory.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/MutableURLStreamHandlerFactory.java b/microsphere-java-core/src/main/java/io/microsphere/net/MutableURLStreamHandlerFactory.java index 7dbbe4b7e..b413027a3 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/MutableURLStreamHandlerFactory.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/MutableURLStreamHandlerFactory.java @@ -44,24 +44,29 @@ public MutableURLStreamHandlerFactory(Map handlers) { } public MutableURLStreamHandlerFactory addURLStreamHandler(String protocol, H handler) { - handlers.put(protocol, handler); + this.handlers.put(protocol, handler); return this; } public H removeURLStreamHandler(String protocol) { - return handlers.remove(protocol); + return this.handlers.remove(protocol); } public H getURLStreamHandler(String protocol) { - return handlers.get(protocol); + return this.handlers.get(protocol); } public Collection getHandlers() { - return handlers.values(); + return this.handlers.values(); } @Override public URLStreamHandler createURLStreamHandler(String protocol) { - return handlers.get(protocol); + return getURLStreamHandler(protocol); + } + + public MutableURLStreamHandlerFactory clearHandlers() { + this.handlers.clear(); + return this; } } From f53f6d92227475651b245f540b87ce34f5a94cd4 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 7 Mar 2025 13:19:03 +0800 Subject: [PATCH 028/115] Create MutableURLStreamHandlerFactoryTest.java --- .../MutableURLStreamHandlerFactoryTest.java | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 microsphere-java-core/src/test/java/io/microsphere/net/MutableURLStreamHandlerFactoryTest.java diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/MutableURLStreamHandlerFactoryTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/MutableURLStreamHandlerFactoryTest.java new file mode 100644 index 000000000..83613dbb9 --- /dev/null +++ b/microsphere-java-core/src/test/java/io/microsphere/net/MutableURLStreamHandlerFactoryTest.java @@ -0,0 +1,109 @@ +package io.microsphere.net; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; + +/** + * {@link MutableURLStreamHandlerFactory} Test + * + * @author Mercy + * @see MutableURLStreamHandlerFactory + * @since 1.0.0 + */ +public class MutableURLStreamHandlerFactoryTest { + + MutableURLStreamHandlerFactory factory; + + private static final int OP_ADD = 1; + + private static final int OP_GET = OP_ADD << 1; + + private static final int OP_CREATE = OP_GET << 1; + + private static final int OP_REMOVE = OP_CREATE << 1; + + private static final int OP_CLEAR = OP_REMOVE << 1; + + @BeforeEach + public void init() { + factory = new MutableURLStreamHandlerFactory(); + } + + @AfterEach + public void destroy() { + factory.clearHandlers(); + } + + @Test + public void testAddURLStreamHandler() { + assertURLStreamHandler(new io.microsphere.net.classpath.Handler(), OP_ADD); + assertURLStreamHandler(new io.microsphere.net.console.Handler(), OP_ADD); + assertURLStreamHandler(new io.microsphere.net.test.Handler(), OP_ADD); + } + + @Test + public void testRemoveURLStreamHandler() { + assertURLStreamHandler(new io.microsphere.net.classpath.Handler(), OP_ADD | OP_REMOVE); + assertURLStreamHandler(new io.microsphere.net.console.Handler(), OP_ADD | OP_REMOVE); + assertURLStreamHandler(new io.microsphere.net.test.Handler(), OP_ADD | OP_REMOVE); + } + + @Test + public void testGetURLStreamHandler() { + assertURLStreamHandler(new io.microsphere.net.classpath.Handler(), OP_ADD | OP_GET); + assertURLStreamHandler(new io.microsphere.net.console.Handler(), OP_ADD | OP_GET); + assertURLStreamHandler(new io.microsphere.net.test.Handler(), OP_ADD | OP_GET); + } + + @Test + public void testGetHandlers() { + assertURLStreamHandler(new io.microsphere.net.classpath.Handler(), OP_ADD); + assertEquals(1, factory.getHandlers().size()); + + assertURLStreamHandler(new io.microsphere.net.console.Handler(), OP_ADD); + assertEquals(2, factory.getHandlers().size()); + + assertURLStreamHandler(new io.microsphere.net.test.Handler(), OP_ADD); + assertEquals(3, factory.getHandlers().size()); + } + + @Test + public void testCreateURLStreamHandler() { + assertURLStreamHandler(new io.microsphere.net.classpath.Handler(), OP_ADD | OP_CREATE); + assertURLStreamHandler(new io.microsphere.net.console.Handler(), OP_ADD | OP_CREATE); + assertURLStreamHandler(new io.microsphere.net.test.Handler(), OP_ADD | OP_CREATE); + } + + @Test + public void testClearHandlers() { + assertURLStreamHandler(new io.microsphere.net.classpath.Handler(), OP_ADD | OP_CLEAR); + assertURLStreamHandler(new io.microsphere.net.console.Handler(), OP_ADD | OP_CLEAR); + assertURLStreamHandler(new io.microsphere.net.test.Handler(), OP_ADD | OP_CLEAR); + } + + protected void assertURLStreamHandler(ExtendableProtocolURLStreamHandler handler, int operator) { + if ((operator & OP_ADD) != 0) { + assertSame(factory, factory.addURLStreamHandler(handler.getProtocol(), handler)); + } + + if ((operator & OP_GET) != 0) { + assertSame(handler, factory.getURLStreamHandler(handler.getProtocol())); + } + + if ((operator & OP_CREATE) != 0) { + assertSame(handler, factory.createURLStreamHandler(handler.getProtocol())); + } + + if ((operator & OP_REMOVE) != 0) { + assertSame(handler, factory.removeURLStreamHandler(handler.getProtocol())); + } + + if ((operator & OP_CLEAR) != 0) { + assertSame(factory, factory.clearHandlers()); + } + } +} \ No newline at end of file From 03b23e5782798f79f199ae3bd785dfbf5cfac4a8 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 7 Mar 2025 13:31:56 +0800 Subject: [PATCH 029/115] Update HandlerTest.java --- .../test/java/io/microsphere/net/classpath/HandlerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/classpath/HandlerTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/classpath/HandlerTest.java index 1bcd04975..6990b8df9 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/classpath/HandlerTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/classpath/HandlerTest.java @@ -38,9 +38,9 @@ */ public class HandlerTest extends AbstractExtendableProtocolURLStreamHandlerTest { - private static final String TEST_PROPERTIES_CLASSPATH_URL = "classpath://META-INF/test.properties"; + public static final String TEST_PROPERTIES_CLASSPATH_URL = "classpath://META-INF/test.properties"; - private static final String EVENT_LISTENER_URL = "classpath:////META-INF/services/io.microsphere.event.EventListener"; + public static final String EVENT_LISTENER_URL = "classpath:////META-INF/services/io.microsphere.event.EventListener"; private static final String NOT_FOUND_URL = "classpath://META-INF/not-found.res"; From e74fc7edebac18298d281e63adefc0cb3bb1d8d1 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 7 Mar 2025 13:38:52 +0800 Subject: [PATCH 030/115] Update ServiceLoaderURLStreamHandlerFactoryTest.java --- ...viceLoaderURLStreamHandlerFactoryTest.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/ServiceLoaderURLStreamHandlerFactoryTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/ServiceLoaderURLStreamHandlerFactoryTest.java index cbddc3e9a..202239ddf 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/ServiceLoaderURLStreamHandlerFactoryTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/ServiceLoaderURLStreamHandlerFactoryTest.java @@ -16,10 +16,20 @@ */ package io.microsphere.net; +import io.microsphere.io.IOUtils; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.io.IOException; +import java.net.URL; import java.net.URLStreamHandler; +import static io.microsphere.net.ServiceLoaderURLStreamHandlerFactory.attach; +import static io.microsphere.net.URLUtils.clearURLStreamHandlerFactory; +import static io.microsphere.net.classpath.HandlerTest.TEST_PROPERTIES_CLASSPATH_URL; import static org.junit.jupiter.api.Assertions.assertEquals; /** @@ -30,6 +40,16 @@ */ public class ServiceLoaderURLStreamHandlerFactoryTest { + @BeforeEach + public void init() { + attach(); + } + + @AfterEach + public void destroy() { + clearURLStreamHandlerFactory(); + } + @Test public void test() { ServiceLoaderURLStreamHandlerFactory factory = new ServiceLoaderURLStreamHandlerFactory(); @@ -44,7 +64,12 @@ public void test() { handler = factory.createURLStreamHandler("console"); assertEquals("io.microsphere.net.console.Handler", handler.getClass().getName()); + } - + @Test + public void testAttach() throws IOException { + attach(); + URL url = new URL(TEST_PROPERTIES_CLASSPATH_URL); + assertEquals("name = 测试名称", IOUtils.toString(url.openStream(), "UTF-8")); } } From 76fb97407b0d00a74f0450656e9437aa0c01fd65 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 7 Mar 2025 13:39:05 +0800 Subject: [PATCH 031/115] Update ServiceLoaderURLStreamHandlerFactoryTest.java --- .../net/ServiceLoaderURLStreamHandlerFactoryTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/ServiceLoaderURLStreamHandlerFactoryTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/ServiceLoaderURLStreamHandlerFactoryTest.java index 202239ddf..456c70cc0 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/ServiceLoaderURLStreamHandlerFactoryTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/ServiceLoaderURLStreamHandlerFactoryTest.java @@ -17,9 +17,7 @@ package io.microsphere.net; import io.microsphere.io.IOUtils; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; From fd9bf7871c3cfdc9898cec47bb2af1b031b3d83e Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 7 Mar 2025 15:31:02 +0800 Subject: [PATCH 032/115] Update URLUtils.java --- .../src/main/java/io/microsphere/net/URLUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java index 9049ba241..399c15c81 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java @@ -158,10 +158,10 @@ protected static String doResolveArchiveEntryPath(String path) { */ public static String resolveBasePath(URL url) throws NullPointerException { // NPE check - return doResolveBasePath(url.getPath()); + return resolveBasePath(url.getPath()); } - protected static String doResolveBasePath(String path) { + protected static String resolveBasePath(String path) { int beginIndex = path.lastIndexOf(COLON_CHAR); if (beginIndex == -1) { return path; From 21ae083999f6a84c9784055c4a052f37483c1f8c Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 7 Mar 2025 15:31:05 +0800 Subject: [PATCH 033/115] Update URLUtilsTest.java --- .../java/io/microsphere/net/URLUtilsTest.java | 278 ++++++++++++++---- 1 file changed, 215 insertions(+), 63 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java index 6e7ab378a..b73caad60 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java @@ -3,9 +3,9 @@ */ package io.microsphere.net; -import io.microsphere.util.ClassLoaderUtils; import io.microsphere.util.StringUtils; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import javax.annotation.Nonnull; @@ -20,21 +20,33 @@ import static io.microsphere.net.URLUtils.attachURLStreamHandlerFactory; import static io.microsphere.net.URLUtils.buildMatrixString; +import static io.microsphere.net.URLUtils.clearURLStreamHandlerFactory; import static io.microsphere.net.URLUtils.decode; import static io.microsphere.net.URLUtils.encode; import static io.microsphere.net.URLUtils.getURLStreamHandlerFactory; +import static io.microsphere.net.URLUtils.isArchiveURL; +import static io.microsphere.net.URLUtils.isDirectoryURL; +import static io.microsphere.net.URLUtils.isJarURL; import static io.microsphere.net.URLUtils.normalizePath; import static io.microsphere.net.URLUtils.resolveArchiveEntryPath; +import static io.microsphere.net.URLUtils.resolveArchiveFile; +import static io.microsphere.net.URLUtils.resolveBasePath; import static io.microsphere.net.URLUtils.resolveMatrixParameters; import static io.microsphere.net.URLUtils.resolveProtocol; import static io.microsphere.net.URLUtils.resolveQueryParameters; +import static io.microsphere.util.ClassLoaderUtils.getClassResource; +import static io.microsphere.util.ClassLoaderUtils.getDefaultClassLoader; import static io.microsphere.util.StringUtils.substringBeforeLast; +import static io.microsphere.util.SystemUtils.USER_DIR; +import static java.nio.file.Paths.get; import static java.util.Collections.emptyMap; 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.assertNotSame; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -47,69 +59,67 @@ */ public class URLUtilsTest { - @AfterEach - public void after() { - URLUtils.clearURLStreamHandlerFactory(); - } + private static final String TEST_PATH = "/abc/def"; - @Test - public void testEncodeAndDecode() { - String path = "/abc/def"; + private static final String UTF8_ENCODED_TEST_PATH = "%2Fabc%2Fdef"; - String encodedPath = encode(path); - String decodedPath = decode(encodedPath); - assertEquals(path, decodedPath); + private static final String FILE_URL_PREFIX = "file://"; - encodedPath = encode(path, "GBK"); - decodedPath = decode(encodedPath, "GBK"); - assertEquals(path, decodedPath); - } + private static URL userDirURL; - @Test - public void testResolvePath() { - String path = null; - String expectedPath = null; - String resolvedPath = null; + private static URL classFileURL; - resolvedPath = normalizePath(path); - assertEquals(expectedPath, resolvedPath); - - path = ""; - expectedPath = ""; - resolvedPath = normalizePath(path); - assertEquals(expectedPath, resolvedPath); - - path = "/abc/"; - expectedPath = "/abc/"; - resolvedPath = normalizePath(path); - assertEquals(expectedPath, resolvedPath); - - path = "//abc///"; - expectedPath = "/abc/"; - resolvedPath = normalizePath(path); - assertEquals(expectedPath, resolvedPath); + private static URL classArchiveEntryURL; + @BeforeAll + public static void beforeAll() throws Throwable { + ClassLoader classLoader = getDefaultClassLoader(); + userDirURL = new URL(FILE_URL_PREFIX + USER_DIR); + classFileURL = getClassResource(classLoader, StringUtils.class); + classArchiveEntryURL = getClassResource(classLoader, Nonnull.class); + } - path = "//\\abc///"; - expectedPath = "/abc/"; - resolvedPath = normalizePath(path); - assertEquals(expectedPath, resolvedPath); + @AfterEach + public void after() { + clearURLStreamHandlerFactory(); } + @Test - public void testResolveRelativePath() throws MalformedURLException { - ClassLoader classLoader = ClassLoader.getSystemClassLoader(); - URL resourceURL = ClassLoaderUtils.getClassResource(classLoader, Nonnull.class); + public void testResolveArchiveEntryPath() { + ClassLoader classLoader = getDefaultClassLoader(); + URL resourceURL = getClassResource(classLoader, Nonnull.class); String expectedPath = "javax/annotation/Nonnull.class"; String relativePath = resolveArchiveEntryPath(resourceURL); assertEquals(expectedPath, relativePath); } + @Test + public void testResolveArchiveEntryPathOnFile() { + assertNull(resolveArchiveEntryPath(userDirURL)); + } + + @Test + public void testResolveBasePathOnFile() { + assertEquals(get(USER_DIR), get(resolveBasePath(userDirURL))); + } + + @Test + public void testResolveBasePathOnArchiveEntry() throws MalformedURLException { + String basePath = resolveBasePath(classArchiveEntryURL); + assertNotNull(basePath); + assertEquals(get(basePath), get(resolveBasePath(FILE_URL_PREFIX + basePath))); + } + @Test public void testResolveArchiveFile() { - ClassLoader classLoader = ClassLoader.getSystemClassLoader(); - URL resourceURL = ClassLoaderUtils.getClassResource(classLoader, Nonnull.class); - File archiveFile = URLUtils.resolveArchiveFile(resourceURL); + File archiveFile = resolveArchiveFile(classArchiveEntryURL); + assertTrue(archiveFile.exists()); + } + + @Test + public void testResolveArchiveFileOnClassFile() { + File archiveFile = resolveArchiveFile(classFileURL); assertTrue(archiveFile.exists()); } @@ -137,6 +147,19 @@ public void testResolveQueryParameters() { assertEquals(expectedParametersMap, parametersMap); } + @Test + public void testEncodeAndDecode() { + String path = "/abc/def"; + + String encodedPath = encode(path); + String decodedPath = decode(encodedPath); + assertEquals(path, decodedPath); + + encodedPath = encode(path, "GBK"); + decodedPath = decode(encodedPath, "GBK"); + assertEquals(path, decodedPath); + } + @Test public void testResolveMatrixParameters() { String url = "https://www.google.com.hk/search;q=java;oq=java;sourceid=chrome;es_sm=122;ie=UTF-8"; @@ -162,37 +185,166 @@ public void testResolveMatrixParameters() { } @Test - public void testBuildMatrixString() { - String matrixString = buildMatrixString("n", "1"); - assertEquals(";n=1", matrixString); + public void testResolvePath() { + String path = null; + String expectedPath = null; + String resolvedPath = null; - matrixString = buildMatrixString("n", "1", "2"); - assertEquals(";n=1;n=2", matrixString); + resolvedPath = normalizePath(path); + assertEquals(expectedPath, resolvedPath); - matrixString = buildMatrixString("n", "1", "2", "3"); - assertEquals(";n=1;n=2;n=3", matrixString); + path = ""; + expectedPath = ""; + resolvedPath = normalizePath(path); + assertEquals(expectedPath, resolvedPath); + + path = "/abc/"; + expectedPath = "/abc/"; + resolvedPath = normalizePath(path); + assertEquals(expectedPath, resolvedPath); + + path = "//abc///"; + expectedPath = "/abc/"; + resolvedPath = normalizePath(path); + assertEquals(expectedPath, resolvedPath); + + + path = "//\\abc///"; + expectedPath = "/abc/"; + resolvedPath = normalizePath(path); + assertEquals(expectedPath, resolvedPath); + } + + @Test + public void testEncode() { + assertEquals(UTF8_ENCODED_TEST_PATH, encode(TEST_PATH)); + } + + @Test + public void testEncodeWithEncoding() { + assertEquals(UTF8_ENCODED_TEST_PATH, encode(TEST_PATH, "UTF-8")); + } + + @Test + public void testEncodeOnInvalidEncoding() { + assertThrows(IllegalArgumentException.class, () -> encode(TEST_PATH, "unknown-encoding")); + } + + @Test + public void testDecode() { + assertEquals(TEST_PATH, decode(UTF8_ENCODED_TEST_PATH)); + } + + @Test + public void testDecodeWithEncoding() { + assertEquals(TEST_PATH, decode(UTF8_ENCODED_TEST_PATH, "UTF-8")); + } + + @Test + public void testDecodeOnInvalidEncoding() { + assertThrows(IllegalArgumentException.class, () -> decode(UTF8_ENCODED_TEST_PATH, "unknown-encoding")); } @Test public void testIsDirectoryURL() throws Exception { - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - URL resourceURL = ClassLoaderUtils.getClassResource(classLoader, StringUtils.class); - assertFalse(URLUtils.isDirectoryURL(resourceURL)); + ClassLoader classLoader = getDefaultClassLoader(); + URL resourceURL = getClassResource(classLoader, StringUtils.class); + assertFalse(isDirectoryURL(classFileURL)); String externalForm = null; externalForm = substringBeforeLast(resourceURL.toExternalForm(), StringUtils.class.getSimpleName() + ".class"); resourceURL = new URL(externalForm); - assertTrue(URLUtils.isDirectoryURL(resourceURL)); + assertTrue(isDirectoryURL(resourceURL)); - resourceURL = ClassLoaderUtils.getClassResource(classLoader, String.class); - assertFalse(URLUtils.isDirectoryURL(resourceURL)); + resourceURL = getClassResource(classLoader, String.class); + assertFalse(isDirectoryURL(resourceURL)); - resourceURL = ClassLoaderUtils.getClassResource(classLoader, getClass()); - assertFalse(URLUtils.isDirectoryURL(resourceURL)); + resourceURL = getClassResource(classLoader, getClass()); + assertFalse(isDirectoryURL(resourceURL)); externalForm = substringBeforeLast(resourceURL.toExternalForm(), getClass().getSimpleName() + ".class"); resourceURL = new URL(externalForm); - assertTrue(URLUtils.isDirectoryURL(resourceURL)); + assertTrue(isDirectoryURL(resourceURL)); + } + + @Test + public void testIsJarURLOnDirectory() { + assertFalse(isJarURL(userDirURL)); + } + + @Test + public void testIsJarURLOnClassFile() { + assertFalse(isJarURL(classFileURL)); + } + + @Test + public void testIsJarURLOnArchiveEntry() { + assertTrue(isJarURL(classArchiveEntryURL)); + } + + @Test + public void testIsJarURLOnArchiveFile() throws MalformedURLException { + File archiveFile = resolveArchiveFile(classArchiveEntryURL); + assertTrue(isJarURL(new URL(FILE_URL_PREFIX + archiveFile.getAbsolutePath()))); + } + + @Test + public void testIsArchiveURLOnJar() throws MalformedURLException { + assertTrue(isArchiveURL(classArchiveEntryURL)); + } + + @Test + public void testIsArchiveURLOnFile() throws MalformedURLException { + File archiveFile = resolveArchiveFile(classArchiveEntryURL); + assertTrue(isArchiveURL(new URL(FILE_URL_PREFIX + archiveFile.getAbsolutePath()))); + } + + @Test + public void testIsArchiveURLOnNotJar() throws MalformedURLException { + assertFalse(isArchiveURL(classFileURL)); + } + +// +// @Test +// public void testIsArchiveURLOnWar() throws MalformedURLException { +// testIsArchiveURLOn(WAR_PROTOCOL); +// } +// +// @Test +// public void testIsArchiveURLOnEar() throws MalformedURLException { +// testIsArchiveURLOn(EAR_PROTOCOL); +// } +// +// private void testIsArchiveURLOn(String protocol) throws MalformedURLException { +// String url = classArchiveEntryURL.toString().replace(JAR_PROTOCOL, protocol); +// assertTrue(isArchiveURL(new URL(url))); +// } + + @Test + public void testBuildMatrixString() { + String matrixString = buildMatrixString("n", "1"); + assertEquals(";n=1", matrixString); + + matrixString = buildMatrixString("n", "1", "2"); + assertEquals(";n=1;n=2", matrixString); + + matrixString = buildMatrixString("n", "1", "2", "3"); + assertEquals(";n=1;n=2;n=3", matrixString); + } + + @Test + public void testToStringOnDirectory() { + assertEquals(URLUtils.toString(userDirURL), userDirURL.toExternalForm()); + } + + @Test + public void testToStringOnClassFile() { + assertEquals(URLUtils.toString(classFileURL), classFileURL.toExternalForm()); + } + + @Test + public void testToStringOnClassArchiveEntry() { + assertEquals(URLUtils.toString(classArchiveEntryURL), classArchiveEntryURL.toExternalForm()); } @Test From dc37e29cd6e25c1298b2cea135652811344684f9 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 7 Mar 2025 15:52:00 +0800 Subject: [PATCH 034/115] Update URLUtils.java --- .../src/main/java/io/microsphere/net/URLUtils.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java index 399c15c81..225ab209c 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java @@ -484,17 +484,6 @@ public static String buildMatrixString(String name, String... values) { return buildString(name, values, SEMICOLON_CHAR, EQUAL_CHAR); } - /** - * Converts a URL of a specific protocol to a String. - * - * @param url {@link URL} - * @return non-null - * @throws NullPointerException If url is null - */ - public static String toString(URL url) throws NullPointerException { - return toExternalForm(url); - } - /** * Converts a URL of a specific protocol to a String. * From c701b4e63f7e54de07b462addd2739f5965ec54d Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 7 Mar 2025 16:10:26 +0800 Subject: [PATCH 035/115] Update URLUtilsTest.java --- .../java/io/microsphere/net/URLUtilsTest.java | 97 ++++++++++++++++--- 1 file changed, 81 insertions(+), 16 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java index b73caad60..c6bf3ba8c 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java @@ -3,6 +3,7 @@ */ package io.microsphere.net; +import io.microsphere.net.console.Handler; import io.microsphere.util.StringUtils; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; @@ -23,6 +24,7 @@ import static io.microsphere.net.URLUtils.clearURLStreamHandlerFactory; import static io.microsphere.net.URLUtils.decode; import static io.microsphere.net.URLUtils.encode; +import static io.microsphere.net.URLUtils.getSubProtocol; import static io.microsphere.net.URLUtils.getURLStreamHandlerFactory; import static io.microsphere.net.URLUtils.isArchiveURL; import static io.microsphere.net.URLUtils.isDirectoryURL; @@ -34,6 +36,8 @@ import static io.microsphere.net.URLUtils.resolveMatrixParameters; import static io.microsphere.net.URLUtils.resolveProtocol; import static io.microsphere.net.URLUtils.resolveQueryParameters; +import static io.microsphere.net.URLUtils.resolveSubProtocols; +import static io.microsphere.net.URLUtils.toExternalForm; import static io.microsphere.util.ClassLoaderUtils.getClassResource; import static io.microsphere.util.ClassLoaderUtils.getDefaultClassLoader; import static io.microsphere.util.StringUtils.substringBeforeLast; @@ -333,34 +337,81 @@ public void testBuildMatrixString() { } @Test - public void testToStringOnDirectory() { - assertEquals(URLUtils.toString(userDirURL), userDirURL.toExternalForm()); + public void testToExternalFormOnDirectory() { + testToExternalForm(userDirURL); } @Test - public void testToStringOnClassFile() { - assertEquals(URLUtils.toString(classFileURL), classFileURL.toExternalForm()); + public void testToExternalFormOnClassFile() { + testToExternalForm(classFileURL); } @Test - public void testToStringOnClassArchiveEntry() { - assertEquals(URLUtils.toString(classArchiveEntryURL), classArchiveEntryURL.toExternalForm()); + public void testToExternalFormOnClassArchiveEntry() { + testToExternalForm(classArchiveEntryURL); } @Test - public void testAttachURLStreamHandlerFactory() { - URLStreamHandlerFactory factory = new StandardURLStreamHandlerFactory(); - attachURLStreamHandlerFactory(factory); - assertSame(factory, getURLStreamHandlerFactory()); + public void testToExternalFormWithMatrix() throws MalformedURLException { + String url = "https://acme.com/;q=java"; + testToExternalForm(url); + } + @Test + public void testToExternalFormWithQueryString() throws MalformedURLException { + String url = "https://acme.com?q=java&key=1"; + testToExternalForm(url); + } - attachURLStreamHandlerFactory(factory); - CompositeURLStreamHandlerFactory compositeFactory = (CompositeURLStreamHandlerFactory) getURLStreamHandlerFactory(); - assertNotSame(factory, compositeFactory); - assertEquals(1, compositeFactory.getFactories().size()); - assertSame(factory, compositeFactory.getFactories().get(0)); - assertEquals(CompositeURLStreamHandlerFactory.class, compositeFactory.getClass()); + @Test + public void testToExternalFormWithPath() throws MalformedURLException { + String url = "https://acme.com/abc/def"; + testToExternalForm(url); + } + + @Test + public void testToExternalFormWithRef() throws MalformedURLException { + String url = "https://acme.com/abc/def#hash"; + testToExternalForm(url); + } + + private void testToExternalForm(String urlString) throws MalformedURLException { + testToExternalForm(new URL(urlString)); + } + + private void testToExternalForm(URL url) { + assertEquals(url.toExternalForm(), toExternalForm(url)); + } + + @Test + public void testGetSubProtocol() { + String url = "https://acme.com/;_sp=classpath"; + assertEquals("classpath", getSubProtocol(url)); + } + + @Test + public void testGetSubProtocolWithSubProtocol() { + String url = "https://acme.com/"; + assertNull(getSubProtocol(url)); + } + + @Test + public void testResolveSubProtocolsFromMatrix() throws MalformedURLException { + URL url = new URL("https://localhost/;_sp=text;_sp=properties"); + List subProtocols = resolveSubProtocols(url); + assertEquals(2, subProtocols.size()); + assertEquals("text", subProtocols.get(0)); + assertEquals("properties", subProtocols.get(1)); + } + @Test + public void testResolveSubProtocolsFromProtocol() throws MalformedURLException { + new Handler(); + URL url = new URL("console:text:properties://localhost"); + List subProtocols = resolveSubProtocols(url); + assertEquals(2, subProtocols.size()); + assertEquals("text", subProtocols.get(0)); + assertEquals("properties", subProtocols.get(1)); } @Test @@ -374,7 +425,21 @@ public void testResolveProtocol() { assertNull(resolveProtocol("a :")); assertEquals("ftp", resolveProtocol("ftp://...")); assertEquals("http", resolveProtocol("http://...")); + } + @Test + public void testAttachURLStreamHandlerFactory() { + URLStreamHandlerFactory factory = new StandardURLStreamHandlerFactory(); + attachURLStreamHandlerFactory(factory); + assertSame(factory, getURLStreamHandlerFactory()); + + + attachURLStreamHandlerFactory(factory); + CompositeURLStreamHandlerFactory compositeFactory = (CompositeURLStreamHandlerFactory) getURLStreamHandlerFactory(); + assertNotSame(factory, compositeFactory); + assertEquals(1, compositeFactory.getFactories().size()); + assertSame(factory, compositeFactory.getFactories().get(0)); + assertEquals(CompositeURLStreamHandlerFactory.class, compositeFactory.getClass()); } From 5d0a0218ebfc5488aee60ba51dd0a8ac1da9b941 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Fri, 7 Mar 2025 16:14:27 +0800 Subject: [PATCH 036/115] Update URLUtilsTest.java --- .../src/test/java/io/microsphere/net/URLUtilsTest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java index c6bf3ba8c..bfd11dce9 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java @@ -34,6 +34,7 @@ import static io.microsphere.net.URLUtils.resolveArchiveFile; import static io.microsphere.net.URLUtils.resolveBasePath; import static io.microsphere.net.URLUtils.resolveMatrixParameters; +import static io.microsphere.net.URLUtils.resolvePath; import static io.microsphere.net.URLUtils.resolveProtocol; import static io.microsphere.net.URLUtils.resolveQueryParameters; import static io.microsphere.net.URLUtils.resolveSubProtocols; @@ -189,7 +190,7 @@ public void testResolveMatrixParameters() { } @Test - public void testResolvePath() { + public void testNormalizePath() { String path = null; String expectedPath = null; String resolvedPath = null; @@ -427,6 +428,11 @@ public void testResolveProtocol() { assertEquals("http", resolveProtocol("http://...")); } + @Test + public void testResolvePath() { + assertEquals(USER_DIR, resolvePath(userDirURL)); + } + @Test public void testAttachURLStreamHandlerFactory() { URLStreamHandlerFactory factory = new StandardURLStreamHandlerFactory(); From c90ef43bc07f288170260d4db07bc4f8948fc732 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 01:24:39 +0800 Subject: [PATCH 037/115] Update URLUtils.java --- .../main/java/io/microsphere/net/URLUtils.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java index 225ab209c..751b1fe04 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java @@ -128,6 +128,22 @@ public abstract class URLUtils extends BaseUtils { */ public static final String SUB_PROTOCOL_MATRIX_NAME = "_sp"; + + /** + * Convert the url to {@link URL} + * + * @param url + * @return non-null + * @throws IllegalArgumentException if url is malformed + */ + public static URL ofURL(String url) { + try { + return new URL(url); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } + /** * Resolve the entry path from Archive File URL * From aaad6ba2a580ea81cb39a9b4e31aeff09ca22267 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 01:24:41 +0800 Subject: [PATCH 038/115] Update URLUtilsTest.java --- .../java/io/microsphere/net/URLUtilsTest.java | 110 ++++++++---------- 1 file changed, 51 insertions(+), 59 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java index bfd11dce9..95fa3faa2 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java @@ -30,6 +30,7 @@ import static io.microsphere.net.URLUtils.isDirectoryURL; import static io.microsphere.net.URLUtils.isJarURL; import static io.microsphere.net.URLUtils.normalizePath; +import static io.microsphere.net.URLUtils.ofURL; import static io.microsphere.net.URLUtils.resolveArchiveEntryPath; import static io.microsphere.net.URLUtils.resolveArchiveFile; import static io.microsphere.net.URLUtils.resolveBasePath; @@ -70,6 +71,20 @@ public class URLUtilsTest { private static final String FILE_URL_PREFIX = "file://"; + private static final String userDirURLString = FILE_URL_PREFIX + USER_DIR; + + private static final String TEST_HTTP_BASE = "http://localhost/"; + + private static final String TEST_HTTP_WITH_PATH = TEST_HTTP_BASE + TEST_PATH; + + private static final String TEST_HTTP_WITH_PATH_HASH = TEST_HTTP_WITH_PATH + "#hash"; + + private static final String TEST_HTTP_WITH_QUERY_STRING = TEST_HTTP_BASE + "?q=java&oq=java&sourceid=chrome&es_sm=122&ie=UTF-8"; + + private static final String TEST_HTTP_WITH_MATRIX_STRING = TEST_HTTP_BASE + ";q=java;oq=java;sourceid=chrome;es_sm=122;ie=UTF-8"; + + private static final String TEST_HTTP_WITH_SP_MATRIX = TEST_HTTP_BASE + ";_sp=text;_sp=properties"; + private static URL userDirURL; private static URL classFileURL; @@ -79,7 +94,7 @@ public class URLUtilsTest { @BeforeAll public static void beforeAll() throws Throwable { ClassLoader classLoader = getDefaultClassLoader(); - userDirURL = new URL(FILE_URL_PREFIX + USER_DIR); + userDirURL = ofURL(userDirURLString); classFileURL = getClassResource(classLoader, StringUtils.class); classArchiveEntryURL = getClassResource(classLoader, Nonnull.class); } @@ -89,6 +104,15 @@ public void after() { clearURLStreamHandlerFactory(); } + @Test + public void testOfURL() throws MalformedURLException { + assertEquals(new URL(userDirURLString), ofURL(userDirURLString)); + } + + @Test + public void testOfURLOnFailed() { + assertThrows(IllegalArgumentException.class, () -> ofURL("unknown://localhost/")); + } @Test public void testResolveArchiveEntryPath() { @@ -130,7 +154,7 @@ public void testResolveArchiveFileOnClassFile() { @Test public void testResolveQueryParameters() { - String url = "https://www.google.com.hk/search?q=java&oq=java&sourceid=chrome&es_sm=122&ie=UTF-8"; + String url = TEST_HTTP_WITH_QUERY_STRING; Map> parametersMap = resolveQueryParameters(url); Map> expectedParametersMap = new LinkedHashMap<>(); expectedParametersMap.put("q", Arrays.asList("java")); @@ -141,33 +165,20 @@ public void testResolveQueryParameters() { assertEquals(expectedParametersMap, parametersMap); - url = "https://www.google.com.hk/search"; + url = TEST_HTTP_BASE; parametersMap = resolveQueryParameters(url); expectedParametersMap = emptyMap(); assertEquals(expectedParametersMap, parametersMap); - url = "https://www.google.com.hk/search?"; + url = TEST_HTTP_BASE; parametersMap = resolveQueryParameters(url); expectedParametersMap = emptyMap(); assertEquals(expectedParametersMap, parametersMap); } - @Test - public void testEncodeAndDecode() { - String path = "/abc/def"; - - String encodedPath = encode(path); - String decodedPath = decode(encodedPath); - assertEquals(path, decodedPath); - - encodedPath = encode(path, "GBK"); - decodedPath = decode(encodedPath, "GBK"); - assertEquals(path, decodedPath); - } - @Test public void testResolveMatrixParameters() { - String url = "https://www.google.com.hk/search;q=java;oq=java;sourceid=chrome;es_sm=122;ie=UTF-8"; + String url = TEST_HTTP_WITH_MATRIX_STRING; Map> parametersMap = resolveMatrixParameters(url); Map> expectedParametersMap = new LinkedHashMap<>(); expectedParametersMap.put("q", Arrays.asList("java")); @@ -178,12 +189,12 @@ public void testResolveMatrixParameters() { assertEquals(expectedParametersMap, parametersMap); - url = "https://www.google.com.hk/search"; + url = TEST_HTTP_WITH_QUERY_STRING; parametersMap = resolveMatrixParameters(url); expectedParametersMap = emptyMap(); assertEquals(expectedParametersMap, parametersMap); - url = "https://www.google.com.hk/search;"; + url = TEST_HTTP_BASE; parametersMap = resolveMatrixParameters(url); expectedParametersMap = emptyMap(); assertEquals(expectedParametersMap, parametersMap); @@ -258,7 +269,7 @@ public void testIsDirectoryURL() throws Exception { String externalForm = null; externalForm = substringBeforeLast(resourceURL.toExternalForm(), StringUtils.class.getSimpleName() + ".class"); - resourceURL = new URL(externalForm); + resourceURL = ofURL(externalForm); assertTrue(isDirectoryURL(resourceURL)); resourceURL = getClassResource(classLoader, String.class); @@ -268,7 +279,7 @@ public void testIsDirectoryURL() throws Exception { assertFalse(isDirectoryURL(resourceURL)); externalForm = substringBeforeLast(resourceURL.toExternalForm(), getClass().getSimpleName() + ".class"); - resourceURL = new URL(externalForm); + resourceURL = ofURL(externalForm); assertTrue(isDirectoryURL(resourceURL)); } @@ -290,7 +301,7 @@ public void testIsJarURLOnArchiveEntry() { @Test public void testIsJarURLOnArchiveFile() throws MalformedURLException { File archiveFile = resolveArchiveFile(classArchiveEntryURL); - assertTrue(isJarURL(new URL(FILE_URL_PREFIX + archiveFile.getAbsolutePath()))); + assertTrue(isJarURL(ofURL(FILE_URL_PREFIX + archiveFile.getAbsolutePath()))); } @Test @@ -301,7 +312,7 @@ public void testIsArchiveURLOnJar() throws MalformedURLException { @Test public void testIsArchiveURLOnFile() throws MalformedURLException { File archiveFile = resolveArchiveFile(classArchiveEntryURL); - assertTrue(isArchiveURL(new URL(FILE_URL_PREFIX + archiveFile.getAbsolutePath()))); + assertTrue(isArchiveURL(ofURL(FILE_URL_PREFIX + archiveFile.getAbsolutePath()))); } @Test @@ -309,22 +320,6 @@ public void testIsArchiveURLOnNotJar() throws MalformedURLException { assertFalse(isArchiveURL(classFileURL)); } -// -// @Test -// public void testIsArchiveURLOnWar() throws MalformedURLException { -// testIsArchiveURLOn(WAR_PROTOCOL); -// } -// -// @Test -// public void testIsArchiveURLOnEar() throws MalformedURLException { -// testIsArchiveURLOn(EAR_PROTOCOL); -// } -// -// private void testIsArchiveURLOn(String protocol) throws MalformedURLException { -// String url = classArchiveEntryURL.toString().replace(JAR_PROTOCOL, protocol); -// assertTrue(isArchiveURL(new URL(url))); -// } - @Test public void testBuildMatrixString() { String matrixString = buildMatrixString("n", "1"); @@ -353,31 +348,27 @@ public void testToExternalFormOnClassArchiveEntry() { } @Test - public void testToExternalFormWithMatrix() throws MalformedURLException { - String url = "https://acme.com/;q=java"; - testToExternalForm(url); + public void testToExternalFormWithMatrixString() throws MalformedURLException { + testToExternalForm(TEST_HTTP_WITH_MATRIX_STRING); } @Test public void testToExternalFormWithQueryString() throws MalformedURLException { - String url = "https://acme.com?q=java&key=1"; - testToExternalForm(url); + testToExternalForm(TEST_HTTP_WITH_QUERY_STRING); } @Test public void testToExternalFormWithPath() throws MalformedURLException { - String url = "https://acme.com/abc/def"; - testToExternalForm(url); + testToExternalForm(TEST_HTTP_WITH_PATH); } @Test public void testToExternalFormWithRef() throws MalformedURLException { - String url = "https://acme.com/abc/def#hash"; - testToExternalForm(url); + testToExternalForm(TEST_HTTP_WITH_PATH_HASH); } private void testToExternalForm(String urlString) throws MalformedURLException { - testToExternalForm(new URL(urlString)); + testToExternalForm(ofURL(urlString)); } private void testToExternalForm(URL url) { @@ -386,19 +377,17 @@ private void testToExternalForm(URL url) { @Test public void testGetSubProtocol() { - String url = "https://acme.com/;_sp=classpath"; - assertEquals("classpath", getSubProtocol(url)); + assertEquals("text", getSubProtocol(TEST_HTTP_WITH_SP_MATRIX)); } @Test public void testGetSubProtocolWithSubProtocol() { - String url = "https://acme.com/"; - assertNull(getSubProtocol(url)); + assertNull(getSubProtocol(TEST_HTTP_BASE)); } @Test - public void testResolveSubProtocolsFromMatrix() throws MalformedURLException { - URL url = new URL("https://localhost/;_sp=text;_sp=properties"); + public void testResolveSubProtocolsFromMatrixString() throws MalformedURLException { + URL url = ofURL(TEST_HTTP_WITH_SP_MATRIX); List subProtocols = resolveSubProtocols(url); assertEquals(2, subProtocols.size()); assertEquals("text", subProtocols.get(0)); @@ -408,7 +397,7 @@ public void testResolveSubProtocolsFromMatrix() throws MalformedURLException { @Test public void testResolveSubProtocolsFromProtocol() throws MalformedURLException { new Handler(); - URL url = new URL("console:text:properties://localhost"); + URL url = ofURL("console:text:properties://localhost"); List subProtocols = resolveSubProtocols(url); assertEquals(2, subProtocols.size()); assertEquals("text", subProtocols.get(0)); @@ -433,13 +422,17 @@ public void testResolvePath() { assertEquals(USER_DIR, resolvePath(userDirURL)); } + @Test + public void testResolvePathWithMatrixString() { + assertEquals(USER_DIR, resolvePath(userDirURL)); + } + @Test public void testAttachURLStreamHandlerFactory() { URLStreamHandlerFactory factory = new StandardURLStreamHandlerFactory(); attachURLStreamHandlerFactory(factory); assertSame(factory, getURLStreamHandlerFactory()); - attachURLStreamHandlerFactory(factory); CompositeURLStreamHandlerFactory compositeFactory = (CompositeURLStreamHandlerFactory) getURLStreamHandlerFactory(); assertNotSame(factory, compositeFactory); @@ -448,5 +441,4 @@ public void testAttachURLStreamHandlerFactory() { assertEquals(CompositeURLStreamHandlerFactory.class, compositeFactory.getClass()); } - } From 059699b94c53b7b9c0c494e49a795fd5c6aaf338 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 01:38:22 +0800 Subject: [PATCH 039/115] Update URLUtilsTest.java --- .../java/io/microsphere/net/URLUtilsTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java index 95fa3faa2..226b48fe0 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java @@ -11,8 +11,11 @@ import javax.annotation.Nonnull; import java.io.File; +import java.io.IOException; +import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; +import java.net.URLConnection; import java.net.URLStreamHandlerFactory; import java.util.Arrays; import java.util.LinkedHashMap; @@ -22,6 +25,7 @@ import static io.microsphere.net.URLUtils.attachURLStreamHandlerFactory; import static io.microsphere.net.URLUtils.buildMatrixString; import static io.microsphere.net.URLUtils.clearURLStreamHandlerFactory; +import static io.microsphere.net.URLUtils.close; import static io.microsphere.net.URLUtils.decode; import static io.microsphere.net.URLUtils.encode; import static io.microsphere.net.URLUtils.getSubProtocol; @@ -31,6 +35,7 @@ import static io.microsphere.net.URLUtils.isJarURL; import static io.microsphere.net.URLUtils.normalizePath; import static io.microsphere.net.URLUtils.ofURL; +import static io.microsphere.net.URLUtils.registerURLStreamHandler; import static io.microsphere.net.URLUtils.resolveArchiveEntryPath; import static io.microsphere.net.URLUtils.resolveArchiveFile; import static io.microsphere.net.URLUtils.resolveBasePath; @@ -40,6 +45,7 @@ import static io.microsphere.net.URLUtils.resolveQueryParameters; import static io.microsphere.net.URLUtils.resolveSubProtocols; import static io.microsphere.net.URLUtils.toExternalForm; +import static io.microsphere.net.console.HandlerTest.TEST_CONSOLE_URL; import static io.microsphere.util.ClassLoaderUtils.getClassResource; import static io.microsphere.util.ClassLoaderUtils.getDefaultClassLoader; import static io.microsphere.util.StringUtils.substringBeforeLast; @@ -441,4 +447,36 @@ public void testAttachURLStreamHandlerFactory() { assertEquals(CompositeURLStreamHandlerFactory.class, compositeFactory.getClass()); } + @Test + public void testGetURLStreamHandlerFactory() { + assertNull(getURLStreamHandlerFactory()); + } + + @Test + public void testRegisterURLStreamHandler() throws IOException { + Handler handler = new Handler(); + registerURLStreamHandler(handler); + URL url = ofURL(TEST_CONSOLE_URL); + assertSame(System.in, url.openStream()); + } + + @Test + public void testClose() throws IOException { + URL url = ofURL("http://localhost"); + URLConnection urlConnection = url.openConnection(); + close(urlConnection); + } + + @Test + public void testCloseOnNonHttp() throws IOException { + URL url = ofURL("ftp://localhost"); + URLConnection urlConnection = url.openConnection(); + close(urlConnection); + } + + @Test + public void testCloseOnNull() { + close(null); + } + } From aec5afeaab8b8f00f90d18951b08587efefac4d4 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 01:43:04 +0800 Subject: [PATCH 040/115] Update URLUtilsTest.java --- .../java/io/microsphere/net/URLUtilsTest.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java index 226b48fe0..d169eadc9 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java @@ -12,7 +12,6 @@ import javax.annotation.Nonnull; import java.io.File; import java.io.IOException; -import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; @@ -28,6 +27,7 @@ import static io.microsphere.net.URLUtils.close; import static io.microsphere.net.URLUtils.decode; import static io.microsphere.net.URLUtils.encode; +import static io.microsphere.net.URLUtils.getMutableURLStreamHandlerFactory; import static io.microsphere.net.URLUtils.getSubProtocol; import static io.microsphere.net.URLUtils.getURLStreamHandlerFactory; import static io.microsphere.net.URLUtils.isArchiveURL; @@ -479,4 +479,23 @@ public void testCloseOnNull() { close(null); } + @Test + public void testGetMutableURLStreamHandlerFactory() { + MutableURLStreamHandlerFactory factory = getMutableURLStreamHandlerFactory(); + assertNull(factory); + } + + @Test + public void testGetMutableURLStreamHandlerFactoryFromAttached() { + MutableURLStreamHandlerFactory factory = new MutableURLStreamHandlerFactory(); + attachURLStreamHandlerFactory(factory); + assertSame(factory, getMutableURLStreamHandlerFactory()); + } + + @Test + public void testGetMutableURLStreamHandlerFactoryOnCreateIfAbsent() { + MutableURLStreamHandlerFactory factory = getMutableURLStreamHandlerFactory(true); + assertNotNull(factory); + } + } From 7968f074f899553fcefee7ce1c9fe42930d2ac06 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 01:47:47 +0800 Subject: [PATCH 041/115] Update URLUtilsTest.java --- .../src/test/java/io/microsphere/net/URLUtilsTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java index d169eadc9..d27264506 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java @@ -498,4 +498,11 @@ public void testGetMutableURLStreamHandlerFactoryOnCreateIfAbsent() { assertNotNull(factory); } + @Test + public void testClearURLStreamHandlerFactory() { + testGetMutableURLStreamHandlerFactoryFromAttached(); + clearURLStreamHandlerFactory(); + testGetMutableURLStreamHandlerFactory(); + } + } From 1cd02325b6a39406831ce182bd84cb273366e8c6 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 01:52:46 +0800 Subject: [PATCH 042/115] Update URLUtils.java --- .../src/main/java/io/microsphere/net/URLUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java index 751b1fe04..8ff67c740 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java @@ -29,6 +29,7 @@ import java.util.jar.JarFile; import static io.microsphere.collection.CollectionUtils.size; +import static io.microsphere.collection.MapUtils.MIN_LOAD_FACTOR; import static io.microsphere.constants.PathConstants.BACK_SLASH; import static io.microsphere.constants.PathConstants.DOUBLE_SLASH; import static io.microsphere.constants.PathConstants.SLASH; @@ -813,7 +814,7 @@ protected static Map> resolveParameters(String paramsString return emptyMap(); } - Map> parametersMap = new LinkedHashMap(paramsLen, Float.MIN_NORMAL); + Map> parametersMap = new LinkedHashMap(paramsLen, MIN_LOAD_FACTOR); for (int i = 0; i < paramsLen; i++) { String param = params[i]; From f98995c5e7f54fcff2dc73130684b28a8a40f2d2 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 01:55:12 +0800 Subject: [PATCH 043/115] Update StringUtils.java --- .../src/main/java/io/microsphere/util/StringUtils.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java index b3a12add7..692f60ba1 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/StringUtils.java @@ -32,6 +32,8 @@ public abstract class StringUtils extends BaseUtils { public final static String EMPTY = ""; + public final static String EMPTY_STRING = ""; + public static final String[] EMPTY_STRING_ARRAY = ArrayUtils.EMPTY_STRING_ARRAY; public static int length(String value) { From ba284f90c652349ea5a5ee792f4b080d7c6bd24b Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 01:59:34 +0800 Subject: [PATCH 044/115] Update URLUtilsTest.java --- .../test/java/io/microsphere/net/URLUtilsTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java index d27264506..98e5d65c3 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; +import static io.microsphere.constants.SymbolConstants.AND_CHAR; import static io.microsphere.net.URLUtils.attachURLStreamHandlerFactory; import static io.microsphere.net.URLUtils.buildMatrixString; import static io.microsphere.net.URLUtils.clearURLStreamHandlerFactory; @@ -40,6 +41,7 @@ import static io.microsphere.net.URLUtils.resolveArchiveFile; import static io.microsphere.net.URLUtils.resolveBasePath; import static io.microsphere.net.URLUtils.resolveMatrixParameters; +import static io.microsphere.net.URLUtils.resolveParameters; import static io.microsphere.net.URLUtils.resolvePath; import static io.microsphere.net.URLUtils.resolveProtocol; import static io.microsphere.net.URLUtils.resolveQueryParameters; @@ -48,6 +50,8 @@ import static io.microsphere.net.console.HandlerTest.TEST_CONSOLE_URL; import static io.microsphere.util.ClassLoaderUtils.getClassResource; import static io.microsphere.util.ClassLoaderUtils.getDefaultClassLoader; +import static io.microsphere.util.StringUtils.EMPTY; +import static io.microsphere.util.StringUtils.EMPTY_STRING; import static io.microsphere.util.StringUtils.substringBeforeLast; import static io.microsphere.util.SystemUtils.USER_DIR; import static java.nio.file.Paths.get; @@ -505,4 +509,14 @@ public void testClearURLStreamHandlerFactory() { testGetMutableURLStreamHandlerFactory(); } + @Test + public void testResolveParametersOnNull() { + assertSame(emptyMap(), resolveParameters(null, AND_CHAR)); + } + + @Test + public void testResolveParametersOnEmptyString() { + assertSame(emptyMap(), resolveParameters(EMPTY_STRING, AND_CHAR)); + } + } From 287a64f2e817e6e25c5e7e57612d4a7bf61b63a7 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 01:59:40 +0800 Subject: [PATCH 045/115] Refactor --- .../main/java/io/microsphere/collection/MapUtils.java | 11 ++++++++--- .../main/java/io/microsphere/collection/SetUtils.java | 6 +++--- .../src/main/java/io/microsphere/net/URLUtils.java | 7 ++++--- .../java/io/microsphere/collection/MapUtilsTest.java | 4 ++-- .../java/io/microsphere/collection/SetUtilsTest.java | 6 +++--- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java index 617645776..27359fe28 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java @@ -51,7 +51,12 @@ public abstract class MapUtils extends BaseUtils { /** * The min load factor for {@link HashMap} or {@link Hashtable} */ - public static final float MIN_LOAD_FACTOR = 1.0f; + public static final float MIN_LOAD_FACTOR = Float.MIN_VALUE; + + /** + * The fixed load factor for {@link HashMap} or {@link Hashtable} = 1.00 + */ + public static final float FIXED_LOAD_FACTOR = 1.00f; public static boolean isEmpty(Map map) { return map == null || map.isEmpty(); @@ -87,7 +92,7 @@ public static Map of(Object... values) { public static Map ofMap(Object... keyValuePairs) { int length = keyValuePairs.length; - Map map = new HashMap(length / 2, MIN_LOAD_FACTOR); + Map map = new HashMap(length / 2, FIXED_LOAD_FACTOR); for (int i = 0; i < length; ) { map.put(keyValuePairs[i++], keyValuePairs[i++]); } @@ -198,7 +203,7 @@ public static Map toFixedMap(Collection values, return emptyMap(); } - Map fixedMap = newHashMap(size, MIN_LOAD_FACTOR); + Map fixedMap = newHashMap(size, FIXED_LOAD_FACTOR); for (E value : values) { Map.Entry entry = entryMapper.apply(value); diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java index 9576c7d01..ee3c56250 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java @@ -28,7 +28,7 @@ import java.util.Set; import static io.microsphere.collection.CollectionUtils.size; -import static io.microsphere.collection.MapUtils.MIN_LOAD_FACTOR; +import static io.microsphere.collection.MapUtils.FIXED_LOAD_FACTOR; import static io.microsphere.util.ArrayUtils.length; import static java.util.Collections.emptySet; import static java.util.Collections.singleton; @@ -122,7 +122,7 @@ public static Set ofSet(E one, E... others) { return singleton(one); } - Set elements = new LinkedHashSet<>(othersSize + 1, MIN_LOAD_FACTOR); + Set elements = new LinkedHashSet<>(othersSize + 1, FIXED_LOAD_FACTOR); elements.add(one); @@ -148,7 +148,7 @@ public static Set ofSet(Collection elements, T... others) { int size = valuesSize + othersSize; - Set set = newLinkedHashSet(size, MIN_LOAD_FACTOR); + Set set = newLinkedHashSet(size, FIXED_LOAD_FACTOR); // add elements set.addAll(elements); diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java index 8ff67c740..e1ba5be70 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java @@ -5,6 +5,7 @@ import io.microsphere.collection.MapUtils; import io.microsphere.logging.Logger; +import io.microsphere.util.ArrayUtils; import io.microsphere.util.BaseUtils; import io.microsphere.util.ClassPathUtils; import io.microsphere.util.jar.JarUtils; @@ -29,7 +30,7 @@ import java.util.jar.JarFile; import static io.microsphere.collection.CollectionUtils.size; -import static io.microsphere.collection.MapUtils.MIN_LOAD_FACTOR; +import static io.microsphere.collection.MapUtils.FIXED_LOAD_FACTOR; import static io.microsphere.constants.PathConstants.BACK_SLASH; import static io.microsphere.constants.PathConstants.DOUBLE_SLASH; import static io.microsphere.constants.PathConstants.SLASH; @@ -809,12 +810,12 @@ protected static String reformProtocol(String protocol, List subProtocol protected static Map> resolveParameters(String paramsString, char separatorChar) { String[] params = split(paramsString, separatorChar); - int paramsLen = params == null ? 0 : params.length; + int paramsLen = ArrayUtils.size(params); if (paramsLen == 0) { return emptyMap(); } - Map> parametersMap = new LinkedHashMap(paramsLen, MIN_LOAD_FACTOR); + Map> parametersMap = new LinkedHashMap(paramsLen, FIXED_LOAD_FACTOR); for (int i = 0; i < paramsLen; i++) { String param = params[i]; diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java index 259676ea7..4c31ef832 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java @@ -28,7 +28,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentSkipListMap; -import static io.microsphere.collection.MapUtils.MIN_LOAD_FACTOR; +import static io.microsphere.collection.MapUtils.FIXED_LOAD_FACTOR; import static io.microsphere.collection.MapUtils.immutableEntry; import static io.microsphere.collection.MapUtils.isEmpty; import static io.microsphere.collection.MapUtils.isNotEmpty; @@ -59,7 +59,7 @@ public class MapUtilsTest { @Test public void testConstants() { - assertEquals(1.f, MIN_LOAD_FACTOR); + assertEquals(1.f, FIXED_LOAD_FACTOR); } @Test diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/SetUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/SetUtilsTest.java index feb00ff6a..a2491c95b 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/SetUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/SetUtilsTest.java @@ -8,7 +8,7 @@ import static io.microsphere.collection.CollectionUtils.toIterable; import static io.microsphere.collection.EnumerationUtils.enumeration; -import static io.microsphere.collection.MapUtils.MIN_LOAD_FACTOR; +import static io.microsphere.collection.MapUtils.FIXED_LOAD_FACTOR; import static io.microsphere.collection.SetUtils.isSet; import static io.microsphere.collection.SetUtils.newHashSet; import static io.microsphere.collection.SetUtils.newLinkedHashSet; @@ -86,7 +86,7 @@ public void testOfSetIterable() { @Test public void testNewHashSet() { - Iterable iterable = newHashSet(1, MIN_LOAD_FACTOR); + Iterable iterable = newHashSet(1, FIXED_LOAD_FACTOR); assertEquals(iterable, newHashSet(iterable)); iterable = newHashSet(ELEMENTS); @@ -98,7 +98,7 @@ public void testNewHashSet() { @Test public void testNewLinkedHashSet() { - Iterable iterable = newLinkedHashSet(1, MIN_LOAD_FACTOR); + Iterable iterable = newLinkedHashSet(1, FIXED_LOAD_FACTOR); Collection elements = newLinkedHashSet(iterable); assertEquals(iterable, elements); From 1b03a7381f71a0467c033265e36419b7ce0245e6 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:01:47 +0800 Subject: [PATCH 046/115] Update URLUtils.java --- .../src/main/java/io/microsphere/net/URLUtils.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java index e1ba5be70..820d9bc90 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java @@ -19,7 +19,6 @@ import java.net.URLEncoder; import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; -import java.util.Arrays; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; @@ -30,6 +29,7 @@ import java.util.jar.JarFile; import static io.microsphere.collection.CollectionUtils.size; +import static io.microsphere.collection.Lists.ofList; import static io.microsphere.collection.MapUtils.FIXED_LOAD_FACTOR; import static io.microsphere.constants.PathConstants.BACK_SLASH; import static io.microsphere.constants.PathConstants.DOUBLE_SLASH; @@ -62,7 +62,6 @@ import static java.lang.reflect.Array.getLength; import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; -import static java.util.Collections.unmodifiableList; import static java.util.Collections.unmodifiableMap; /** @@ -611,9 +610,9 @@ public static List resolveSubProtocols(String url) { subProtocols = parameters.get(SUB_PROTOCOL_MATRIX_NAME); } else { String[] values = split(subProtocolsString, COLON_CHAR); - subProtocols = Arrays.asList(values); + subProtocols = ofList(values); } - return subProtocols == null ? emptyList() : unmodifiableList(subProtocols); + return subProtocols == null ? emptyList() : subProtocols; } /** @@ -810,7 +809,7 @@ protected static String reformProtocol(String protocol, List subProtocol protected static Map> resolveParameters(String paramsString, char separatorChar) { String[] params = split(paramsString, separatorChar); - int paramsLen = ArrayUtils.size(params); + int paramsLen = ArrayUtils.length(params); if (paramsLen == 0) { return emptyMap(); } @@ -837,7 +836,7 @@ protected static Map> resolveParameters(String paramsString } protected static String buildString(String name, String[] values, char separator, char joiner) { - int len = getLength(values); + int len = ArrayUtils.length(values); if (len == 0) { return null; From 798a0047a5b3f374742e80b89a40838a048c4ef9 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:04:26 +0800 Subject: [PATCH 047/115] Update ListUtils.java --- .../main/java/io/microsphere/collection/ListUtils.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/ListUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/ListUtils.java index 9636fd781..0cb27588c 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/ListUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/ListUtils.java @@ -54,6 +54,14 @@ public static List of(E... elements) { return unmodifiableList(asList(elements)); } + /** + * Create a {@link List} from the specified array + * + * @param elements + * @param + * @return + * @see {@link Lists#ofList} as recommended + */ public static List ofList(E... elements) { return of(elements); } From 6cb0ffe3b01e54414ed8ce94460475aa2e9a3a1b Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:04:37 +0800 Subject: [PATCH 048/115] Update URLUtilsTest.java --- .../java/io/microsphere/net/URLUtilsTest.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java index 98e5d65c3..f0815ccae 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/URLUtilsTest.java @@ -16,11 +16,11 @@ import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandlerFactory; -import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import static io.microsphere.collection.Lists.ofList; import static io.microsphere.constants.SymbolConstants.AND_CHAR; import static io.microsphere.net.URLUtils.attachURLStreamHandlerFactory; import static io.microsphere.net.URLUtils.buildMatrixString; @@ -50,7 +50,6 @@ import static io.microsphere.net.console.HandlerTest.TEST_CONSOLE_URL; import static io.microsphere.util.ClassLoaderUtils.getClassResource; import static io.microsphere.util.ClassLoaderUtils.getDefaultClassLoader; -import static io.microsphere.util.StringUtils.EMPTY; import static io.microsphere.util.StringUtils.EMPTY_STRING; import static io.microsphere.util.StringUtils.substringBeforeLast; import static io.microsphere.util.SystemUtils.USER_DIR; @@ -167,11 +166,11 @@ public void testResolveQueryParameters() { String url = TEST_HTTP_WITH_QUERY_STRING; Map> parametersMap = resolveQueryParameters(url); Map> expectedParametersMap = new LinkedHashMap<>(); - expectedParametersMap.put("q", Arrays.asList("java")); - expectedParametersMap.put("oq", Arrays.asList("java")); - expectedParametersMap.put("sourceid", Arrays.asList("chrome")); - expectedParametersMap.put("es_sm", Arrays.asList("122")); - expectedParametersMap.put("ie", Arrays.asList("UTF-8")); + expectedParametersMap.put("q", ofList("java")); + expectedParametersMap.put("oq", ofList("java")); + expectedParametersMap.put("sourceid", ofList("chrome")); + expectedParametersMap.put("es_sm", ofList("122")); + expectedParametersMap.put("ie", ofList("UTF-8")); assertEquals(expectedParametersMap, parametersMap); @@ -191,11 +190,11 @@ public void testResolveMatrixParameters() { String url = TEST_HTTP_WITH_MATRIX_STRING; Map> parametersMap = resolveMatrixParameters(url); Map> expectedParametersMap = new LinkedHashMap<>(); - expectedParametersMap.put("q", Arrays.asList("java")); - expectedParametersMap.put("oq", Arrays.asList("java")); - expectedParametersMap.put("sourceid", Arrays.asList("chrome")); - expectedParametersMap.put("es_sm", Arrays.asList("122")); - expectedParametersMap.put("ie", Arrays.asList("UTF-8")); + expectedParametersMap.put("q", ofList("java")); + expectedParametersMap.put("oq", ofList("java")); + expectedParametersMap.put("sourceid", ofList("chrome")); + expectedParametersMap.put("es_sm", ofList("122")); + expectedParametersMap.put("ie", ofList("UTF-8")); assertEquals(expectedParametersMap, parametersMap); From 11ada25498d38872b49f29e7aeb8cdf40389d8f8 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:06:03 +0800 Subject: [PATCH 049/115] Update FilterOperator.java --- .../main/java/io/microsphere/filter/FilterOperator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/filter/FilterOperator.java b/microsphere-java-core/src/main/java/io/microsphere/filter/FilterOperator.java index c2812a177..719b080fa 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/filter/FilterOperator.java +++ b/microsphere-java-core/src/main/java/io/microsphere/filter/FilterOperator.java @@ -1,6 +1,6 @@ package io.microsphere.filter; -import java.lang.reflect.Array; +import static io.microsphere.util.ArrayUtils.length; /** * {@link Filter} Operator enumeration , which contains {@link #AND}��{@link #OR}��{@link #XOR} @@ -21,7 +21,7 @@ public enum FilterOperator { AND { @Override public boolean accept(T filteredObject, Filter... filters) { - int length = Array.getLength(filters); + int length = length(filters); if (length == 0) return true; boolean success = true; @@ -38,7 +38,7 @@ public boolean accept(T filteredObject, Filter... filters) { OR { @Override public boolean accept(T filteredObject, Filter... filters) { - int length = Array.getLength(filters); + int length = length(filters); if (length == 0) return true; boolean success = false; @@ -54,7 +54,7 @@ public boolean accept(T filteredObject, Filter... filters) { XOR { @Override public boolean accept(T filteredObject, Filter... filters) { - int length = Array.getLength(filters); + int length = length(filters); if (length == 0) return true; boolean success = true; From 8da1c73a6c19158d629e85fbe32e254021aa3898 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:09:08 +0800 Subject: [PATCH 050/115] Update URLUtils.java --- .../src/main/java/io/microsphere/net/URLUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java index 820d9bc90..3eb3198d9 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java @@ -59,7 +59,6 @@ import static io.microsphere.util.StringUtils.substringAfterLast; import static io.microsphere.util.SystemUtils.FILE_ENCODING; import static java.lang.Character.isWhitespace; -import static java.lang.reflect.Array.getLength; import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; import static java.util.Collections.unmodifiableMap; @@ -451,7 +450,7 @@ public static boolean isArchiveURL(URL url) { * @return URI */ public static String buildURI(String... paths) { - int length = getLength(paths); + int length = ArrayUtils.length(paths); if (length < 1) { return SLASH; } From dcf28cabec6399f92848a8edc1902dc67599668b Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:12:00 +0800 Subject: [PATCH 051/115] Update ReflectionUtils.java --- .../main/java/io/microsphere/reflect/ReflectionUtils.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/ReflectionUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/ReflectionUtils.java index bb2770981..ec48fcc40 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/ReflectionUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/ReflectionUtils.java @@ -25,6 +25,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import static io.microsphere.collection.CollectionUtils.addAll; import static io.microsphere.logging.LoggerFactory.getLogger; import static io.microsphere.reflect.AccessibleObjectUtils.trySetAccessible; import static io.microsphere.reflect.FieldUtils.getDeclaredField; @@ -34,7 +35,6 @@ import static io.microsphere.util.ClassUtils.isPrimitive; import static io.microsphere.util.ClassUtils.isSimpleType; import static java.lang.reflect.Modifier.isStatic; -import static java.util.Arrays.asList; import static java.util.Collections.emptySet; import static java.util.Collections.unmodifiableSet; @@ -434,8 +434,9 @@ public static Map readFieldsAsMap(Object object) { * @return non-null read-only {@link Set} */ public static Set findParameterizedTypes(Class sourceClass) { + List genericTypes = new LinkedList<>(); // Add Generic Interfaces - List genericTypes = new LinkedList<>(asList(sourceClass.getGenericInterfaces())); + addAll(genericTypes, sourceClass.getGenericInterfaces()); // Add Generic Super Class genericTypes.add(sourceClass.getGenericSuperclass()); From ccfc72898d080f2110095d848b6315206740ed9b Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:16:02 +0800 Subject: [PATCH 052/115] Update WindowsRedefinedClassLoader.java --- .../microsphere/classloading/WindowsRedefinedClassLoader.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/classloading/WindowsRedefinedClassLoader.java b/microsphere-java-core/src/main/java/io/microsphere/classloading/WindowsRedefinedClassLoader.java index 54add7d97..c599bb2c3 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/classloading/WindowsRedefinedClassLoader.java +++ b/microsphere-java-core/src/main/java/io/microsphere/classloading/WindowsRedefinedClassLoader.java @@ -1,5 +1,6 @@ package io.microsphere.classloading; +import io.microsphere.collection.CollectionUtils; import io.microsphere.io.IOUtils; import io.microsphere.logging.Logger; @@ -20,6 +21,7 @@ import java.util.TreeMap; import java.util.TreeSet; +import static io.microsphere.collection.CollectionUtils.addAll; import static io.microsphere.collection.MapUtils.isEmpty; import static io.microsphere.constants.SeparatorConstants.LINE_SEPARATOR; import static io.microsphere.io.IOUtils.toByteArray; @@ -162,7 +164,7 @@ private static SortedSet loadRedefinedClassNames(ClassLoader classLoader try (InputStream inputStream = resource.openStream()) { String configContent = IOUtils.toString(inputStream, charset); String[] classNames = split(configContent, LINE_SEPARATOR); - redefinedClassNames.addAll(Arrays.asList(classNames)); + addAll(redefinedClassNames, classNames); } } } catch (IOException e) { From 3419e13d1ea37cca82fdfb06d66eb167da120291 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:16:07 +0800 Subject: [PATCH 053/115] Update MethodUtils.java --- .../src/main/java/io/microsphere/reflect/MethodUtils.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java index c818ba2ab..6cc2463ff 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java @@ -57,7 +57,6 @@ import static io.microsphere.util.ClassUtils.getTypes; import static io.microsphere.util.ClassUtils.isArray; import static io.microsphere.util.ClassUtils.isPrimitive; -import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.unmodifiableList; @@ -378,10 +377,10 @@ public static R invokeMethod(@Nullable Object instance, Method method, Objec String errorMessage = format("The method[signature : '{}' , instance : {}] can't be accessed[accessible : {}]", getSignature(method), instance, accessible); failure = new IllegalStateException(errorMessage, e); } catch (IllegalArgumentException e) { - String errorMessage = format("The arguments can't match the method[signature : '{}' , instance : {}] : {}", getSignature(method), instance, asList(arguments)); + String errorMessage = format("The arguments can't match the method[signature : '{}' , instance : {}] : {}", getSignature(method), instance, Arrays.toString(arguments)); failure = new IllegalArgumentException(errorMessage, e); } catch (InvocationTargetException e) { - String errorMessage = format("It's failed to invoke the method[signature : '{}' , instance : {} , arguments : {}]", getSignature(method), instance, asList(arguments)); + String errorMessage = format("It's failed to invoke the method[signature : '{}' , instance : {} , arguments : {}]", getSignature(method), instance, Arrays.toString(arguments)); failure = new RuntimeException(errorMessage, e.getTargetException()); } From 2ad566c9c3d5e9c0d2eb1692109a208e852f3b0a Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:16:12 +0800 Subject: [PATCH 054/115] Update CollectionUtilsTest.java --- .../java/io/microsphere/collection/CollectionUtilsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/CollectionUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/CollectionUtilsTest.java index 4dab46193..52849bee4 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/CollectionUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/CollectionUtilsTest.java @@ -19,7 +19,6 @@ import io.microsphere.AbstractTestCase; import org.junit.jupiter.api.Test; -import java.util.Arrays; import java.util.Collection; import java.util.Enumeration; import java.util.Iterator; @@ -34,6 +33,7 @@ import static io.microsphere.collection.CollectionUtils.singletonIterable; import static io.microsphere.collection.CollectionUtils.size; import static io.microsphere.collection.CollectionUtils.toIterable; +import static io.microsphere.collection.Lists.ofList; import static java.util.Collections.emptyEnumeration; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -153,7 +153,7 @@ public void testAddAll() { assertEquals(0, addAll(null, "A")); assertEquals(0, addAll(values)); assertEquals(2, addAll(values, "A", "B")); - assertEquals(Arrays.asList("A", "B"), values); + assertEquals(ofList("A", "B"), values); } @Test From 2a2300c0a2dc96bbbee2b1d986067479e25f3844 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:16:16 +0800 Subject: [PATCH 055/115] Update ListsTest.java --- .../src/test/java/io/microsphere/collection/ListsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 d615c7f6a..5d31ec3c3 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 @@ -3,7 +3,7 @@ import org.junit.jupiter.api.Test; import static io.microsphere.collection.Lists.ofList; -import static java.util.Arrays.asList; +import static io.microsphere.collection.ListUtils.of; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -19,6 +19,6 @@ public class ListsTest { @Test public void testOfList() { assertTrue(ofList().isEmpty()); - assertEquals(asList(1, 2, 3), ofList(1, 2, 3)); + assertEquals(of(1, 2, 3), ofList(1, 2, 3)); } } \ No newline at end of file From ef0cfc2a38c19cd96d7a00bb4105eaaa849f3d61 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:18:02 +0800 Subject: [PATCH 056/115] Update MapUtilsTest.java --- .../src/test/java/io/microsphere/collection/MapUtilsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java index 4c31ef832..552cbf1bb 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java @@ -18,7 +18,6 @@ import org.junit.jupiter.api.Test; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.IdentityHashMap; @@ -28,6 +27,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentSkipListMap; +import static io.microsphere.collection.Lists.ofList; import static io.microsphere.collection.MapUtils.FIXED_LOAD_FACTOR; import static io.microsphere.collection.MapUtils.immutableEntry; import static io.microsphere.collection.MapUtils.isEmpty; @@ -172,7 +172,7 @@ public void testToFixedMap() { Map map = toFixedMap(Collections.emptyList(), a -> ofEntry(a, a.hashCode())); assertTrue(map.isEmpty()); - map = toFixedMap(Arrays.asList("A", "B"), a -> ofEntry(a, a.hashCode())); + map = toFixedMap(ofList("A", "B"), a -> ofEntry(a, a.hashCode())); assertEquals(2, map.size()); assertEquals("A".hashCode(), map.get("A")); assertEquals("B".hashCode(), map.get("B")); From fd7a82701ad7af982ffb41398f75d30b262f791d Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:18:10 +0800 Subject: [PATCH 057/115] Update StringToBlockingDequeConverterTest.java --- .../multiple/StringToBlockingDequeConverterTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToBlockingDequeConverterTest.java b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToBlockingDequeConverterTest.java index 59eb3019e..843b4c157 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToBlockingDequeConverterTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToBlockingDequeConverterTest.java @@ -37,7 +37,7 @@ import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.TransferQueue; -import static java.util.Arrays.asList; +import static io.microsphere.collection.Lists.ofList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; @@ -89,13 +89,13 @@ public void testAccept() { @Test public void testConvert() throws NoSuchFieldException { - BlockingQueue values = new LinkedBlockingDeque(asList(1, 2, 3)); + BlockingQueue values = new LinkedBlockingDeque(ofList(1, 2, 3)); BlockingDeque result = (BlockingDeque) converter.convert("1,2,3", BlockingDeque.class, Integer.class); assertTrue(CollectionUtils.equals(values, result)); - values = new LinkedBlockingDeque(asList(123)); + values = new LinkedBlockingDeque(ofList(123)); result = (BlockingDeque) converter.convert("123", BlockingDeque.class, Integer.class); From 52093d9f31d4dc7810781c937e78f87d453a7d1c Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:51:37 +0800 Subject: [PATCH 058/115] Update MethodUtils.java --- .../microsphere/annotation/processor/util/MethodUtils.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/MethodUtils.java b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/MethodUtils.java index 7fabaa34d..f79057002 100644 --- a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/MethodUtils.java +++ b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/MethodUtils.java @@ -35,11 +35,12 @@ import static io.microsphere.annotation.processor.util.MemberUtils.matchParameterTypes; import static io.microsphere.annotation.processor.util.TypeUtils.getHierarchicalTypes; import static io.microsphere.annotation.processor.util.TypeUtils.ofDeclaredType; +import static io.microsphere.collection.CollectionUtils.addAll; import static io.microsphere.filter.FilterUtils.filter; import static io.microsphere.lang.function.Predicates.EMPTY_PREDICATE_ARRAY; import static io.microsphere.lang.function.Streams.filterAll; import static io.microsphere.lang.function.Streams.filterFirst; -import static java.util.Arrays.asList; +import static io.microsphere.collection.Lists.ofList; import static java.util.Collections.emptyList; import static javax.lang.model.element.ElementKind.METHOD; import static javax.lang.model.util.ElementFilter.methodsIn; @@ -106,7 +107,7 @@ static ExecutableElement findMethod(TypeElement type, String methodName, Type on static ExecutableElement findMethod(TypeMirror type, String methodName, Type oneParameterType, Type... otherParameterTypes) { List parameterTypes = new LinkedList<>(); parameterTypes.add(oneParameterType); - parameterTypes.addAll(asList(otherParameterTypes)); + addAll(parameterTypes, otherParameterTypes); return findMethod(type, methodName, parameterTypes.stream().map(Type::getTypeName).toArray(String[]::new)); } From 0eda5ebd1c848f9e165560d569778a8aefe220d6 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:51:39 +0800 Subject: [PATCH 059/115] Update TypeUtils.java --- .../io/microsphere/annotation/processor/util/TypeUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/TypeUtils.java b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/TypeUtils.java index 2984352dd..3e0e8ec3f 100644 --- a/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/TypeUtils.java +++ b/microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/TypeUtils.java @@ -43,7 +43,7 @@ import static io.microsphere.lang.function.Streams.filterFirst; import static io.microsphere.reflect.MethodUtils.invokeMethod; import static java.lang.String.valueOf; -import static java.util.Arrays.asList; +import static io.microsphere.collection.Lists.ofList; import static java.util.Collections.emptyList; import static java.util.Collections.emptySet; import static java.util.stream.Collectors.toSet; @@ -61,7 +61,7 @@ */ public interface TypeUtils { - List SIMPLE_TYPES = asList( + List SIMPLE_TYPES = ofList( ClassUtils.SIMPLE_TYPES .stream() .map(Class::getName) From 3062d9eab1856358345bb4bfff1ec7e77786d9ab Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:51:41 +0800 Subject: [PATCH 060/115] Update Compiler.java --- .../java/io/microsphere/annotation/processor/Compiler.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/Compiler.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/Compiler.java index 80b0e9ad4..ba47c62ed 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/Compiler.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/Compiler.java @@ -29,7 +29,8 @@ import java.util.LinkedHashSet; import java.util.Set; -import static java.util.Arrays.asList; +import static io.microsphere.collection.CollectionUtils.addAll; +import static io.microsphere.collection.Lists.ofList; /** * The Java Compiler @@ -84,7 +85,7 @@ private static File detectClassPath(Class targetClass) { } public Compiler processors(Processor... processors) { - this.processors.addAll(asList(processors)); + addAll(this.processors, processors); return this; } @@ -105,7 +106,7 @@ private File javaSourceFile(String sourceClassName) { public boolean compile(Class... sourceClasses) { JavaCompiler.CompilationTask task = javaCompiler.getTask(null, this.javaFileManager, null, - asList("-parameters", "-Xlint:unchecked", "-nowarn", "-Xlint:deprecation"), + ofList("-parameters", "-Xlint:unchecked", "-nowarn", "-Xlint:deprecation"), // null, null, getJavaFileObjects(sourceClasses)); if (!processors.isEmpty()) { From 06916f8a50feb54ca44dc4fb16c971bc0cf39d76 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:51:44 +0800 Subject: [PATCH 061/115] Update TypeUtilsTest.java --- .../annotation/processor/util/TypeUtilsTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java index 6ca3771ec..e93f51907 100644 --- a/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java +++ b/microsphere-annotation-processor/src/test/java/io/microsphere/annotation/processor/util/TypeUtilsTest.java @@ -68,7 +68,7 @@ import static io.microsphere.annotation.processor.util.TypeUtils.ofDeclaredType; import static io.microsphere.annotation.processor.util.TypeUtils.ofDeclaredTypes; import static io.microsphere.annotation.processor.util.TypeUtils.ofTypeElement; -import static java.util.Arrays.asList; +import static io.microsphere.collection.Lists.ofList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -415,7 +415,7 @@ public void testOfTypeElement() { @Test public void testOfDeclaredTypes() { - Set declaredTypes = ofDeclaredTypes(asList(getType(String.class), getType(TestServiceImpl.class), getType(Color.class))); + Set declaredTypes = ofDeclaredTypes(ofList(getType(String.class), getType(TestServiceImpl.class), getType(Color.class))); assertTrue(declaredTypes.contains(getType(String.class).asType())); assertTrue(declaredTypes.contains(getType(TestServiceImpl.class).asType())); assertTrue(declaredTypes.contains(getType(Color.class).asType())); @@ -425,24 +425,24 @@ public void testOfDeclaredTypes() { @Test public void testListDeclaredTypes() { - List types = listDeclaredTypes(asList(testType, testType, testType)); + List types = listDeclaredTypes(ofList(testType, testType, testType)); assertEquals(1, types.size()); assertEquals(ofDeclaredType(testType), types.get(0)); - types = listDeclaredTypes(asList(new Element[]{null})); + types = listDeclaredTypes(ofList(new Element[]{null})); assertTrue(types.isEmpty()); } @Test public void testListTypeElements() { - List typeElements = listTypeElements(asList(testType.asType(), ofDeclaredType(testType))); + List typeElements = listTypeElements(ofList(testType.asType(), ofDeclaredType(testType))); assertEquals(1, typeElements.size()); assertEquals(testType, typeElements.get(0)); - typeElements = listTypeElements(asList(types.getPrimitiveType(TypeKind.BYTE), types.getNullType(), types.getNoType(TypeKind.NONE))); + typeElements = listTypeElements(ofList(types.getPrimitiveType(TypeKind.BYTE), types.getNullType(), types.getNoType(TypeKind.NONE))); assertTrue(typeElements.isEmpty()); - typeElements = listTypeElements(asList(new TypeMirror[]{null})); + typeElements = listTypeElements(ofList(new TypeMirror[]{null})); assertTrue(typeElements.isEmpty()); typeElements = listTypeElements(null); From 1eaa18b678cb070ba79d8ed7dbd6b96e82f3840d Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:51:47 +0800 Subject: [PATCH 062/115] Update WindowsRedefinedClassLoader.java --- .../microsphere/classloading/WindowsRedefinedClassLoader.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/classloading/WindowsRedefinedClassLoader.java b/microsphere-java-core/src/main/java/io/microsphere/classloading/WindowsRedefinedClassLoader.java index c599bb2c3..292e01a5c 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/classloading/WindowsRedefinedClassLoader.java +++ b/microsphere-java-core/src/main/java/io/microsphere/classloading/WindowsRedefinedClassLoader.java @@ -1,6 +1,5 @@ package io.microsphere.classloading; -import io.microsphere.collection.CollectionUtils; import io.microsphere.io.IOUtils; import io.microsphere.logging.Logger; @@ -12,7 +11,6 @@ import java.net.URLClassLoader; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.util.Arrays; import java.util.Enumeration; import java.util.LinkedList; import java.util.List; From ef5380ea17aecf57ee71d8d1e8c061f997d574fb Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:51:49 +0800 Subject: [PATCH 063/115] Update Listenable.java --- .../src/main/java/io/microsphere/event/Listenable.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/event/Listenable.java b/microsphere-java-core/src/main/java/io/microsphere/event/Listenable.java index 2fffd6d96..0d2c27e70 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/event/Listenable.java +++ b/microsphere-java-core/src/main/java/io/microsphere/event/Listenable.java @@ -18,9 +18,9 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; +import static io.microsphere.collection.CollectionUtils.addAll; import static java.util.stream.StreamSupport.stream; /** @@ -73,7 +73,7 @@ default void addEventListeners(E listener, E... others) throws NullPointerExcept IllegalArgumentException { List listeners = new ArrayList<>(1 + others.length); listeners.add(listener); - listeners.addAll(Arrays.asList(others)); + addAll(listeners,others); addEventListeners(listeners); } From c94371ef50be3c51fa35f3bbaf02c223113b971d Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:51:51 +0800 Subject: [PATCH 064/115] Update ConstructorUtils.java --- .../java/io/microsphere/reflect/ConstructorUtils.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/ConstructorUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/ConstructorUtils.java index 5e5033942..17a010f47 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/ConstructorUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/ConstructorUtils.java @@ -20,14 +20,15 @@ import io.microsphere.util.BaseUtils; import java.lang.reflect.Constructor; +import java.util.Arrays; import java.util.List; import java.util.function.Predicate; +import static io.microsphere.collection.Lists.ofList; import static io.microsphere.lang.function.Streams.filterAll; import static io.microsphere.lang.function.ThrowableSupplier.execute; import static io.microsphere.logging.LoggerFactory.getLogger; import static io.microsphere.reflect.MemberUtils.isPrivate; -import static java.util.Arrays.asList; /** * The utilities class of {@link Constructor} @@ -66,13 +67,13 @@ public static boolean hasNonPrivateConstructorWithoutParameters(Class type) { public static List> findConstructors(Class type, Predicate>... constructorFilters) { - List> constructors = asList(type.getConstructors()); + List> constructors = ofList(type.getConstructors()); return filterAll(constructors, constructorFilters); } public static List> findDeclaredConstructors(Class type, Predicate>... constructorFilters) { - List> constructors = asList(type.getDeclaredConstructors()); + List> constructors = ofList(type.getDeclaredConstructors()); return filterAll(constructors, constructorFilters); } @@ -87,7 +88,7 @@ public static Constructor getDeclaredConstructor(Class type, Class. public static Constructor findConstructor(Class type, Class... parameterTypes) { return execute(() -> type.getDeclaredConstructor(parameterTypes), e -> { if (logger.isTraceEnabled()) { - logger.trace("The declared constructor of '{}' can't be found by parameter types : {}", type, asList(parameterTypes)); + logger.trace("The declared constructor of '{}' can't be found by parameter types : {}", type, Arrays.toString(parameterTypes)); } return NOT_FOUND_CONSTRUCTOR; }); From 19db362378d78cdebfc7cecc17fed16b4a981c70 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:51:53 +0800 Subject: [PATCH 065/115] Update FieldUtils.java --- .../main/java/io/microsphere/reflect/FieldUtils.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/FieldUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/FieldUtils.java index 5cc7f20be..020431989 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/FieldUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/FieldUtils.java @@ -25,6 +25,8 @@ import java.util.Set; import java.util.function.Predicate; +import static io.microsphere.collection.CollectionUtils.addAll; +import static io.microsphere.collection.Lists.ofList; import static io.microsphere.lang.function.Predicates.and; import static io.microsphere.lang.function.Streams.filter; import static io.microsphere.lang.function.ThrowableSupplier.execute; @@ -32,7 +34,6 @@ import static io.microsphere.reflect.AccessibleObjectUtils.trySetAccessible; import static io.microsphere.text.FormatUtils.format; import static io.microsphere.util.ClassUtils.getAllInheritedTypes; -import static java.util.Arrays.asList; /** * The Java Reflection {@link Field} Utility class @@ -141,17 +142,17 @@ public static void setStaticFieldValue(Class klass, String fieldName, Object } public static Set findAllFields(Class declaredClass, Predicate... fieldFilters) { - Set allFields = new LinkedHashSet<>(asList(declaredClass.getFields())); + Set allFields = new LinkedHashSet<>(ofList(declaredClass.getFields())); for (Class superType : getAllInheritedTypes(declaredClass)) { - allFields.addAll(asList(superType.getFields())); + allFields.addAll(ofList(superType.getFields())); } return filter(allFields, and(fieldFilters)); } public static Set findAllDeclaredFields(Class declaredClass, Predicate... fieldFilters) { - Set allDeclaredFields = new LinkedHashSet<>(asList(declaredClass.getDeclaredFields())); + Set allDeclaredFields = new LinkedHashSet<>(ofList(declaredClass.getDeclaredFields())); for (Class superType : getAllInheritedTypes(declaredClass)) { - allDeclaredFields.addAll(asList(superType.getDeclaredFields())); + addAll(allDeclaredFields, superType.getDeclaredFields()); } return filter(allDeclaredFields, and(fieldFilters)); } From 417a251ce97ed6ac4f642fec46c468502f6b332b Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:51:55 +0800 Subject: [PATCH 066/115] Update MethodUtils.java --- .../src/main/java/io/microsphere/reflect/MethodUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java index 6cc2463ff..4178bd0ae 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java @@ -36,7 +36,7 @@ import java.util.concurrent.ConcurrentMap; import java.util.function.Predicate; -import static io.microsphere.collection.ListUtils.ofList; +import static io.microsphere.collection.Lists.ofList; import static io.microsphere.constants.SymbolConstants.COMMA_CHAR; import static io.microsphere.constants.SymbolConstants.LEFT_PARENTHESIS_CHAR; import static io.microsphere.constants.SymbolConstants.RIGHT_PARENTHESIS_CHAR; From 9e573d06ce940506ffa93113f0fedf38e29b3e87 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:51:57 +0800 Subject: [PATCH 067/115] Update TypeUtils.java --- .../io/microsphere/reflect/TypeUtils.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/TypeUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/TypeUtils.java index c6f6a95d0..f0b48a960 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/TypeUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/TypeUtils.java @@ -37,8 +37,10 @@ import java.util.function.Predicate; import java.util.stream.Collectors; +import static io.microsphere.collection.CollectionUtils.addAll; import static io.microsphere.collection.ListUtils.newArrayList; import static io.microsphere.collection.ListUtils.newLinkedList; +import static io.microsphere.collection.Lists.ofList; import static io.microsphere.collection.MapUtils.newConcurrentHashMap; import static io.microsphere.collection.MapUtils.newLinkedHashMap; import static io.microsphere.lang.function.Predicates.EMPTY_PREDICATE_ARRAY; @@ -47,7 +49,6 @@ import static io.microsphere.lang.function.Streams.filterList; import static io.microsphere.util.ClassUtils.getAllSuperClasses; import static java.lang.Integer.getInteger; -import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.emptySet; import static java.util.Collections.singleton; @@ -272,7 +273,7 @@ protected static List doResolveActualTypeArguments(Type type, Class baseCl } } - return Arrays.asList(actualTypeArguments); + return ofList(actualTypeArguments); }); } @@ -398,9 +399,15 @@ public static List getGenericTypes(Type type, Predicate genericTypes = new LinkedList<>(); genericTypes.add(rawClass.getGenericSuperclass()); - genericTypes.addAll(asList(rawClass.getGenericInterfaces())); + addAll(genericTypes, rawClass.getGenericInterfaces()); - return unmodifiableList(filterList(genericTypes, TypeUtils::isParameterizedType).stream().map(ParameterizedType.class::cast).filter(and(typeFilters)).collect(toList())); + return unmodifiableList( + filterList(genericTypes, TypeUtils::isParameterizedType) + .stream() + .map(ParameterizedType.class::cast) + .filter(and(typeFilters)) + .collect(toList()) + ); } public static List findAllTypes(Type type, Predicate... typeFilters) { @@ -552,7 +559,12 @@ public static List getAllGenericInterfaces(Type type, Predica // Add all super interfaces allTypes.addAll(ClassUtils.getAllInterfaces(rawClass)); - List allGenericInterfaces = allTypes.stream().map(Class::getGenericInterfaces).map(Arrays::asList).flatMap(Collection::stream).map(TypeUtils::asParameterizedType).filter(Objects::nonNull).collect(toList()); + List allGenericInterfaces = allTypes.stream().map(Class::getGenericInterfaces) + .map(Arrays::asList) + .flatMap(Collection::stream) + .map(TypeUtils::asParameterizedType) + .filter(Objects::nonNull) + .collect(toList()); return unmodifiableList(filterAll(allGenericInterfaces, typeFilters)); } @@ -758,8 +770,9 @@ public static Set getAllTypes(Type type, Predicate... typeFilters) { } public static Set findParameterizedTypes(Class sourceClass) { + List genericTypes = new LinkedList<>(); // Add Generic Interfaces - List genericTypes = new LinkedList<>(asList(sourceClass.getGenericInterfaces())); + addAll(genericTypes, sourceClass.getGenericInterfaces()); // Add Generic Super Class genericTypes.add(sourceClass.getGenericSuperclass()); From e180fa82470a84e9dea9f56a79f29ab7c23e7aee Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:51:59 +0800 Subject: [PATCH 068/115] Update AnnotationUtils.java --- .../io/microsphere/util/AnnotationUtils.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/AnnotationUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/AnnotationUtils.java index 319d28aca..e0066d1f1 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/AnnotationUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/AnnotationUtils.java @@ -38,6 +38,7 @@ import java.util.function.Predicate; import java.util.stream.Stream; +import static io.microsphere.collection.Lists.ofList; import static io.microsphere.lang.function.Predicates.and; import static io.microsphere.lang.function.Streams.filterAll; import static io.microsphere.lang.function.Streams.filterFirst; @@ -47,10 +48,8 @@ import static io.microsphere.util.ArrayUtils.length; import static io.microsphere.util.ClassLoaderUtils.resolveClass; import static io.microsphere.util.ClassUtils.getAllInheritedTypes; -import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; -import static java.util.Collections.unmodifiableList; import static java.util.Collections.unmodifiableMap; import static java.util.Optional.ofNullable; @@ -62,8 +61,14 @@ */ public abstract class AnnotationUtils extends BaseUtils { - public final static List> NATIVE_ANNOTATION_TYPES = unmodifiableList(asList - (Target.class, Retention.class, Documented.class, Inherited.class, Native.class, Repeatable.class)); + public final static List> NATIVE_ANNOTATION_TYPES = ofList( + Target.class, + Retention.class, + Documented.class, + Inherited.class, + Native.class, + Repeatable.class + ); private static final Predicate INHERITED_OBJECT_METHOD_PREDICATE = AnnotationUtils::isInheritedObjectMethod; @@ -138,7 +143,7 @@ public static boolean isMetaAnnotation(Annotation annotation, if (metaAnnotationTypes == null) { return false; } - return isMetaAnnotation(annotation, asList(metaAnnotationTypes)); + return isMetaAnnotation(annotation, ofList(metaAnnotationTypes)); } public static boolean isMetaAnnotation(Annotation annotation, @@ -151,7 +156,7 @@ public static boolean isMetaAnnotation(Annotation annotation, public static boolean isMetaAnnotation(Class annotationType, Class... metaAnnotationTypes) { - return isMetaAnnotation(annotationType, asList(metaAnnotationTypes)); + return isMetaAnnotation(annotationType, ofList(metaAnnotationTypes)); } public static boolean isMetaAnnotation(Class annotationType, @@ -200,7 +205,7 @@ public static > Optional filterAnnota public static List filterAnnotations(Annotation[] annotations, Predicate... annotationsToFilter) { - return filterAnnotations(asList(annotations), annotationsToFilter); + return filterAnnotations(ofList(annotations), annotationsToFilter); } public static > S filterAnnotations(S annotations, @@ -252,7 +257,7 @@ public static List getDeclaredAnnotations(AnnotatedElement annotated return emptyList(); } - return filterAll(asList(annotatedElement.getAnnotations()), annotationsToFilter); + return filterAll(ofList(annotatedElement.getAnnotations()), annotationsToFilter); } public static T getAttributeValue(Annotation[] annotations, String attributeName, Class returnType) { From 511a793a1e609f803e72d685e48eeca6a21ed760 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:52:04 +0800 Subject: [PATCH 069/115] Update ArrayUtils.java --- .../src/main/java/io/microsphere/util/ArrayUtils.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/ArrayUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/ArrayUtils.java index dffb95fbb..c98bc56ea 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/ArrayUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/ArrayUtils.java @@ -18,6 +18,7 @@ import java.lang.reflect.Array; import java.lang.reflect.Parameter; +import java.util.Arrays; import java.util.Collection; import java.util.Enumeration; import java.util.function.BiConsumer; @@ -237,4 +238,14 @@ public static void forEach(T[] values, Consumer consumer) { forEach(values, (i, e) -> consumer.accept(e)); } + /** + * Convert the specified array to a string + * + * @param array the specified array + * @param the element type of array + * @return {@link Arrays#toString} + */ + public static String arrayToString(T[] array) { + return Arrays.toString(array); + } } From 00b2db75238e20ded9d4b0751ec4e73792dd8201 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:52:06 +0800 Subject: [PATCH 070/115] Update ClassLoaderUtils.java --- .../src/main/java/io/microsphere/util/ClassLoaderUtils.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/ClassLoaderUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/ClassLoaderUtils.java index a0d0c4118..b7314554c 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/ClassLoaderUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/ClassLoaderUtils.java @@ -18,7 +18,6 @@ import java.net.URL; import java.net.URLClassLoader; import java.security.SecureClassLoader; -import java.util.Arrays; import java.util.Enumeration; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -29,6 +28,7 @@ import java.util.concurrent.ConcurrentMap; import java.util.jar.JarFile; +import static io.microsphere.collection.CollectionUtils.addAll; import static io.microsphere.collection.CollectionUtils.isNotEmpty; import static io.microsphere.collection.SetUtils.ofSet; import static io.microsphere.constants.FileConstants.CLASS_EXTENSION; @@ -632,9 +632,8 @@ public static Set findAllClassPathURLs(ClassLoader classLoader) { Set allClassPathURLs = new LinkedHashSet<>(); URL[] classPathURLs = urlClassPathHandle.getURLs(classLoader); - int length = classPathURLs.length; - allClassPathURLs.addAll(Arrays.asList(classPathURLs).subList(0, length)); + addAll(allClassPathURLs,classPathURLs); ClassLoader parentClassLoader = classLoader.getParent(); if (parentClassLoader != null) { From 51889456d64ef7b2e8f45184cfd0003138698d39 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:52:10 +0800 Subject: [PATCH 071/115] Update ClassUtils.java --- .../src/main/java/io/microsphere/util/ClassUtils.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/ClassUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/ClassUtils.java index 3f5cb6612..1c683a933 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/ClassUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/ClassUtils.java @@ -33,6 +33,7 @@ import java.util.jar.JarEntry; import java.util.jar.JarFile; +import static io.microsphere.collection.Lists.ofList; import static io.microsphere.collection.MapUtils.ofMap; import static io.microsphere.collection.SetUtils.newLinkedHashSet; import static io.microsphere.collection.SetUtils.of; @@ -53,6 +54,7 @@ import static io.microsphere.reflect.ConstructorUtils.findDeclaredConstructors; import static io.microsphere.text.FormatUtils.format; import static io.microsphere.util.ArrayUtils.EMPTY_CLASS_ARRAY; +import static io.microsphere.util.ArrayUtils.arrayToString; import static io.microsphere.util.ArrayUtils.isEmpty; import static io.microsphere.util.ArrayUtils.isNotEmpty; import static io.microsphere.util.ArrayUtils.length; @@ -65,7 +67,6 @@ import static io.microsphere.util.StringUtils.substringBetween; import static java.lang.reflect.Modifier.isAbstract; import static java.lang.reflect.Modifier.isInterface; -import static java.util.Arrays.asList; import static java.util.Collections.emptySet; import static java.util.Collections.reverse; import static java.util.Collections.synchronizedMap; @@ -205,9 +206,9 @@ public abstract class ClassUtils extends BaseUtils { static { Map> typeNamesMap = new HashMap<>(16); List> primitiveTypeNames = new ArrayList<>(16); - primitiveTypeNames.addAll(asList(boolean.class, byte.class, char.class, double.class, + primitiveTypeNames.addAll(ofList(boolean.class, byte.class, char.class, double.class, float.class, int.class, long.class, short.class)); - primitiveTypeNames.addAll(asList(boolean[].class, byte[].class, char[].class, double[].class, + primitiveTypeNames.addAll(ofList(boolean[].class, byte[].class, char[].class, double[].class, float[].class, int[].class, long[].class, short[].class)); for (Class primitiveTypeName : primitiveTypeNames) { typeNamesMap.put(primitiveTypeName.getName(), primitiveTypeName); @@ -849,7 +850,7 @@ public static T newInstance(Class type, Object... args) { }); if (constructors.isEmpty()) { - String message = format("No constructor[class : '{}'] matches the arguments : {}", getTypeName(type), Arrays.asList(args)); + String message = format("No constructor[class : '{}'] matches the arguments : {}", getTypeName(type), arrayToString(args)); throw new IllegalArgumentException(message); } From 8c59a1b327e055a84b1b8b8c8dd8e869e7061de5 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:52:13 +0800 Subject: [PATCH 072/115] Update AbstractDequeTest.java --- .../test/java/io/microsphere/collection/AbstractDequeTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9c29d268d..0ccd8d0df 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 @@ -7,7 +7,7 @@ import java.util.NoSuchElementException; import static io.microsphere.collection.ListUtils.newLinkedList; -import static io.microsphere.collection.ListUtils.ofList; +import static io.microsphere.collection.Lists.ofList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; From 55e831aac7d68d6ed52e783df05b0845a4b9435c Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:52:17 +0800 Subject: [PATCH 073/115] Update ListsTest.java --- .../src/test/java/io/microsphere/collection/ListsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5d31ec3c3..eddac6290 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 @@ -2,8 +2,8 @@ import org.junit.jupiter.api.Test; -import static io.microsphere.collection.Lists.ofList; import static io.microsphere.collection.ListUtils.of; +import static io.microsphere.collection.Lists.ofList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; From d6ced9a6de2fc6630edd4bd07b4412bcee134a80 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:52:19 +0800 Subject: [PATCH 074/115] Update DelegatingBlockingQueueTest.java --- .../io/microsphere/concurrent/DelegatingBlockingQueueTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/concurrent/DelegatingBlockingQueueTest.java b/microsphere-java-core/src/test/java/io/microsphere/concurrent/DelegatingBlockingQueueTest.java index 0dfc99aed..73d109b0a 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/concurrent/DelegatingBlockingQueueTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/concurrent/DelegatingBlockingQueueTest.java @@ -12,7 +12,7 @@ import java.util.stream.Stream; import static io.microsphere.collection.ListUtils.newLinkedList; -import static io.microsphere.collection.ListUtils.ofList; +import static io.microsphere.collection.Lists.ofList; import static io.microsphere.collection.QueueUtils.emptyQueue; import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.jupiter.api.Assertions.assertArrayEquals; From ac87b8b1ae11a7065e256dcef6b9d2d183a0ce88 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:52:21 +0800 Subject: [PATCH 075/115] Update DelegatingScheduledExecutorServiceTest.java --- .../concurrent/DelegatingScheduledExecutorServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/concurrent/DelegatingScheduledExecutorServiceTest.java b/microsphere-java-core/src/test/java/io/microsphere/concurrent/DelegatingScheduledExecutorServiceTest.java index c3d30d91c..0ed6dd2e3 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/concurrent/DelegatingScheduledExecutorServiceTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/concurrent/DelegatingScheduledExecutorServiceTest.java @@ -7,7 +7,7 @@ import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; -import static io.microsphere.collection.ListUtils.ofList; +import static io.microsphere.collection.Lists.ofList; import static io.microsphere.logging.LoggerFactory.getLogger; import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; import static java.util.concurrent.TimeUnit.MILLISECONDS; From ee7c8d5a05eac0bade7de81da00f323ab3218876 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:52:24 +0800 Subject: [PATCH 076/115] Update StringToCollectionConverterTest.java --- .../convert/multiple/StringToCollectionConverterTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToCollectionConverterTest.java b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToCollectionConverterTest.java index 75e3dcbe3..c4c05a8aa 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToCollectionConverterTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToCollectionConverterTest.java @@ -35,7 +35,7 @@ import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.TransferQueue; -import static java.util.Arrays.asList; +import static io.microsphere.collection.Lists.ofList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; @@ -86,13 +86,13 @@ public void testAccept() { @Test public void testConvert() { - List values = asList(1L, 2L, 3L); + List values = ofList(1L, 2L, 3L); Collection result = (Collection) converter.convert("1,2,3", Collection.class, Long.class); assertEquals(values, result); - values = asList(123); + values = ofList(123); result = (Collection) converter.convert("123", Collection.class, Integer.class); From 159308a1b402d83f9cf182dff4bdf7ce4c8c9c7d Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:52:26 +0800 Subject: [PATCH 077/115] Update StringToDequeConverterTest.java --- .../convert/multiple/StringToDequeConverterTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToDequeConverterTest.java b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToDequeConverterTest.java index 8cdcdb689..1ea5c123a 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToDequeConverterTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToDequeConverterTest.java @@ -37,7 +37,7 @@ import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.TransferQueue; -import static java.util.Arrays.asList; +import static io.microsphere.collection.Lists.ofList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; @@ -88,13 +88,13 @@ public void testAccept() { @Test public void testConvert() { - Deque values = new ArrayDeque(asList(1, 2, 3)); + Deque values = new ArrayDeque(ofList(1, 2, 3)); Deque result = (Deque) converter.convert("1,2,3", Deque.class, Integer.class); assertTrue(CollectionUtils.equals(values, result)); - values = new ArrayDeque(asList("123")); + values = new ArrayDeque(ofList("123")); result = (Deque) converter.convert("123", Deque.class, String.class); From 31f3bd1f76d99520224d6726fe7e5cec3e5907f9 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:52:28 +0800 Subject: [PATCH 078/115] Update StringToListConverterTest.java --- .../convert/multiple/StringToListConverterTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToListConverterTest.java b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToListConverterTest.java index a88adc4d7..311556d55 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToListConverterTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToListConverterTest.java @@ -36,7 +36,7 @@ import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.TransferQueue; -import static java.util.Arrays.asList; +import static io.microsphere.collection.Lists.ofList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; @@ -87,13 +87,13 @@ public void testAccept() { @Test public void testConvert() { - List values = asList(1, 2, 3); + List values = ofList(1, 2, 3); List result = (List) converter.convert("1,2,3", List.class, Integer.class); assertTrue(CollectionUtils.equals(values, result)); - values = asList("123"); + values = ofList("123"); result = (List) converter.convert("123", List.class, String.class); From b266289a3777c03d6ea387b31219c7af15e96cc7 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:52:32 +0800 Subject: [PATCH 079/115] Update StringToNavigableSetConverterTest.java --- .../convert/multiple/StringToNavigableSetConverterTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToNavigableSetConverterTest.java b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToNavigableSetConverterTest.java index 56df55677..8ed1843c1 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToNavigableSetConverterTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToNavigableSetConverterTest.java @@ -36,7 +36,7 @@ import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.TransferQueue; -import static java.util.Arrays.asList; +import static io.microsphere.collection.Lists.ofList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; @@ -87,13 +87,13 @@ public void testAccept() { @Test public void testConvert() { - Set values = new TreeSet(asList(1, 2, 3)); + Set values = new TreeSet(ofList(1, 2, 3)); NavigableSet result = (NavigableSet) converter.convert("1,2,3", List.class, Integer.class); assertTrue(CollectionUtils.equals(values, result)); - values = new TreeSet(asList("123")); + values = new TreeSet(ofList("123")); result = (NavigableSet) converter.convert("123", NavigableSet.class, String.class); From 4583c88d2f8b116c72d66e4390a6f09e35622fb0 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:52:35 +0800 Subject: [PATCH 080/115] Update StringToQueueConverterTest.java --- .../convert/multiple/StringToQueueConverterTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToQueueConverterTest.java b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToQueueConverterTest.java index 48eec34b0..d1fc9c4b3 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToQueueConverterTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToQueueConverterTest.java @@ -37,7 +37,7 @@ import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.TransferQueue; -import static java.util.Arrays.asList; +import static io.microsphere.collection.Lists.ofList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; @@ -88,7 +88,7 @@ public void testAccept() { @Test public void testConvert() { - Queue values = new ArrayDeque(asList(1.0, 2.0, 3.0)); + Queue values = new ArrayDeque(ofList(1.0, 2.0, 3.0)); Queue result = (Queue) converter.convert("1.0,2.0,3.0", Queue.class, Double.class); From 5b4c96b106e13c4d8d4e769093e6d97eaa7ab5c2 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:52:37 +0800 Subject: [PATCH 081/115] Update StringToSetConverterTest.java --- .../convert/multiple/StringToSetConverterTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToSetConverterTest.java b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToSetConverterTest.java index be1f6b42f..7e87d3a72 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToSetConverterTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToSetConverterTest.java @@ -37,7 +37,7 @@ import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.TransferQueue; -import static java.util.Arrays.asList; +import static io.microsphere.collection.Lists.ofList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; @@ -87,7 +87,7 @@ public void testAccept() { @Test public void testConvert() { - Set values = new HashSet(asList(1.0, 2.0, 3.0)); + Set values = new HashSet(ofList(1.0, 2.0, 3.0)); Set result = (Set) converter.convert("1.0,2.0,3.0", Queue.class, Double.class); From ec390f9eb62d09d99bcaf1daaeb8f596326c752e Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:52:39 +0800 Subject: [PATCH 082/115] Update StringToSortedSetConverterTest.java --- .../convert/multiple/StringToSortedSetConverterTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToSortedSetConverterTest.java b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToSortedSetConverterTest.java index 98a5e6969..bca1e63cc 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToSortedSetConverterTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToSortedSetConverterTest.java @@ -36,7 +36,7 @@ import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.TransferQueue; -import static java.util.Arrays.asList; +import static io.microsphere.collection.Lists.ofList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; @@ -87,13 +87,13 @@ public void testAccept() { @Test public void testConvert() { - Set values = new TreeSet(asList(1, 2, 3)); + Set values = new TreeSet(ofList(1, 2, 3)); SortedSet result = (SortedSet) converter.convert("1,2,3", List.class, Integer.class); assertTrue(CollectionUtils.equals(values, result)); - values = new TreeSet(asList("123")); + values = new TreeSet(ofList("123")); result = (SortedSet) converter.convert("123", NavigableSet.class, String.class); From 4721253897e6ca8a958adad634c56b10ca9533d0 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:52:41 +0800 Subject: [PATCH 083/115] Update StringToTransferQueueConverterTest.java --- .../multiple/StringToTransferQueueConverterTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToTransferQueueConverterTest.java b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToTransferQueueConverterTest.java index 105323e8a..5d556703d 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToTransferQueueConverterTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/convert/multiple/StringToTransferQueueConverterTest.java @@ -37,7 +37,7 @@ import java.util.concurrent.LinkedTransferQueue; import java.util.concurrent.TransferQueue; -import static java.util.Arrays.asList; +import static io.microsphere.collection.Lists.ofList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; @@ -88,7 +88,7 @@ public void testAccept() { @Test public void testConvert() { - TransferQueue values = new LinkedTransferQueue(asList(1, 2, 3)); + TransferQueue values = new LinkedTransferQueue(ofList(1, 2, 3)); TransferQueue result = (TransferQueue) converter.convert("1,2,3", List.class, Integer.class); @@ -96,7 +96,7 @@ public void testConvert() { values.clear(); - values.addAll(asList("123")); + values.addAll(ofList("123")); result = (TransferQueue) converter.convert("123", NavigableSet.class, String.class); From e57f11a2c960d1396a5ee39ce8d18ed6ff1f32c8 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:52:43 +0800 Subject: [PATCH 084/115] Update DirectEventDispatcherTest.java --- .../event/DirectEventDispatcherTest.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/event/DirectEventDispatcherTest.java b/microsphere-java-core/src/test/java/io/microsphere/event/DirectEventDispatcherTest.java index a13102076..811986b7d 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/event/DirectEventDispatcherTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/event/DirectEventDispatcherTest.java @@ -19,7 +19,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static java.util.Arrays.asList; +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.assertNotNull; @@ -61,15 +61,15 @@ public void testSingleListener() { // add two listeners dispatcher.addEventListener(echoEventListener); dispatcher.addEventListener(echoEventListener2); - assertEquals(asList(echoEventListener2, echoEventListener), dispatcher.getAllEventListeners()); + assertEquals(ofList(echoEventListener2, echoEventListener), dispatcher.getAllEventListeners()); // add a duplicated listener dispatcher.addEventListener(echoEventListener); - assertEquals(asList(echoEventListener2, echoEventListener), dispatcher.getAllEventListeners()); + assertEquals(ofList(echoEventListener2, echoEventListener), dispatcher.getAllEventListeners()); // remove dispatcher.removeEventListener(echoEventListener); - assertEquals(asList(echoEventListener2), dispatcher.getAllEventListeners()); + assertEquals(ofList(echoEventListener2), dispatcher.getAllEventListeners()); dispatcher.removeEventListener(echoEventListener2); assertEquals(emptyList(), dispatcher.getAllEventListeners()); @@ -80,7 +80,7 @@ public void testMultipleListeners() { // add two listeners dispatcher.addEventListeners(echoEventListener, echoEventListener2); - assertEquals(asList(echoEventListener2, echoEventListener), dispatcher.getAllEventListeners()); + assertEquals(ofList(echoEventListener2, echoEventListener), dispatcher.getAllEventListeners()); // remove all listeners dispatcher.removeAllEventListeners(); @@ -88,16 +88,16 @@ public void testMultipleListeners() { // add the duplicated listeners dispatcher.addEventListeners(echoEventListener, echoEventListener, echoEventListener2); - assertEquals(asList(echoEventListener2, echoEventListener), dispatcher.getAllEventListeners()); + assertEquals(ofList(echoEventListener2, echoEventListener), dispatcher.getAllEventListeners()); // remove all listeners dispatcher.removeAllEventListeners(); assertEquals(emptyList(), dispatcher.getAllEventListeners()); - dispatcher.addEventListeners(asList(echoEventListener, echoEventListener, echoEventListener2)); - assertEquals(asList(echoEventListener2, echoEventListener), dispatcher.getAllEventListeners()); + dispatcher.addEventListeners(ofList(echoEventListener, echoEventListener, echoEventListener2)); + assertEquals(ofList(echoEventListener2, echoEventListener), dispatcher.getAllEventListeners()); - dispatcher.removeEventListeners(asList(echoEventListener, echoEventListener, echoEventListener2)); + dispatcher.removeEventListeners(ofList(echoEventListener, echoEventListener, echoEventListener2)); assertEquals(emptyList(), dispatcher.getAllEventListeners()); } From 044cf3f024d4c86f491edcb67f69db7c8a18d23d Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:52:47 +0800 Subject: [PATCH 085/115] Update FileWatchServiceTest.java --- .../src/test/java/io/microsphere/io/FileWatchServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/io/FileWatchServiceTest.java b/microsphere-java-core/src/test/java/io/microsphere/io/FileWatchServiceTest.java index c2d074383..5e417aa4a 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/io/FileWatchServiceTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/io/FileWatchServiceTest.java @@ -7,7 +7,7 @@ import java.io.File; -import static io.microsphere.collection.ListUtils.ofList; +import static io.microsphere.collection.Lists.ofList; /** * {@link FileWatchService} Test From 4afd008d24d959953eea89125d0767e415df4d6f Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:52:50 +0800 Subject: [PATCH 086/115] Update StreamsTest.java --- .../io/microsphere/lang/function/StreamsTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/lang/function/StreamsTest.java b/microsphere-java-core/src/test/java/io/microsphere/lang/function/StreamsTest.java index 2951715d1..cec5283ca 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/lang/function/StreamsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/lang/function/StreamsTest.java @@ -24,10 +24,10 @@ import java.util.Set; import java.util.stream.Stream; +import static io.microsphere.collection.Lists.ofList; import static io.microsphere.lang.function.Streams.filterList; import static io.microsphere.lang.function.Streams.filterSet; import static io.microsphere.lang.function.Streams.filterStream; -import static java.util.Arrays.asList; import static java.util.stream.Collectors.toList; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -40,19 +40,19 @@ public class StreamsTest { @Test public void testFilterStream() { - Stream stream = filterStream(asList(1, 2, 3, 4, 5), i -> i % 2 == 0); - assertEquals(asList(2, 4), stream.collect(toList())); + Stream stream = filterStream(ofList(1, 2, 3, 4, 5), i -> i % 2 == 0); + assertEquals(ofList(2, 4), stream.collect(toList())); } @Test public void testFilterList() { - List list = filterList(asList(1, 2, 3, 4, 5), i -> i % 2 == 0); - assertEquals(asList(2, 4), list); + List list = filterList(ofList(1, 2, 3, 4, 5), i -> i % 2 == 0); + assertEquals(ofList(2, 4), list); } @Test public void testFilterSet() { - Set set = filterSet(asList(1, 2, 3, 4, 5), i -> i % 2 == 0); - assertEquals(new LinkedHashSet<>(asList(2, 4)), set); + Set set = filterSet(ofList(1, 2, 3, 4, 5), i -> i % 2 == 0); + assertEquals(new LinkedHashSet<>(ofList(2, 4)), set); } } From 9bf3234af0ef7745072a2112b306476575f25cdf Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 02:52:53 +0800 Subject: [PATCH 087/115] Update ExtendableProtocolURLStreamHandlerTest.java --- .../microsphere/net/ExtendableProtocolURLStreamHandlerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java b/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java index 5cd7f8869..5f7e6a49c 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/net/ExtendableProtocolURLStreamHandlerTest.java @@ -26,7 +26,7 @@ import java.util.List; import static io.microsphere.collection.ListUtils.newLinkedList; -import static io.microsphere.collection.ListUtils.ofList; +import static io.microsphere.collection.Lists.ofList; import static io.microsphere.collection.SetUtils.ofSet; import static io.microsphere.net.ExtendableProtocolURLStreamHandler.appendHandlePackage; import static io.microsphere.net.ExtendableProtocolURLStreamHandler.assertClassName; From 49eb46b9fd05c12830766652d434f17e206e8266 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 03:02:49 +0800 Subject: [PATCH 088/115] Create ListsBenchmark.java --- .../collection/ListsBenchmark.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 microsphere-java-core/src/test/java/io/microsphere/collection/ListsBenchmark.java diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/ListsBenchmark.java b/microsphere-java-core/src/test/java/io/microsphere/collection/ListsBenchmark.java new file mode 100644 index 000000000..c41f7b88b --- /dev/null +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/ListsBenchmark.java @@ -0,0 +1,58 @@ +/* + * 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.collection; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Warmup; + +import java.util.concurrent.TimeUnit; + +import static io.microsphere.collection.Lists.ofList; +import static io.microsphere.collection.ListUtils.of; + +/** + * {@link Lists} Benchmark + * + * @author Mercy + * @see Lists + * @since 1.0.0 + */ +@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) +@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS) +@Fork(3) +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +@State(Scope.Thread) +public class ListsBenchmark { + + @Benchmark + public void testOfList() { + ofList("a","b","c"); + } + + @Benchmark + public void testOf() { + of("a", "b", "c"); + } +} From 2288365ba7db8d44fa15b6351f74aa8bc3df72ff Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 03:22:15 +0800 Subject: [PATCH 089/115] Update MethodUtils.java --- .../src/main/java/io/microsphere/reflect/MethodUtils.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java index 4178bd0ae..eb6a7ef77 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java @@ -36,6 +36,7 @@ import java.util.concurrent.ConcurrentMap; import java.util.function.Predicate; +import static io.microsphere.collection.ListUtils.of; import static io.microsphere.collection.Lists.ofList; import static io.microsphere.constants.SymbolConstants.COMMA_CHAR; import static io.microsphere.constants.SymbolConstants.LEFT_PARENTHESIS_CHAR; @@ -73,12 +74,12 @@ public abstract class MethodUtils extends BaseUtils { /** * The public methods of {@link Object} */ - public final static List OBJECT_PUBLIC_METHODS = ofList(Object.class.getMethods()); + public final static List OBJECT_PUBLIC_METHODS = of(Object.class.getMethods()); /** * The declared methods of {@link Object} */ - public final static List OBJECT_DECLARED_METHODS = ofList(Object.class.getDeclaredMethods()); + public final static List OBJECT_DECLARED_METHODS = of(Object.class.getDeclaredMethods()); /** * The {@link Predicate} reference to {@link MethodUtils#isObjectMethod(Method)} From d180db10d3f7a7798cbf1c8cd5d6d38d0e7067de Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 03:22:54 +0800 Subject: [PATCH 090/115] Update MethodUtils.java --- .../src/main/java/io/microsphere/reflect/MethodUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java index eb6a7ef77..1f8f92d3c 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java @@ -37,7 +37,6 @@ import java.util.function.Predicate; import static io.microsphere.collection.ListUtils.of; -import static io.microsphere.collection.Lists.ofList; import static io.microsphere.constants.SymbolConstants.COMMA_CHAR; import static io.microsphere.constants.SymbolConstants.LEFT_PARENTHESIS_CHAR; import static io.microsphere.constants.SymbolConstants.RIGHT_PARENTHESIS_CHAR; From 0b6b40e7d8812adb49d13a0ed5f8dfb786905bc5 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:07:50 +0800 Subject: [PATCH 091/115] Update MapUtils.java --- .../io/microsphere/collection/MapUtils.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java index 27359fe28..73d7a9699 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java @@ -35,6 +35,7 @@ import java.util.function.Function; import static io.microsphere.collection.CollectionUtils.size; +import static io.microsphere.util.ArrayUtils.length; import static java.util.Collections.emptyMap; import static java.util.Collections.singletonMap; import static java.util.Collections.unmodifiableMap; @@ -56,7 +57,7 @@ public abstract class MapUtils extends BaseUtils { /** * The fixed load factor for {@link HashMap} or {@link Hashtable} = 1.00 */ - public static final float FIXED_LOAD_FACTOR = 1.00f; + protected static final float FIXED_LOAD_FACTOR = 1.00f; public static boolean isEmpty(Map map) { return map == null || map.isEmpty(); @@ -91,8 +92,12 @@ public static Map of(Object... values) { } public static Map ofMap(Object... keyValuePairs) { - int length = keyValuePairs.length; - Map map = new HashMap(length / 2, FIXED_LOAD_FACTOR); + int length = length(keyValuePairs); + if (length < 1) { + return emptyMap(); + } + int size = length / 2; + Map map = newFixedLinkedHashMap(size); for (int i = 0; i < length; ) { map.put(keyValuePairs[i++], keyValuePairs[i++]); } @@ -196,6 +201,14 @@ public static Map shallowCloneMap(@Nonnull Map source) { } } + public static Map newFixedHashMap(int size) { + return newHashMap(size, FIXED_LOAD_FACTOR); + } + + public static Map newFixedLinkedHashMap(int size) { + return newLinkedHashMap(size, FIXED_LOAD_FACTOR); + } + public static Map toFixedMap(Collection values, Function> entryMapper) { int size = size(values); @@ -203,7 +216,7 @@ public static Map toFixedMap(Collection values, return emptyMap(); } - Map fixedMap = newHashMap(size, FIXED_LOAD_FACTOR); + Map fixedMap = newFixedLinkedHashMap(size); for (E value : values) { Map.Entry entry = entryMapper.apply(value); From 8aadebca15a16400252689526ce55dda1fb67fbc Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:07:55 +0800 Subject: [PATCH 092/115] Update URLUtils.java --- .../src/main/java/io/microsphere/net/URLUtils.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java index 3eb3198d9..0b2dd3510 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/URLUtils.java @@ -19,7 +19,6 @@ import java.net.URLEncoder; import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; -import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -30,7 +29,7 @@ import static io.microsphere.collection.CollectionUtils.size; import static io.microsphere.collection.Lists.ofList; -import static io.microsphere.collection.MapUtils.FIXED_LOAD_FACTOR; +import static io.microsphere.collection.MapUtils.newFixedLinkedHashMap; import static io.microsphere.constants.PathConstants.BACK_SLASH; import static io.microsphere.constants.PathConstants.DOUBLE_SLASH; import static io.microsphere.constants.PathConstants.SLASH; @@ -813,7 +812,7 @@ protected static Map> resolveParameters(String paramsString return emptyMap(); } - Map> parametersMap = new LinkedHashMap(paramsLen, FIXED_LOAD_FACTOR); + Map> parametersMap = newFixedLinkedHashMap(paramsLen); for (int i = 0; i < paramsLen; i++) { String param = params[i]; From c460c997fb0ecc5d0c4197014af141136224d811 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:08:02 +0800 Subject: [PATCH 093/115] Update MapUtilsTest.java --- .../microsphere/collection/MapUtilsTest.java | 115 +++++++++++++++--- 1 file changed, 96 insertions(+), 19 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java index 552cbf1bb..25c817de2 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java @@ -16,6 +16,7 @@ */ package io.microsphere.collection; +import io.microsphere.reflect.FieldUtils; import org.junit.jupiter.api.Test; import java.util.Collections; @@ -26,20 +27,26 @@ import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentSkipListMap; +import java.util.function.Function; import static io.microsphere.collection.Lists.ofList; import static io.microsphere.collection.MapUtils.FIXED_LOAD_FACTOR; +import static io.microsphere.collection.MapUtils.MIN_LOAD_FACTOR; import static io.microsphere.collection.MapUtils.immutableEntry; import static io.microsphere.collection.MapUtils.isEmpty; import static io.microsphere.collection.MapUtils.isNotEmpty; import static io.microsphere.collection.MapUtils.newConcurrentHashMap; +import static io.microsphere.collection.MapUtils.newFixedHashMap; import static io.microsphere.collection.MapUtils.newHashMap; import static io.microsphere.collection.MapUtils.newLinkedHashMap; import static io.microsphere.collection.MapUtils.newTreeMap; import static io.microsphere.collection.MapUtils.of; import static io.microsphere.collection.MapUtils.ofEntry; +import static io.microsphere.collection.MapUtils.ofMap; import static io.microsphere.collection.MapUtils.shallowCloneMap; import static io.microsphere.collection.MapUtils.toFixedMap; +import static io.microsphere.reflect.FieldUtils.getFieldValue; +import static java.lang.Integer.valueOf; import static java.util.Collections.emptyMap; import static java.util.Collections.unmodifiableMap; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -59,6 +66,7 @@ public class MapUtilsTest { @Test public void testConstants() { + assertEquals(Float.MIN_VALUE, MIN_LOAD_FACTOR); assertEquals(1.f, FIXED_LOAD_FACTOR); } @@ -83,31 +91,58 @@ public void testIsNotEmpty() { } @Test - public void testOf() { + public void testOf1() { Map map = of("A", 1); + assertEquals(1, map.size()); assertEquals(1, map.get("A")); assertNull(map.get("B")); + } - map = of("B", 2, "C", 3); - assertEquals(3, map.get("C")); + @Test + public void testOf2() { + Map map = of("A", 1, "B", 2); + assertEquals(2, map.size()); + assertEquals(1, map.get("A")); assertEquals(2, map.get("B")); - assertNull(map.get("A")); - + assertNull(map.get("C")); + } - map = of("B", 2, "C", 3, "D", 4); - assertEquals(4, map.get("D")); - assertEquals(3, map.get("C")); + @Test + public void testOf3() { + Map map = of("A", 1, "B", 2, "C", 3); + assertEquals(3, map.size()); + assertEquals(1, map.get("A")); assertEquals(2, map.get("B")); - assertNull(map.get("A")); + assertEquals(3, map.get("C")); + assertNull(map.get("D")); + } - map = of("B", 2, "C", 3, "D", 4, "E", 5); - assertEquals(5, map.get("E")); - assertEquals(4, map.get("D")); + @Test + public void testOf4() { + Map map = of("A", 1, "B", 2, "C", 3, "D", 4); + assertEquals(4, map.size()); + assertEquals(1, map.get("A")); + assertEquals(2, map.get("B")); assertEquals(3, map.get("C")); + assertEquals(4, map.get("D")); + assertNull(map.get("E")); + } + + @Test + public void testOf5() { + Map map = of("A", 1, "B", 2, "C", 3, "D", 4, "E", 5); + assertEquals(5, map.size()); + assertEquals(1, map.get("A")); assertEquals(2, map.get("B")); - assertNull(map.get("A")); + assertEquals(3, map.get("C")); + assertEquals(4, map.get("D")); + assertEquals(5, map.get("E")); + assertNull(map.get("F")); + } - map = of("B", 2, "C", 3, "D", 4, "E", 5, "F", 6); + @Test + public void testOf() { + Map map = of("B", 2, "C", 3, "D", 4, "E", 5, "F", 6); assertEquals(6, map.get("F")); assertEquals(5, map.get("E")); assertEquals(4, map.get("D")); @@ -125,6 +160,15 @@ public void testOf() { assertNull(map.get("A")); } + @Test + public void testOfMap() { + Map map = ofMap("A", 1); + assertEquals(1, map.size()); + assertEquals(1, map.get("A")); + assertNull(map.get("B")); + } + + @Test public void testOfEntry() { Map.Entry entry = ofEntry("A", 1); @@ -144,27 +188,46 @@ public void testImmutableEntry() { } @Test - public void testNew() { + public void testNewHashMap() { assertNewMap(HashMap.class, newHashMap()); assertNewMap(HashMap.class, newHashMap(2)); assertNewMap(HashMap.class, newHashMap(2, 0.75f)); assertNewMap(HashMap.class, newHashMap(emptyMap())); + } + @Test + public void testNewLinkedHashMap() { assertNewMap(LinkedHashMap.class, newLinkedHashMap()); assertNewMap(LinkedHashMap.class, newLinkedHashMap(2)); assertNewMap(LinkedHashMap.class, newLinkedHashMap(2, 0.75f)); assertNewMap(LinkedHashMap.class, newLinkedHashMap(2, 0.75f, true)); assertNewMap(LinkedHashMap.class, newLinkedHashMap(emptyMap())); + } + + @Test + public void testNewTreeMap() { + assertNewMap(TreeMap.class, newTreeMap()); + assertNewMap(TreeMap.class, newTreeMap(Integer::compare)); + assertNewMap(TreeMap.class, newTreeMap(emptyMap())); + assertNewMap(TreeMap.class, newTreeMap(new TreeMap<>())); + } + @Test + public void testNewConcurrentHashMap() { assertNewMap(TreeMap.class, newTreeMap()); assertNewMap(TreeMap.class, newTreeMap(Integer::compare)); assertNewMap(TreeMap.class, newTreeMap(emptyMap())); assertNewMap(TreeMap.class, newTreeMap(new TreeMap<>())); + } - assertNewMap(ConcurrentHashMap.class, newConcurrentHashMap()); - assertNewMap(ConcurrentHashMap.class, newConcurrentHashMap(2)); - assertNewMap(ConcurrentHashMap.class, newConcurrentHashMap(2, 0.75f)); - assertNewMap(ConcurrentHashMap.class, newConcurrentHashMap(emptyMap())); + @Test + public void testNewFixedHashMap() { + assertNewFixedMap(8, MapUtils::newFixedHashMap); + } + + @Test + public void testNewFixedLinkedHashMap() { + assertNewFixedMap(8, MapUtils::newFixedLinkedHashMap); } @Test @@ -209,6 +272,20 @@ public void testShallowCloneMap() { assertEquals(map, cloneMap); } + private void assertNewFixedMap(int size, Function> fixedMapCreator) { + Map map = fixedMapCreator.apply(size); + map.put("A", 1); + map.put("B", 2); + map.put("C", 3); + map.put("D", 4); + map.put("E", 5); + map.put("F", 6); + map.put("G", 7); + map.put("H", 8); + assertEquals(size, map.size()); + assertEquals(valueOf(size), getFieldValue(map, "threshold")); + } + private void assertNewMap(Class mapClass, Map map) { assertEquals(mapClass, map.getClass()); assertEquals(0, map.size()); From fbe8ad9fb688f7b52d58ee14dbc0984fa7ea708c Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:08:50 +0800 Subject: [PATCH 094/115] Update MapUtilsTest.java --- .../src/test/java/io/microsphere/collection/MapUtilsTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java index 25c817de2..9d9a13cae 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java @@ -16,7 +16,6 @@ */ package io.microsphere.collection; -import io.microsphere.reflect.FieldUtils; import org.junit.jupiter.api.Test; import java.util.Collections; @@ -25,7 +24,6 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.TreeMap; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentSkipListMap; import java.util.function.Function; @@ -36,7 +34,6 @@ import static io.microsphere.collection.MapUtils.isEmpty; import static io.microsphere.collection.MapUtils.isNotEmpty; import static io.microsphere.collection.MapUtils.newConcurrentHashMap; -import static io.microsphere.collection.MapUtils.newFixedHashMap; import static io.microsphere.collection.MapUtils.newHashMap; import static io.microsphere.collection.MapUtils.newLinkedHashMap; import static io.microsphere.collection.MapUtils.newTreeMap; From 51e79dce30cf85f03320f6c47db9ef7989cb6c12 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:14:08 +0800 Subject: [PATCH 095/115] Update MapUtils.java --- .../src/main/java/io/microsphere/collection/MapUtils.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java index 73d7a9699..0a825d794 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/MapUtils.java @@ -68,7 +68,7 @@ public static boolean isNotEmpty(Map map) { } public static Map of(K key, V value) { - return singletonMap(key, value); + return ofMap(key, value); } public static Map of(K key1, V value1, K key2, V value2) { @@ -91,6 +91,10 @@ public static Map of(Object... values) { return ofMap(values); } + public static Map ofMap(K key, V value) { + return singletonMap(key, value); + } + public static Map ofMap(Object... keyValuePairs) { int length = length(keyValuePairs); if (length < 1) { From c2ca5d71f5348608966dc7fceead3dca6297a39e Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:14:15 +0800 Subject: [PATCH 096/115] Update MapUtilsTest.java --- .../microsphere/collection/MapUtilsTest.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java index 9d9a13cae..78c2e33d4 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/MapUtilsTest.java @@ -43,12 +43,14 @@ import static io.microsphere.collection.MapUtils.shallowCloneMap; import static io.microsphere.collection.MapUtils.toFixedMap; import static io.microsphere.reflect.FieldUtils.getFieldValue; +import static io.microsphere.util.ArrayUtils.EMPTY_OBJECT_ARRAY; import static java.lang.Integer.valueOf; import static java.util.Collections.emptyMap; import static java.util.Collections.unmodifiableMap; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -158,13 +160,36 @@ public void testOf() { } @Test - public void testOfMap() { + public void testOfMap1() { Map map = ofMap("A", 1); assertEquals(1, map.size()); assertEquals(1, map.get("A")); assertNull(map.get("B")); } + @Test + public void testOfMap() { + Map map = ofMap("A", 1, "C", 3); + assertEquals(2, map.size()); + assertEquals(1, map.get("A")); + assertNull(map.get("B")); + assertEquals(3, map.get("C")); + } + + @Test + public void testOfMapOnEmptyArray() { + Map map = ofMap(EMPTY_OBJECT_ARRAY); + assertTrue(map.isEmpty()); + assertSame(emptyMap(), map); + } + + @Test + public void testOfMapOnNull() { + Map map = ofMap(null); + assertTrue(map.isEmpty()); + assertSame(emptyMap(), map); + } + @Test public void testOfEntry() { From 2ebf03e3126ad97fb46e2883df5f10b1d82f9169 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:15:40 +0800 Subject: [PATCH 097/115] Update ArrayUtils.java --- .../src/main/java/io/microsphere/util/ArrayUtils.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/ArrayUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/ArrayUtils.java index c98bc56ea..640effb3d 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/ArrayUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/ArrayUtils.java @@ -141,6 +141,10 @@ public static T[] of(T... values) { return values; } + public static T[] ofArray(T... values) { + return of(values); + } + public static int length(T[] values) { return values == null ? 0 : values.length; } From f98e8f974a01bfa5e7ac415cdf3944bda6ec77cb Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:24:41 +0800 Subject: [PATCH 098/115] Update ArrayUtils.java --- .../src/main/java/io/microsphere/util/ArrayUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/ArrayUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/ArrayUtils.java index 640effb3d..7e543e9b9 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/ArrayUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/ArrayUtils.java @@ -138,11 +138,11 @@ public abstract class ArrayUtils extends BaseUtils { public static final Character[] EMPTY_CHARACTER_OBJECT_ARRAY = new Character[0]; public static T[] of(T... values) { - return values; + return ofArray(values); } public static T[] ofArray(T... values) { - return of(values); + return values; } public static int length(T[] values) { From d4e0ca80cae2f36a6be86737bfc8cb59d0948373 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:24:55 +0800 Subject: [PATCH 099/115] Update ArrayUtilsTest.java --- .../io/microsphere/util/ArrayUtilsTest.java | 86 ++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/util/ArrayUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/util/ArrayUtilsTest.java index dd8998314..f65840f6c 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/util/ArrayUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/util/ArrayUtilsTest.java @@ -30,11 +30,17 @@ import static io.microsphere.util.ArrayUtils.EMPTY_SHORT_OBJECT_ARRAY; import static io.microsphere.util.ArrayUtils.EMPTY_STRING_ARRAY; import static io.microsphere.util.ArrayUtils.combine; +import static io.microsphere.util.ArrayUtils.isNotEmpty; import static io.microsphere.util.ArrayUtils.length; import static io.microsphere.util.ArrayUtils.of; +import static io.microsphere.util.ArrayUtils.ofArray; +import static io.microsphere.util.ArrayUtils.size; import static io.microsphere.util.ClassUtils.getTopComponentType; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.springframework.util.ObjectUtils.isEmpty; /** * {@link ArrayUtils} Test @@ -59,6 +65,82 @@ public void testConstants() { assertEmptyArray(EMPTY_CHARACTER_OBJECT_ARRAY, Character.class); } + @Test + public void tesOf() { + assertArrayEquals(of("A"), array("A")); + assertArrayEquals(of("A", "B"), array("A", "B")); + assertArrayEquals(of("A", "B", "C"), array("A", "B", "C")); + } + + @Test + public void testOfArray() { + assertArrayEquals(of("A"), ofArray("A")); + assertArrayEquals(of("A", "B"), ofArray("A", "B")); + assertArrayEquals(of("A", "B", "C"), ofArray("A", "B", "C")); + } + + @Test + public void testLength() { + assertEquals(1, length(ofArray("A"))); + assertEquals(2, length(ofArray("A", "B"))); + } + + @Test + public void testLengthOnNull() { + assertEquals(0, length(ofArray(null))); + } + + @Test + public void testLengthOnEmptyArray() { + assertEquals(0, length(ofArray(EMPTY_OBJECT_ARRAY))); + } + + @Test + public void testSize() { + assertEquals(1, size(ofArray("A"))); + assertEquals(2, size(ofArray("A", "B"))); + } + + @Test + public void testSizeOnNull() { + assertEquals(0, size(ofArray(null))); + } + + @Test + public void testSizeOnEmptyArray() { + assertEquals(0, size(ofArray(EMPTY_OBJECT_ARRAY))); + } + + @Test + public void testIsEmpty() { + assertFalse(isEmpty(ofArray("A"))); + } + + @Test + public void testIsEmptyOnEmptyArray() { + assertTrue(isEmpty(EMPTY_OBJECT_ARRAY)); + } + + @Test + public void testIsEmptyOnNull() { + assertTrue(isEmpty(null)); + } + + @Test + public void testIsNotEmpty() { + assertTrue(isNotEmpty(ofArray("A"))); + } + + @Test + public void testIsNotEmptyOnEmptyArray() { + assertFalse(isNotEmpty(EMPTY_OBJECT_ARRAY)); + } + + @Test + public void testIsNotEmptyOnNull() { + assertFalse(isNotEmpty(null)); + } + @Test public void testCombine() { assertArrayEquals(of("A", "B"), combine("A", of("B"))); @@ -78,8 +160,10 @@ public void testCombine() { combine(of("A", "B", "C"), of("D"))); assertArrayEquals(of("A", "B", "C", "D"), combine(of("A", "B", "C", "D"))); + } - + public static T[] array(T... values) { + return values; } private void assertEmptyArray(E[] array, Class expectedComponentType) { From 635c5deb05677dca35347549ef343afcd806af18 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:26:08 +0800 Subject: [PATCH 100/115] Update MultipleType.java --- .../src/main/java/io/microsphere/reflect/MultipleType.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/reflect/MultipleType.java b/microsphere-java-core/src/main/java/io/microsphere/reflect/MultipleType.java index db73a99ed..949d752d7 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/reflect/MultipleType.java +++ b/microsphere-java-core/src/main/java/io/microsphere/reflect/MultipleType.java @@ -16,13 +16,12 @@ */ package io.microsphere.reflect; -import io.microsphere.util.ArrayUtils; - import java.lang.reflect.Type; import java.util.Arrays; import java.util.Objects; import static io.microsphere.util.ArrayUtils.combineArray; +import static io.microsphere.util.ArrayUtils.ofArray; /** * Multiple {@link Type} @@ -61,7 +60,7 @@ public static MultipleType of(Type one, Type two) { } public static MultipleType of(Type one, Type two, Type... others) { - Type[] oneAndTwo = ArrayUtils.of(one, two); + Type[] oneAndTwo = ofArray(one, two); Type[] types = combineArray(oneAndTwo, others); return new MultipleType(types); } From fd32aed990fd8a524defeebb084b209eac2cc6e6 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:26:16 +0800 Subject: [PATCH 101/115] Update ListsBenchmark.java --- .../src/test/java/io/microsphere/collection/ListsBenchmark.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/ListsBenchmark.java b/microsphere-java-core/src/test/java/io/microsphere/collection/ListsBenchmark.java index c41f7b88b..e94057b7d 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/ListsBenchmark.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/ListsBenchmark.java @@ -28,8 +28,8 @@ import java.util.concurrent.TimeUnit; -import static io.microsphere.collection.Lists.ofList; import static io.microsphere.collection.ListUtils.of; +import static io.microsphere.collection.Lists.ofList; /** * {@link Lists} Benchmark From b3b6dd90e956e46cc492b00cc6fe3deae28583c8 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:26:25 +0800 Subject: [PATCH 102/115] Update DelegatingBlockingQueueTest.java --- .../microsphere/concurrent/DelegatingBlockingQueueTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/concurrent/DelegatingBlockingQueueTest.java b/microsphere-java-core/src/test/java/io/microsphere/concurrent/DelegatingBlockingQueueTest.java index 73d109b0a..e16755477 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/concurrent/DelegatingBlockingQueueTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/concurrent/DelegatingBlockingQueueTest.java @@ -1,6 +1,5 @@ package io.microsphere.concurrent; -import io.microsphere.util.ArrayUtils; import org.junit.jupiter.api.Test; import java.util.Iterator; @@ -14,6 +13,7 @@ import static io.microsphere.collection.ListUtils.newLinkedList; import static io.microsphere.collection.Lists.ofList; import static io.microsphere.collection.QueueUtils.emptyQueue; +import static io.microsphere.util.ArrayUtils.ofArray; import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -49,11 +49,11 @@ public void test() throws Throwable { // test toArray() Object[] array = queue.toArray(); - assertArrayEquals(ArrayUtils.of(1), array); + assertArrayEquals(ofArray(1), array); // test toArray(Object[]) array = queue.toArray(new Object[1]); - assertArrayEquals(ArrayUtils.of(1), array); + assertArrayEquals(ofArray(1), array); // test contains assertTrue(queue.contains(1)); From 50c180057d42ce4616be63959d357412b2451d56 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:26:31 +0800 Subject: [PATCH 103/115] Update MethodDefinitionTest.java --- .../java/io/microsphere/reflect/MethodDefinitionTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/reflect/MethodDefinitionTest.java b/microsphere-java-core/src/test/java/io/microsphere/reflect/MethodDefinitionTest.java index dffcbb615..bb1bcd8db 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/reflect/MethodDefinitionTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/reflect/MethodDefinitionTest.java @@ -18,10 +18,10 @@ import io.microsphere.logging.Logger; import io.microsphere.logging.LoggerFactory; -import io.microsphere.util.ArrayUtils; import io.microsphere.util.Version; import org.junit.jupiter.api.Test; +import static io.microsphere.util.ArrayUtils.ofArray; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -47,7 +47,7 @@ public void test() { assertNull(md.getDeprecation()); assertEquals(MethodDefinitionTest.class, md.getResolvedClass()); assertEquals("log", md.getMethodName()); - assertArrayEquals(ArrayUtils.of(String.class), md.getParameterTypes()); + assertArrayEquals(ofArray(String.class), md.getParameterTypes()); assertTrue(md.isPresent()); assertNotNull(md.getMethod()); From 35113ce2811700af883191a736e782bc3d89568a Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:26:35 +0800 Subject: [PATCH 104/115] Update ResourceTypeTest.java --- .../test/java/io/microsphere/util/ResourceTypeTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/util/ResourceTypeTest.java b/microsphere-java-core/src/test/java/io/microsphere/util/ResourceTypeTest.java index 9074cc4b2..8964bc135 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/util/ResourceTypeTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/util/ResourceTypeTest.java @@ -21,7 +21,7 @@ import java.util.Map; import static io.microsphere.collection.MapUtils.ofMap; -import static io.microsphere.util.ArrayUtils.of; +import static io.microsphere.util.ArrayUtils.ofArray; import static io.microsphere.util.ClassLoaderUtils.ResourceType.CLASS; import static io.microsphere.util.ClassLoaderUtils.ResourceType.DEFAULT; import static io.microsphere.util.ClassLoaderUtils.ResourceType.PACKAGE; @@ -40,9 +40,9 @@ public class ResourceTypeTest { private static final Map resourceNamesMap = ofMap( - DEFAULT, of("///////META-INF//abc\\/def", "META-INF/abc/def"), - CLASS, of("java.lang.String.class", "java/lang/String.class"), - PACKAGE, of("java.lang", "java/lang/") + DEFAULT, ofArray("///////META-INF//abc\\/def", "META-INF/abc/def"), + CLASS, ofArray("java.lang.String.class", "java/lang/String.class"), + PACKAGE, ofArray("java.lang", "java/lang/") ); From d4b2ea1bd44d64f5e7d1858eda848efef6e991c6 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:26:39 +0800 Subject: [PATCH 105/115] Update PropertiesUtilsTest.java --- .../io/microsphere/collection/PropertiesUtilsTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/PropertiesUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/PropertiesUtilsTest.java index 89760481b..c0a8bbbf6 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/PropertiesUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/PropertiesUtilsTest.java @@ -20,7 +20,7 @@ import java.util.Map; -import static io.microsphere.collection.MapUtils.of; +import static io.microsphere.collection.MapUtils.ofMap; import static io.microsphere.collection.PropertiesUtils.flatProperties; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -34,9 +34,9 @@ public class PropertiesUtilsTest { @Test public void testFlatProperties() { - Map level3Properties = of("f", "F"); - Map level2Properties = of("c", "C", "d", level3Properties); - Map properties = of("a", "A", "b", level2Properties); + Map level3Properties = ofMap("f", "F"); + Map level2Properties = ofMap("c", "C", "d", level3Properties); + Map properties = ofMap("a", "A", "b", level2Properties); Map flattenProperties = flatProperties(properties); assertEquals("A", flattenProperties.get("a")); assertEquals("C", flattenProperties.get("b.c")); From 14ce00d33b13cc87273b84415c231e578e7cf6a2 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:26:43 +0800 Subject: [PATCH 106/115] Update ClassUtils.java --- .../java/io/microsphere/util/ClassUtils.java | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/ClassUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/ClassUtils.java index 1c683a933..7d26f3d7e 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/ClassUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/ClassUtils.java @@ -17,10 +17,8 @@ import java.lang.reflect.Modifier; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.ArrayList; import java.util.Arrays; import java.util.Date; -import java.util.HashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; @@ -33,10 +31,9 @@ import java.util.jar.JarEntry; import java.util.jar.JarFile; -import static io.microsphere.collection.Lists.ofList; +import static io.microsphere.collection.MapUtils.newFixedHashMap; import static io.microsphere.collection.MapUtils.ofMap; import static io.microsphere.collection.SetUtils.newLinkedHashSet; -import static io.microsphere.collection.SetUtils.of; import static io.microsphere.collection.SetUtils.ofSet; import static io.microsphere.constants.FileConstants.CLASS; import static io.microsphere.constants.FileConstants.CLASS_EXTENSION; @@ -124,7 +121,7 @@ public abstract class ClassUtils extends BaseUtils { * * @see javax.management.openmbean.SimpleType */ - public static final Set> SIMPLE_TYPES = of( + public static final Set> SIMPLE_TYPES = ofSet( Void.class, Boolean.class, Character.class, @@ -140,7 +137,7 @@ public abstract class ClassUtils extends BaseUtils { Date.class, Object.class); - public static final Set> PRIMITIVE_TYPES = of( + public static final Set> PRIMITIVE_TYPES = ofSet( Void.TYPE, Boolean.TYPE, Character.TYPE, @@ -152,6 +149,17 @@ public abstract class ClassUtils extends BaseUtils { Double.TYPE ); + public static final Set> PRIMITIVE_ARRAY_TYPES = ofSet( + boolean[].class, + char[].class, + byte[].class, + short[].class, + int[].class, + long[].class, + float[].class, + double[].class + ); + /** * A map with primitive type name as key and corresponding primitive type as * value, for example: "int" -> "int.class". @@ -204,16 +212,17 @@ public abstract class ClassUtils extends BaseUtils { } static { - Map> typeNamesMap = new HashMap<>(16); - List> primitiveTypeNames = new ArrayList<>(16); - primitiveTypeNames.addAll(ofList(boolean.class, byte.class, char.class, double.class, - float.class, int.class, long.class, short.class)); - primitiveTypeNames.addAll(ofList(boolean[].class, byte[].class, char[].class, double[].class, - float[].class, int[].class, long[].class, short[].class)); - for (Class primitiveTypeName : primitiveTypeNames) { - typeNamesMap.put(primitiveTypeName.getName(), primitiveTypeName); - } - PRIMITIVE_TYPE_NAME_MAP = unmodifiableMap(typeNamesMap); + Map> primitiveTypeNameMap = newFixedHashMap(17); + + PRIMITIVE_TYPES.forEach(type -> { + primitiveTypeNameMap.put(type.getName(), type); + }); + + PRIMITIVE_ARRAY_TYPES.forEach(type -> { + primitiveTypeNameMap.put(type.getName(), type); + }); + + PRIMITIVE_TYPE_NAME_MAP = unmodifiableMap(primitiveTypeNameMap); } /** From 02d5209f864b5e62433237a7b5e90e6638c99dc9 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:27:39 +0800 Subject: [PATCH 107/115] Update AssertTest.java --- .../src/test/java/io/microsphere/util/AssertTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/util/AssertTest.java b/microsphere-java-core/src/test/java/io/microsphere/util/AssertTest.java index 9814f0989..bbdc479de 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/util/AssertTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/util/AssertTest.java @@ -16,7 +16,6 @@ */ package io.microsphere.util; -import io.microsphere.collection.MapUtils; import org.junit.jupiter.api.Test; import java.util.Arrays; @@ -24,6 +23,7 @@ import java.util.Map; import java.util.function.Supplier; +import static io.microsphere.collection.MapUtils.ofMap; import static io.microsphere.util.Assert.assertNoNullElements; import static io.microsphere.util.Assert.assertNotEmpty; import static io.microsphere.util.Assert.assertNotNull; @@ -111,7 +111,7 @@ void testAssertCollectionNotEmpty() { @Test void testAssertMapNotEmpty() { - Map map = MapUtils.of("A", "1"); + Map map = ofMap("A", "1"); assertNotEmpty(map, "map"); assertNotEmpty(map, () -> "map"); assertNotEmpty(map, (Supplier) null); From b8f9013876f87eb8c7c5f943b38daaf2378bff63 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:28:06 +0800 Subject: [PATCH 108/115] Update SystemUtilsTest.java --- .../src/test/java/io/microsphere/util/SystemUtilsTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/util/SystemUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/util/SystemUtilsTest.java index 5a455b219..974b67b7a 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/util/SystemUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/util/SystemUtilsTest.java @@ -26,6 +26,7 @@ import java.util.Objects; import java.util.stream.Stream; +import static io.microsphere.collection.MapUtils.ofMap; import static io.microsphere.util.StringUtils.substringAfter; import static io.microsphere.util.SystemUtils.FILE_ENCODING; import static io.microsphere.util.SystemUtils.FILE_ENCODING_PROPERTY_KEY; @@ -106,7 +107,7 @@ public class SystemUtilsTest { private static final Field[] IS_JAVA_VERSION_FIELDS = findIsJavaVersionFields(); - private static final Map versionedClassNames = MapUtils.of( + private static final Map versionedClassNames = ofMap( 22, "java.lang.foreign.Arena", 21, "java.util.SequencedSet", 20, "java.lang.reflect.ClassFileFormatVersion", From f4c61b1c84eedd889c5719fe265ae9f5723ac40d Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:28:12 +0800 Subject: [PATCH 109/115] Update SystemUtilsTest.java --- .../src/test/java/io/microsphere/util/SystemUtilsTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/util/SystemUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/util/SystemUtilsTest.java index 974b67b7a..d7c633a59 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/util/SystemUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/util/SystemUtilsTest.java @@ -16,7 +16,6 @@ */ package io.microsphere.util; -import io.microsphere.collection.MapUtils; import io.microsphere.reflect.MemberUtils; import org.junit.jupiter.api.Test; From db550281499dc0ed2836299fc9999240fffa1946 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:30:48 +0800 Subject: [PATCH 110/115] Update SetUtils.java --- .../main/java/io/microsphere/collection/SetUtils.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java index ee3c56250..e7292f1ec 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java @@ -55,6 +55,17 @@ public static boolean isSet(@Nullable Iterable elements) { * @return read-only {@link Set} */ public static Set of(E... elements) { + return ofSet(elements); + } + + /** + * Convert to multiple elements to be {@link LinkedHashSet} + * + * @param elements one or more elements + * @param the type of elements + * @return read-only {@link Set} + */ + public static Set ofSet(E... elements) { int size = length(elements); if (size < 1) { return emptySet(); From 2640ee9f48a47a10ebf1e0e7073bb4ae56967716 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:32:55 +0800 Subject: [PATCH 111/115] Update SetUtils.java --- .../io/microsphere/collection/SetUtils.java | 29 ++----------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java b/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java index e7292f1ec..5b1656198 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/SetUtils.java @@ -55,7 +55,7 @@ public static boolean isSet(@Nullable Iterable elements) { * @return read-only {@link Set} */ public static Set of(E... elements) { - return ofSet(elements); + return ofSet(elements); } /** @@ -73,7 +73,7 @@ public static Set ofSet(E... elements) { return singleton(elements[0]); } - Set set = new LinkedHashSet<>(size); + Set set = new LinkedHashSet<>(size, FIXED_LOAD_FACTOR); for (int i = 0; i < size; i++) { set.add(elements[i]); @@ -119,31 +119,6 @@ public static Set ofSet(Iterable elements) { return unmodifiableSet(newLinkedHashSet(elements)); } - /** - * Convert to one or more elements to be a read-only {@link Set} - * - * @param one one element - * @param others others elements - * @param the type of elements - * @return read-only {@link Set} - */ - public static Set ofSet(E one, E... others) { - int othersSize = length(others); - if (othersSize < 1) { - return singleton(one); - } - - Set elements = new LinkedHashSet<>(othersSize + 1, FIXED_LOAD_FACTOR); - - elements.add(one); - - for (int i = 0; i < othersSize; i++) { - elements.add(others[i]); - } - - return unmodifiableSet(elements); - } - public static Set ofSet(Collection elements) { return ofSet(elements, null); } From 9fd8b3b9db74458dd97ff98fe146b142eda749d9 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:33:02 +0800 Subject: [PATCH 112/115] Update ClassPathUtils.java --- .../src/main/java/io/microsphere/util/ClassPathUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/util/ClassPathUtils.java b/microsphere-java-core/src/main/java/io/microsphere/util/ClassPathUtils.java index 7ca8258a0..dc4e444b0 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/util/ClassPathUtils.java +++ b/microsphere-java-core/src/main/java/io/microsphere/util/ClassPathUtils.java @@ -11,7 +11,7 @@ import java.security.ProtectionDomain; import java.util.Set; -import static io.microsphere.collection.SetUtils.of; +import static io.microsphere.collection.SetUtils.ofSet; import static io.microsphere.constants.SeparatorConstants.PATH_SEPARATOR; import static io.microsphere.management.JmxUtils.getRuntimeMXBean; import static io.microsphere.util.ClassLoaderUtils.getClassResource; @@ -49,7 +49,7 @@ private static Set initClassPaths() { private static Set resolveClassPaths(String classPath) { String[] classPathsArray = split(classPath, PATH_SEPARATOR); - return of(classPathsArray); + return ofSet(classPathsArray); } From 492f4589cf2e87c2618383b830255bc6b583f492 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:34:41 +0800 Subject: [PATCH 113/115] Update SetUtilsTest.java --- .../io/microsphere/collection/SetUtilsTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/SetUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/SetUtilsTest.java index a2491c95b..79509b099 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/SetUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/SetUtilsTest.java @@ -4,6 +4,7 @@ import java.util.Collection; import java.util.Enumeration; +import java.util.LinkedHashSet; import java.util.Set; import static io.microsphere.collection.CollectionUtils.toIterable; @@ -39,6 +40,22 @@ public void testIsSet() { assertFalse(isSet(emptyList())); } + @Test + public void testOfSet() { + Set set = ofSet(); + assertEquals(emptySet(), set); + + set = ofSet(((String[]) null)); + assertEquals(emptySet(), set); + + set = ofSet("A", "B", "C"); + Set expectedSet = new LinkedHashSet<>(); + expectedSet.add("A"); + expectedSet.add("B"); + expectedSet.add("C"); + assertEquals(expectedSet, set); + } + @Test public void testOf() { Set set = of(ELEMENTS); From a4a90ef309c56cdc9c87fe3c8521a3cd9656e2a0 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:35:07 +0800 Subject: [PATCH 114/115] Update ExtendableProtocolURLStreamHandler.java --- .../microsphere/net/ExtendableProtocolURLStreamHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java b/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java index 58a994d8a..5eb63c537 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java +++ b/microsphere-java-core/src/main/java/io/microsphere/net/ExtendableProtocolURLStreamHandler.java @@ -29,7 +29,7 @@ import java.util.Set; import java.util.function.Consumer; -import static io.microsphere.collection.SetUtils.of; +import static io.microsphere.collection.SetUtils.ofSet; import static io.microsphere.constants.SymbolConstants.COLON_CHAR; import static io.microsphere.constants.SymbolConstants.DOT_CHAR; import static io.microsphere.constants.SymbolConstants.QUERY_STRING; @@ -114,7 +114,7 @@ public ExtendableProtocolURLStreamHandler(String protocol) { public static Set getHandlePackages() { String value = getHandlePackagesPropertyValue(); String[] packages = split(value, HANDLER_PACKAGES_SEPARATOR_CHAR); - return of(packages); + return ofSet(packages); } /** From 74d809b625616c11c76fa6e02d4d7a5994438fc4 Mon Sep 17 00:00:00 2001 From: Mercy Ma Date: Sun, 9 Mar 2025 04:35:10 +0800 Subject: [PATCH 115/115] Update ClassLoaderUtilsTest.java --- .../microsphere/util/ClassLoaderUtilsTest.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/microsphere-java-core/src/test/java/io/microsphere/util/ClassLoaderUtilsTest.java b/microsphere-java-core/src/test/java/io/microsphere/util/ClassLoaderUtilsTest.java index 11754541c..3f77280b4 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/util/ClassLoaderUtilsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/util/ClassLoaderUtilsTest.java @@ -19,7 +19,6 @@ import java.util.Set; import java.util.TreeSet; -import static io.microsphere.collection.SetUtils.of; import static io.microsphere.constants.FileConstants.CLASS_EXTENSION; import static io.microsphere.reflect.FieldUtils.findAllDeclaredFields; import static io.microsphere.util.ClassLoaderUtils.findAllClassPathURLs; @@ -47,7 +46,6 @@ import static io.microsphere.util.VersionUtils.CURRENT_JAVA_VERSION; import static io.microsphere.util.VersionUtils.JAVA_VERSION_12; import static java.lang.ClassLoader.getSystemClassLoader; -import static java.util.Collections.emptySet; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -259,22 +257,6 @@ public void testFindLoadedClassesInClassPaths() { assertFalse(allLoadedClasses.isEmpty()); } - @Test - public void testOfSet() { - Set set = of(); - assertEquals(emptySet(), set); - - set = of(((String[]) null)); - assertEquals(emptySet(), set); - - set = of("A", "B", "C"); - Set expectedSet = new LinkedHashSet<>(); - expectedSet.add("A"); - expectedSet.add("B"); - expectedSet.add("C"); - assertEquals(expectedSet, set); - } - @Test public void testGetClassLoader() { Class currentClass = getClass();