From 4ee8d7e0cfaa7ecbf9ae2aace032d098b9782e90 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 19 Mar 2026 12:44:07 +0000 Subject: [PATCH] refactor: extract MethodHandle helpers in Sets/Maps/Lists for full branch coverage Co-authored-by: mercyblitz <533114+mercyblitz@users.noreply.github.com> --- .../java/io/microsphere/collection/Lists.java | 96 +++++++--- .../java/io/microsphere/collection/Maps.java | 99 +++++++--- .../java/io/microsphere/collection/Sets.java | 96 +++++++--- .../io/microsphere/collection/ListsTest.java | 150 +++++++++++++++ .../io/microsphere/collection/MapsTest.java | 179 ++++++++++++++++++ .../io/microsphere/collection/SetsTest.java | 150 +++++++++++++++ 6 files changed, 698 insertions(+), 72 deletions(-) diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/Lists.java b/microsphere-java-core/src/main/java/io/microsphere/collection/Lists.java index 6407c2d61..f5851a805 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/Lists.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/Lists.java @@ -117,11 +117,15 @@ public abstract class Lists implements Utils { @Nonnull @Immutable public static List ofList() { - if (of0MethodHandle == null) { + return ofList0(of0MethodHandle); + } + + static List ofList0(MethodHandle methodHandle) { + if (methodHandle == null) { return emptyList(); } try { - return (List) of0MethodHandle.invokeExact(); + return (List) methodHandle.invokeExact(); } catch (Throwable e) { return emptyList(); } @@ -146,11 +150,15 @@ public static List ofList() { @Nonnull @Immutable public static List ofList(E e1) { - if (of1MethodHandle == null) { + return ofList1(of1MethodHandle, e1); + } + + static List ofList1(MethodHandle methodHandle, E e1) { + if (methodHandle == null) { return singletonList(e1); } try { - return (List) of1MethodHandle.invokeExact(e1); + return (List) methodHandle.invokeExact(e1); } catch (Throwable e) { return singletonList(e1); } @@ -176,11 +184,15 @@ public static List ofList(E e1) { @Nonnull @Immutable public static List ofList(E e1, E e2) { - if (of2MethodHandle == null) { + return ofList2(of2MethodHandle, e1, e2); + } + + static List ofList2(MethodHandle methodHandle, E e1, E e2) { + if (methodHandle == null) { return of(e1, e2); } try { - return (List) of2MethodHandle.invokeExact(e1, e2); + return (List) methodHandle.invokeExact(e1, e2); } catch (Throwable e) { return of(e1, e2); } @@ -207,11 +219,15 @@ public static List ofList(E e1, E e2) { @Nonnull @Immutable public static List ofList(E e1, E e2, E e3) { - if (of3MethodHandle == null) { + return ofList3(of3MethodHandle, e1, e2, e3); + } + + static List ofList3(MethodHandle methodHandle, E e1, E e2, E e3) { + if (methodHandle == null) { return of(e1, e2, e3); } try { - return (List) of3MethodHandle.invokeExact(e1, e2, e3); + return (List) methodHandle.invokeExact(e1, e2, e3); } catch (Throwable e) { return of(e1, e2, e3); } @@ -239,11 +255,15 @@ public static List ofList(E e1, E e2, E e3) { @Nonnull @Immutable public static List ofList(E e1, E e2, E e3, E e4) { - if (of4MethodHandle == null) { + return ofList4(of4MethodHandle, e1, e2, e3, e4); + } + + static List ofList4(MethodHandle methodHandle, E e1, E e2, E e3, E e4) { + if (methodHandle == null) { return of(e1, e2, e3, e4); } try { - return (List) of4MethodHandle.invokeExact(e1, e2, e3, e4); + return (List) methodHandle.invokeExact(e1, e2, e3, e4); } catch (Throwable e) { return of(e1, e2, e3, e4); } @@ -272,11 +292,15 @@ public static List ofList(E e1, E e2, E e3, E e4) { @Nonnull @Immutable public static List ofList(E e1, E e2, E e3, E e4, E e5) { - if (of5MethodHandle == null) { + return ofList5(of5MethodHandle, e1, e2, e3, e4, e5); + } + + static List ofList5(MethodHandle methodHandle, E e1, E e2, E e3, E e4, E e5) { + if (methodHandle == null) { return of(e1, e2, e3, e4, e5); } try { - return (List) of5MethodHandle.invokeExact(e1, e2, e3, e4, e5); + return (List) methodHandle.invokeExact(e1, e2, e3, e4, e5); } catch (Throwable e) { return of(e1, e2, e3, e4, e5); } @@ -298,11 +322,15 @@ public static List ofList(E e1, E e2, E e3, E e4, E e5) { @Nonnull @Immutable static List ofList(E e1, E e2, E e3, E e4, E e5, E e6) { - if (of6MethodHandle == null) { + return ofList6(of6MethodHandle, e1, e2, e3, e4, e5, e6); + } + + static List ofList6(MethodHandle methodHandle, E e1, E e2, E e3, E e4, E e5, E e6) { + if (methodHandle == null) { return of(e1, e2, e3, e4, e5, e6); } try { - return (List) of6MethodHandle.invokeExact(e1, e2, e3, e4, e5, e6); + return (List) methodHandle.invokeExact(e1, e2, e3, e4, e5, e6); } catch (Throwable e) { return of(e1, e2, e3, e4, e5, e6); } @@ -333,11 +361,15 @@ static List ofList(E e1, E e2, E e3, E e4, E e5, E e6) { @Nonnull @Immutable public static List ofList(E e1, E e2, E e3, E e4, E e5, E e6, E e7) { - if (of7MethodHandle == null) { + return ofList7(of7MethodHandle, e1, e2, e3, e4, e5, e6, e7); + } + + static List ofList7(MethodHandle methodHandle, E e1, E e2, E e3, E e4, E e5, E e6, E e7) { + if (methodHandle == null) { return of(e1, e2, e3, e4, e5, e6, e7); } try { - return (List) of7MethodHandle.invokeExact(e1, e2, e3, e4, e5, e6, e7); + return (List) methodHandle.invokeExact(e1, e2, e3, e4, e5, e6, e7); } catch (Throwable e) { return of(e1, e2, e3, e4, e5, e6, e7); } @@ -369,11 +401,15 @@ public static List ofList(E e1, E e2, E e3, E e4, E e5, E e6, E e7) { @Nonnull @Immutable public static List ofList(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8) { - if (of8MethodHandle == null) { + return ofList8(of8MethodHandle, e1, e2, e3, e4, e5, e6, e7, e8); + } + + static List ofList8(MethodHandle methodHandle, E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8) { + if (methodHandle == null) { return of(e1, e2, e3, e4, e5, e6, e7, e8); } try { - return (List) of8MethodHandle.invokeExact(e1, e2, e3, e4, e5, e6, e7, e8); + return (List) methodHandle.invokeExact(e1, e2, e3, e4, e5, e6, e7, e8); } catch (Throwable e) { return of(e1, e2, e3, e4, e5, e6, e7, e8); } @@ -406,11 +442,15 @@ public static List ofList(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8) @Nonnull @Immutable public static List ofList(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9) { - if (of9MethodHandle == null) { + return ofList9(of9MethodHandle, e1, e2, e3, e4, e5, e6, e7, e8, e9); + } + + static List ofList9(MethodHandle methodHandle, E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9) { + if (methodHandle == null) { return of(e1, e2, e3, e4, e5, e6, e7, e8, e9); } try { - return (List) of9MethodHandle.invokeExact(e1, e2, e3, e4, e5, e6, e7, e8, e9); + return (List) methodHandle.invokeExact(e1, e2, e3, e4, e5, e6, e7, e8, e9); } catch (Throwable e) { return of(e1, e2, e3, e4, e5, e6, e7, e8, e9); } @@ -436,11 +476,15 @@ public static List ofList(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, @Nonnull @Immutable static List ofList(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10) { - if (of10MethodHandle == null) { + return ofList10(of10MethodHandle, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10); + } + + static List ofList10(MethodHandle methodHandle, E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10) { + if (methodHandle == null) { return of(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10); } try { - return (List) of10MethodHandle.invokeExact(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10); + return (List) methodHandle.invokeExact(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10); } catch (Throwable e) { return of(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10); } @@ -470,11 +514,15 @@ public static List ofList(E... elements) { if (length(elements) < 1) { return ofList(); } - if (ofMethodHandle == null) { + return ofListElements(ofMethodHandle, elements); + } + + static List ofListElements(MethodHandle methodHandle, E[] elements) { + if (methodHandle == null) { return of(elements); } try { - return (List) ofMethodHandle.invokeExact(elements); + return (List) methodHandle.invokeExact(elements); } catch (Throwable e) { return of(elements); } diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/Maps.java b/microsphere-java-core/src/main/java/io/microsphere/collection/Maps.java index a3716cf12..093ec44c4 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/Maps.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/Maps.java @@ -114,11 +114,15 @@ public abstract class Maps implements Utils { @Nonnull @Immutable public static Map ofMap() { - if (of0MethodHandle == null) { + return ofMap0(of0MethodHandle); + } + + static Map ofMap0(MethodHandle methodHandle) { + if (methodHandle == null) { return emptyMap(); } try { - return (Map) of0MethodHandle.invokeExact(); + return (Map) methodHandle.invokeExact(); } catch (Throwable e) { return emptyMap(); } @@ -144,11 +148,15 @@ public static Map ofMap() { @Nonnull @Immutable public static Map ofMap(K k1, V v1) { - if (of1MethodHandle == null) { + return ofMap1(of1MethodHandle, k1, v1); + } + + static Map ofMap1(MethodHandle methodHandle, K k1, V v1) { + if (methodHandle == null) { return singletonMap(k1, v1); } try { - return (Map) of1MethodHandle.invokeExact(k1, v1); + return (Map) methodHandle.invokeExact(k1, v1); } catch (Throwable e) { return singletonMap(k1, v1); } @@ -175,11 +183,15 @@ public static Map ofMap(K k1, V v1) { @Nonnull @Immutable public static Map ofMap(K k1, V v1, K k2, V v2) { - if (of2MethodHandle == null) { + return ofMap2(of2MethodHandle, k1, v1, k2, v2); + } + + static Map ofMap2(MethodHandle methodHandle, K k1, V v1, K k2, V v2) { + if (methodHandle == null) { return of(k1, v1, k2, v2); } try { - return (Map) of2MethodHandle.invokeExact(k1, v1, k2, v2); + return (Map) methodHandle.invokeExact(k1, v1, k2, v2); } catch (Throwable e) { return of(k1, v1, k2, v2); } @@ -208,11 +220,15 @@ public static Map ofMap(K k1, V v1, K k2, V v2) { @Nonnull @Immutable public static Map ofMap(K k1, V v1, K k2, V v2, K k3, V v3) { - if (of3MethodHandle == null) { + return ofMap3(of3MethodHandle, k1, v1, k2, v2, k3, v3); + } + + static Map ofMap3(MethodHandle methodHandle, K k1, V v1, K k2, V v2, K k3, V v3) { + if (methodHandle == null) { return of(k1, v1, k2, v2, k3, v3); } try { - return (Map) of3MethodHandle.invokeExact(k1, v1, k2, v2, k3, v3); + return (Map) methodHandle.invokeExact(k1, v1, k2, v2, k3, v3); } catch (Throwable e) { return of(k1, v1, k2, v2, k3, v3); } @@ -243,11 +259,15 @@ public static Map ofMap(K k1, V v1, K k2, V v2, K k3, V v3) { @Nonnull @Immutable public static Map ofMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { - if (of4MethodHandle == null) { + return ofMap4(of4MethodHandle, k1, v1, k2, v2, k3, v3, k4, v4); + } + + static Map ofMap4(MethodHandle methodHandle, K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { + if (methodHandle == null) { return of(k1, v1, k2, v2, k3, v3, k4, v4); } try { - return (Map) of4MethodHandle.invokeExact(k1, v1, k2, v2, k3, v3, k4, v4); + return (Map) methodHandle.invokeExact(k1, v1, k2, v2, k3, v3, k4, v4); } catch (Throwable e) { return of(k1, v1, k2, v2, k3, v3, k4, v4); } @@ -280,11 +300,15 @@ public static Map ofMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V @Nonnull @Immutable public static Map ofMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { - if (of5MethodHandle == null) { + return ofMap5(of5MethodHandle, k1, v1, k2, v2, k3, v3, k4, v4, k5, v5); + } + + static Map ofMap5(MethodHandle methodHandle, K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { + if (methodHandle == null) { return of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5); } try { - return (Map) of5MethodHandle.invokeExact(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5); + return (Map) methodHandle.invokeExact(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5); } catch (Throwable e) { return of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5); } @@ -319,11 +343,15 @@ public static Map ofMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V @Nonnull @Immutable public static Map ofMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6) { - if (of6MethodHandle == null) { + return ofMap6(of6MethodHandle, k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6); + } + + static Map ofMap6(MethodHandle methodHandle, K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6) { + if (methodHandle == null) { return of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6); } try { - return (Map) of6MethodHandle.invokeExact(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6); + return (Map) methodHandle.invokeExact(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6); } catch (Throwable e) { return of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6); } @@ -361,11 +389,15 @@ public static Map ofMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V @Nonnull @Immutable public static Map ofMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7) { - if (of7MethodHandle == null) { + return ofMap7(of7MethodHandle, k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7); + } + + static Map ofMap7(MethodHandle methodHandle, K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7) { + if (methodHandle == null) { return of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7); } try { - return (Map) of7MethodHandle.invokeExact(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7); + return (Map) methodHandle.invokeExact(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7); } catch (Throwable e) { return of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7); } @@ -406,11 +438,16 @@ public static Map ofMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V @Immutable public static Map ofMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8) { - if (of8MethodHandle == null) { + return ofMap8(of8MethodHandle, k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8); + } + + static Map ofMap8(MethodHandle methodHandle, K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, + K k8, V v8) { + if (methodHandle == null) { return of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8); } try { - return (Map) of8MethodHandle.invokeExact(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8); + return (Map) methodHandle.invokeExact(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8); } catch (Throwable e) { return of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8); } @@ -453,11 +490,16 @@ public static Map ofMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V @Immutable public static Map ofMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9) { - if (of9MethodHandle == null) { + return ofMap9(of9MethodHandle, k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9); + } + + static Map ofMap9(MethodHandle methodHandle, K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, + K k8, V v8, K k9, V v9) { + if (methodHandle == null) { return of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9); } try { - return (Map) of9MethodHandle.invokeExact(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9); + return (Map) methodHandle.invokeExact(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9); } catch (Throwable e) { return of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9); } @@ -503,11 +545,16 @@ public static Map ofMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V @Immutable public static Map ofMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10) { - if (of10MethodHandle == null) { + return ofMap10(of10MethodHandle, k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10); + } + + static Map ofMap10(MethodHandle methodHandle, K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, + K k8, V v8, K k9, V v9, K k10, V v10) { + if (methodHandle == null) { return of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10); } try { - return (Map) of10MethodHandle.invokeExact(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10); + return (Map) methodHandle.invokeExact(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10); } catch (Throwable e) { return of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10); } @@ -539,11 +586,15 @@ public static Map ofMap(Map.Entry... entr if (length(entries) < 1) { return emptyMap(); } - if (ofEntriesMethodHandle == null) { + return ofMapEntries(ofEntriesMethodHandle, entries); + } + + static Map ofMapEntries(MethodHandle methodHandle, Map.Entry[] entries) { + if (methodHandle == null) { return of(entries); } try { - return (Map) ofEntriesMethodHandle.invokeExact(entries); + return (Map) methodHandle.invokeExact(entries); } catch (Throwable e) { return of(entries); } diff --git a/microsphere-java-core/src/main/java/io/microsphere/collection/Sets.java b/microsphere-java-core/src/main/java/io/microsphere/collection/Sets.java index 9c4891a43..f8effe0e5 100644 --- a/microsphere-java-core/src/main/java/io/microsphere/collection/Sets.java +++ b/microsphere-java-core/src/main/java/io/microsphere/collection/Sets.java @@ -119,11 +119,15 @@ public abstract class Sets implements Utils { @Nonnull @Immutable public static Set ofSet() { - if (of0MethodHandle == null) { + return ofSet0(of0MethodHandle); + } + + static Set ofSet0(MethodHandle methodHandle) { + if (methodHandle == null) { return emptySet(); } try { - return (Set) of0MethodHandle.invokeExact(); + return (Set) methodHandle.invokeExact(); } catch (Throwable e) { return emptySet(); } @@ -152,11 +156,15 @@ public static Set ofSet() { @Nonnull @Immutable public static Set ofSet(E e1) { - if (of1MethodHandle == null) { + return ofSet1(of1MethodHandle, e1); + } + + static Set ofSet1(MethodHandle methodHandle, E e1) { + if (methodHandle == null) { return singleton(e1); } try { - return (Set) of1MethodHandle.invokeExact(e1); + return (Set) methodHandle.invokeExact(e1); } catch (Throwable e) { return singleton(e1); } @@ -185,11 +193,15 @@ public static Set ofSet(E e1) { @Nonnull @Immutable public static Set ofSet(E e1, E e2) { - if (of2MethodHandle == null) { + return ofSet2(of2MethodHandle, e1, e2); + } + + static Set ofSet2(MethodHandle methodHandle, E e1, E e2) { + if (methodHandle == null) { return of(e1, e2); } try { - return (Set) of2MethodHandle.invokeExact(e1, e2); + return (Set) methodHandle.invokeExact(e1, e2); } catch (Throwable e) { return of(e1, e2); } @@ -219,11 +231,15 @@ public static Set ofSet(E e1, E e2) { @Nonnull @Immutable public static Set ofSet(E e1, E e2, E e3) { - if (of3MethodHandle == null) { + return ofSet3(of3MethodHandle, e1, e2, e3); + } + + static Set ofSet3(MethodHandle methodHandle, E e1, E e2, E e3) { + if (methodHandle == null) { return of(e1, e2, e3); } try { - return (Set) of3MethodHandle.invokeExact(e1, e2, e3); + return (Set) methodHandle.invokeExact(e1, e2, e3); } catch (Throwable e) { return of(e1, e2, e3); } @@ -254,11 +270,15 @@ public static Set ofSet(E e1, E e2, E e3) { @Nonnull @Immutable public static Set ofSet(E e1, E e2, E e3, E e4) { - if (of4MethodHandle == null) { + return ofSet4(of4MethodHandle, e1, e2, e3, e4); + } + + static Set ofSet4(MethodHandle methodHandle, E e1, E e2, E e3, E e4) { + if (methodHandle == null) { return of(e1, e2, e3, e4); } try { - return (Set) of4MethodHandle.invokeExact(e1, e2, e3, e4); + return (Set) methodHandle.invokeExact(e1, e2, e3, e4); } catch (Throwable e) { return of(e1, e2, e3, e4); } @@ -279,11 +299,15 @@ public static Set ofSet(E e1, E e2, E e3, E e4) { @Nonnull @Immutable public static Set ofSet(E e1, E e2, E e3, E e4, E e5) { - if (of5MethodHandle == null) { + return ofSet5(of5MethodHandle, e1, e2, e3, e4, e5); + } + + static Set ofSet5(MethodHandle methodHandle, E e1, E e2, E e3, E e4, E e5) { + if (methodHandle == null) { return of(e1, e2, e3, e4, e5); } try { - return (Set) of5MethodHandle.invokeExact(e1, e2, e3, e4, e5); + return (Set) methodHandle.invokeExact(e1, e2, e3, e4, e5); } catch (Throwable e) { return of(e1, e2, e3, e4, e5); } @@ -316,11 +340,15 @@ public static Set ofSet(E e1, E e2, E e3, E e4, E e5) { @Nonnull @Immutable public static Set ofSet(E e1, E e2, E e3, E e4, E e5, E e6) { - if (of6MethodHandle == null) { + return ofSet6(of6MethodHandle, e1, e2, e3, e4, e5, e6); + } + + static Set ofSet6(MethodHandle methodHandle, E e1, E e2, E e3, E e4, E e5, E e6) { + if (methodHandle == null) { return of(e1, e2, e3, e4, e5, e6); } try { - return (Set) of6MethodHandle.invokeExact(e1, e2, e3, e4, e5, e6); + return (Set) methodHandle.invokeExact(e1, e2, e3, e4, e5, e6); } catch (Throwable e) { return of(e1, e2, e3, e4, e5, e6); } @@ -354,11 +382,15 @@ public static Set ofSet(E e1, E e2, E e3, E e4, E e5, E e6) { @Nonnull @Immutable public static Set ofSet(E e1, E e2, E e3, E e4, E e5, E e6, E e7) { - if (of7MethodHandle == null) { + return ofSet7(of7MethodHandle, e1, e2, e3, e4, e5, e6, e7); + } + + static Set ofSet7(MethodHandle methodHandle, E e1, E e2, E e3, E e4, E e5, E e6, E e7) { + if (methodHandle == null) { return of(e1, e2, e3, e4, e5, e6, e7); } try { - return (Set) of7MethodHandle.invokeExact(e1, e2, e3, e4, e5, e6, e7); + return (Set) methodHandle.invokeExact(e1, e2, e3, e4, e5, e6, e7); } catch (Throwable e) { return of(e1, e2, e3, e4, e5, e6, e7); } @@ -393,11 +425,15 @@ public static Set ofSet(E e1, E e2, E e3, E e4, E e5, E e6, E e7) { @Nonnull @Immutable public static Set ofSet(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8) { - if (of8MethodHandle == null) { + return ofSet8(of8MethodHandle, e1, e2, e3, e4, e5, e6, e7, e8); + } + + static Set ofSet8(MethodHandle methodHandle, E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8) { + if (methodHandle == null) { return of(e1, e2, e3, e4, e5, e6, e7, e8); } try { - return (Set) of8MethodHandle.invokeExact(e1, e2, e3, e4, e5, e6, e7, e8); + return (Set) methodHandle.invokeExact(e1, e2, e3, e4, e5, e6, e7, e8); } catch (Throwable e) { return of(e1, e2, e3, e4, e5, e6, e7, e8); } @@ -433,11 +469,15 @@ public static Set ofSet(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8) { @Nonnull @Immutable public static Set ofSet(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9) { - if (of9MethodHandle == null) { + return ofSet9(of9MethodHandle, e1, e2, e3, e4, e5, e6, e7, e8, e9); + } + + static Set ofSet9(MethodHandle methodHandle, E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9) { + if (methodHandle == null) { return of(e1, e2, e3, e4, e5, e6, e7, e8, e9); } try { - return (Set) of9MethodHandle.invokeExact(e1, e2, e3, e4, e5, e6, e7, e8, e9); + return (Set) methodHandle.invokeExact(e1, e2, e3, e4, e5, e6, e7, e8, e9); } catch (Throwable e) { return of(e1, e2, e3, e4, e5, e6, e7, e8, e9); } @@ -474,11 +514,15 @@ public static Set ofSet(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E @Nonnull @Immutable public static Set ofSet(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10) { - if (of10MethodHandle == null) { + return ofSet10(of10MethodHandle, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10); + } + + static Set ofSet10(MethodHandle methodHandle, E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10) { + if (methodHandle == null) { return of(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10); } try { - return (Set) of10MethodHandle.invokeExact(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10); + return (Set) methodHandle.invokeExact(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10); } catch (Throwable e) { return of(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10); } @@ -509,11 +553,15 @@ public static Set ofSet(E... elements) { if (length(elements) < 1) { return ofSet(); } - if (ofMethodHandle == null) { + return ofSetElements(ofMethodHandle, elements); + } + + static Set ofSetElements(MethodHandle methodHandle, E[] elements) { + if (methodHandle == null) { return of(elements); } try { - return (Set) ofMethodHandle.invokeExact(elements); + return (Set) methodHandle.invokeExact(elements); } catch (Throwable e) { return of(elements); } 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 375751aeb..298d06b5a 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,10 +2,26 @@ import org.junit.jupiter.api.Test; +import java.lang.invoke.MethodHandle; + import static io.microsphere.AbstractTestCase.TEST_NULL_OBJECT_ARRAY; import static io.microsphere.collection.ListUtils.of; import static io.microsphere.collection.Lists.ofList; +import static io.microsphere.collection.Lists.ofList0; +import static io.microsphere.collection.Lists.ofList1; +import static io.microsphere.collection.Lists.ofList2; +import static io.microsphere.collection.Lists.ofList3; +import static io.microsphere.collection.Lists.ofList4; +import static io.microsphere.collection.Lists.ofList5; +import static io.microsphere.collection.Lists.ofList6; +import static io.microsphere.collection.Lists.ofList7; +import static io.microsphere.collection.Lists.ofList8; +import static io.microsphere.collection.Lists.ofList9; +import static io.microsphere.collection.Lists.ofList10; +import static io.microsphere.collection.Lists.ofListElements; +import static io.microsphere.invoke.MethodHandlesLookupUtils.findPublicStatic; import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -86,4 +102,138 @@ void testOfListImmutability() { assertThrows(UnsupportedOperationException.class, () -> ofList(1, 2).remove(0)); assertThrows(UnsupportedOperationException.class, () -> ofList(1, 2, 3).clear()); } + + @Test + void testOfList0WithNull() { + assertEquals(emptyList(), ofList0(null)); + } + + @Test + void testOfList0WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyList"); + assertEquals(emptyList(), ofList0(wrongMethodHandle)); + } + + @Test + void testOfList1WithNull() { + assertEquals(singletonList(1), ofList1(null, 1)); + } + + @Test + void testOfList1WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyList"); + assertEquals(singletonList(1), ofList1(wrongMethodHandle, 1)); + } + + @Test + void testOfList2WithNull() { + assertEquals(of(1, 2), ofList2(null, 1, 2)); + } + + @Test + void testOfList2WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyList"); + assertEquals(of(1, 2), ofList2(wrongMethodHandle, 1, 2)); + } + + @Test + void testOfList3WithNull() { + assertEquals(of(1, 2, 3), ofList3(null, 1, 2, 3)); + } + + @Test + void testOfList3WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyList"); + assertEquals(of(1, 2, 3), ofList3(wrongMethodHandle, 1, 2, 3)); + } + + @Test + void testOfList4WithNull() { + assertEquals(of(1, 2, 3, 4), ofList4(null, 1, 2, 3, 4)); + } + + @Test + void testOfList4WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyList"); + assertEquals(of(1, 2, 3, 4), ofList4(wrongMethodHandle, 1, 2, 3, 4)); + } + + @Test + void testOfList5WithNull() { + assertEquals(of(1, 2, 3, 4, 5), ofList5(null, 1, 2, 3, 4, 5)); + } + + @Test + void testOfList5WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyList"); + assertEquals(of(1, 2, 3, 4, 5), ofList5(wrongMethodHandle, 1, 2, 3, 4, 5)); + } + + @Test + void testOfList6WithNull() { + assertEquals(of(1, 2, 3, 4, 5, 6), ofList6(null, 1, 2, 3, 4, 5, 6)); + } + + @Test + void testOfList6WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyList"); + assertEquals(of(1, 2, 3, 4, 5, 6), ofList6(wrongMethodHandle, 1, 2, 3, 4, 5, 6)); + } + + @Test + void testOfList7WithNull() { + assertEquals(of(1, 2, 3, 4, 5, 6, 7), ofList7(null, 1, 2, 3, 4, 5, 6, 7)); + } + + @Test + void testOfList7WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyList"); + assertEquals(of(1, 2, 3, 4, 5, 6, 7), ofList7(wrongMethodHandle, 1, 2, 3, 4, 5, 6, 7)); + } + + @Test + void testOfList8WithNull() { + assertEquals(of(1, 2, 3, 4, 5, 6, 7, 8), ofList8(null, 1, 2, 3, 4, 5, 6, 7, 8)); + } + + @Test + void testOfList8WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyList"); + assertEquals(of(1, 2, 3, 4, 5, 6, 7, 8), ofList8(wrongMethodHandle, 1, 2, 3, 4, 5, 6, 7, 8)); + } + + @Test + void testOfList9WithNull() { + assertEquals(of(1, 2, 3, 4, 5, 6, 7, 8, 9), ofList9(null, 1, 2, 3, 4, 5, 6, 7, 8, 9)); + } + + @Test + void testOfList9WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyList"); + assertEquals(of(1, 2, 3, 4, 5, 6, 7, 8, 9), ofList9(wrongMethodHandle, 1, 2, 3, 4, 5, 6, 7, 8, 9)); + } + + @Test + void testOfList10WithNull() { + assertEquals(of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ofList10(null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + } + + @Test + void testOfList10WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyList"); + assertEquals(of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ofList10(wrongMethodHandle, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + } + + @Test + void testOfListElementsWithNull() { + Integer[] elements = {1, 2, 3}; + assertEquals(of(elements), ofListElements(null, elements)); + } + + @Test + void testOfListElementsWithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyList"); + Integer[] elements = {1, 2, 3}; + assertEquals(of(elements), ofListElements(wrongMethodHandle, elements)); + } } \ No newline at end of file diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/MapsTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/MapsTest.java index 0ec9c6c59..325159209 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/MapsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/MapsTest.java @@ -2,12 +2,27 @@ import org.junit.jupiter.api.Test; +import java.lang.invoke.MethodHandle; import java.util.Map; import static io.microsphere.collection.MapUtils.ofEntry; import static io.microsphere.collection.MapUtilsTest.assertOfMap; import static io.microsphere.collection.Maps.ofMap; +import static io.microsphere.collection.Maps.ofMap0; +import static io.microsphere.collection.Maps.ofMap1; +import static io.microsphere.collection.Maps.ofMap2; +import static io.microsphere.collection.Maps.ofMap3; +import static io.microsphere.collection.Maps.ofMap4; +import static io.microsphere.collection.Maps.ofMap5; +import static io.microsphere.collection.Maps.ofMap6; +import static io.microsphere.collection.Maps.ofMap7; +import static io.microsphere.collection.Maps.ofMap8; +import static io.microsphere.collection.Maps.ofMap9; +import static io.microsphere.collection.Maps.ofMap10; +import static io.microsphere.collection.Maps.ofMapEntries; +import static io.microsphere.invoke.MethodHandlesLookupUtils.findPublicStatic; import static java.util.Collections.emptyMap; +import static java.util.Collections.singletonMap; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; @@ -205,4 +220,168 @@ void testOfMapImmutability() { assertThrows(UnsupportedOperationException.class, () -> ofMap("A", 1, "B", 2).remove("A")); assertThrows(UnsupportedOperationException.class, () -> ofMap("A", 1, "B", 2, "C", 3).clear()); } + + @Test + void testOfMap0WithNull() { + assertEquals(emptyMap(), ofMap0(null)); + } + + @Test + void testOfMap0WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyMap"); + assertEquals(emptyMap(), ofMap0(wrongMethodHandle)); + } + + @Test + void testOfMap1WithNull() { + assertEquals(singletonMap("A", 1), ofMap1(null, "A", 1)); + } + + @Test + void testOfMap1WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyMap"); + assertEquals(singletonMap("A", 1), ofMap1(wrongMethodHandle, "A", 1)); + } + + @Test + void testOfMap2WithNull() { + Map map = ofMap2(null, "A", 1, "B", 2); + assertEquals(2, map.size()); + assertEquals(1, map.get("A")); + assertEquals(2, map.get("B")); + } + + @Test + void testOfMap2WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyMap"); + Map map = ofMap2(wrongMethodHandle, "A", 1, "B", 2); + assertEquals(2, map.size()); + assertEquals(1, map.get("A")); + assertEquals(2, map.get("B")); + } + + @Test + void testOfMap3WithNull() { + Map map = ofMap3(null, "A", 1, "B", 2, "C", 3); + assertEquals(3, map.size()); + } + + @Test + void testOfMap3WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyMap"); + Map map = ofMap3(wrongMethodHandle, "A", 1, "B", 2, "C", 3); + assertEquals(3, map.size()); + } + + @Test + void testOfMap4WithNull() { + Map map = ofMap4(null, "A", 1, "B", 2, "C", 3, "D", 4); + assertEquals(4, map.size()); + } + + @Test + void testOfMap4WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyMap"); + Map map = ofMap4(wrongMethodHandle, "A", 1, "B", 2, "C", 3, "D", 4); + assertEquals(4, map.size()); + } + + @Test + void testOfMap5WithNull() { + Map map = ofMap5(null, "A", 1, "B", 2, "C", 3, "D", 4, "E", 5); + assertEquals(5, map.size()); + } + + @Test + void testOfMap5WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyMap"); + Map map = ofMap5(wrongMethodHandle, "A", 1, "B", 2, "C", 3, "D", 4, "E", 5); + assertEquals(5, map.size()); + } + + @Test + void testOfMap6WithNull() { + Map map = ofMap6(null, "A", 1, "B", 2, "C", 3, "D", 4, "E", 5, "F", 6); + assertEquals(6, map.size()); + } + + @Test + void testOfMap6WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyMap"); + Map map = ofMap6(wrongMethodHandle, "A", 1, "B", 2, "C", 3, "D", 4, "E", 5, "F", 6); + assertEquals(6, map.size()); + } + + @Test + void testOfMap7WithNull() { + Map map = ofMap7(null, "A", 1, "B", 2, "C", 3, "D", 4, "E", 5, "F", 6, "G", 7); + assertEquals(7, map.size()); + } + + @Test + void testOfMap7WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyMap"); + Map map = ofMap7(wrongMethodHandle, "A", 1, "B", 2, "C", 3, "D", 4, "E", 5, "F", 6, "G", 7); + assertEquals(7, map.size()); + } + + @Test + void testOfMap8WithNull() { + Map map = ofMap8(null, "A", 1, "B", 2, "C", 3, "D", 4, "E", 5, "F", 6, "G", 7, "H", 8); + assertEquals(8, map.size()); + } + + @Test + void testOfMap8WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyMap"); + Map map = ofMap8(wrongMethodHandle, "A", 1, "B", 2, "C", 3, "D", 4, "E", 5, "F", 6, "G", 7, "H", 8); + assertEquals(8, map.size()); + } + + @Test + void testOfMap9WithNull() { + Map map = ofMap9(null, "A", 1, "B", 2, "C", 3, "D", 4, "E", 5, "F", 6, "G", 7, "H", 8, "I", 9); + assertEquals(9, map.size()); + } + + @Test + void testOfMap9WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyMap"); + Map map = ofMap9(wrongMethodHandle, "A", 1, "B", 2, "C", 3, "D", 4, "E", 5, "F", 6, "G", 7, "H", 8, "I", 9); + assertEquals(9, map.size()); + } + + @Test + void testOfMap10WithNull() { + Map map = ofMap10(null, "A", 1, "B", 2, "C", 3, "D", 4, "E", 5, "F", 6, "G", 7, "H", 8, "I", 9, "J", 10); + assertEquals(10, map.size()); + } + + @Test + void testOfMap10WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyMap"); + Map map = ofMap10(wrongMethodHandle, "A", 1, "B", 2, "C", 3, "D", 4, "E", 5, "F", 6, "G", 7, "H", 8, "I", 9, "J", 10); + assertEquals(10, map.size()); + } + + @Test + void testOfMapEntriesWithNull() { + Map.Entry entryA = ofEntry("A", 1); + Map.Entry entryB = ofEntry("B", 2); + Map map = ofMapEntries(null, new Map.Entry[]{entryA, entryB}); + assertEquals(2, map.size()); + assertEquals(1, map.get("A")); + assertEquals(2, map.get("B")); + } + + @Test + void testOfMapEntriesWithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptyMap"); + Map.Entry entryA = ofEntry("A", 1); + Map.Entry entryB = ofEntry("B", 2); + Map map = ofMapEntries(wrongMethodHandle, new Map.Entry[]{entryA, entryB}); + assertEquals(2, map.size()); + assertEquals(1, map.get("A")); + assertEquals(2, map.get("B")); + } } \ No newline at end of file diff --git a/microsphere-java-core/src/test/java/io/microsphere/collection/SetsTest.java b/microsphere-java-core/src/test/java/io/microsphere/collection/SetsTest.java index 521663ae2..f718e84e8 100644 --- a/microsphere-java-core/src/test/java/io/microsphere/collection/SetsTest.java +++ b/microsphere-java-core/src/test/java/io/microsphere/collection/SetsTest.java @@ -2,10 +2,26 @@ import org.junit.jupiter.api.Test; +import java.lang.invoke.MethodHandle; + import static io.microsphere.AbstractTestCase.TEST_NULL_OBJECT_ARRAY; import static io.microsphere.collection.SetUtils.of; import static io.microsphere.collection.Sets.ofSet; +import static io.microsphere.collection.Sets.ofSet0; +import static io.microsphere.collection.Sets.ofSet1; +import static io.microsphere.collection.Sets.ofSet2; +import static io.microsphere.collection.Sets.ofSet3; +import static io.microsphere.collection.Sets.ofSet4; +import static io.microsphere.collection.Sets.ofSet5; +import static io.microsphere.collection.Sets.ofSet6; +import static io.microsphere.collection.Sets.ofSet7; +import static io.microsphere.collection.Sets.ofSet8; +import static io.microsphere.collection.Sets.ofSet9; +import static io.microsphere.collection.Sets.ofSet10; +import static io.microsphere.collection.Sets.ofSetElements; +import static io.microsphere.invoke.MethodHandlesLookupUtils.findPublicStatic; import static java.util.Collections.emptySet; +import static java.util.Collections.singleton; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -86,4 +102,138 @@ void testOfSetImmutability() { assertThrows(UnsupportedOperationException.class, () -> ofSet(1, 2).remove(1)); assertThrows(UnsupportedOperationException.class, () -> ofSet(1, 2, 3).clear()); } + + @Test + void testOfSet0WithNull() { + assertEquals(emptySet(), ofSet0(null)); + } + + @Test + void testOfSet0WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptySet"); + assertEquals(emptySet(), ofSet0(wrongMethodHandle)); + } + + @Test + void testOfSet1WithNull() { + assertEquals(singleton(1), ofSet1(null, 1)); + } + + @Test + void testOfSet1WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptySet"); + assertEquals(singleton(1), ofSet1(wrongMethodHandle, 1)); + } + + @Test + void testOfSet2WithNull() { + assertEquals(of(1, 2), ofSet2(null, 1, 2)); + } + + @Test + void testOfSet2WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptySet"); + assertEquals(of(1, 2), ofSet2(wrongMethodHandle, 1, 2)); + } + + @Test + void testOfSet3WithNull() { + assertEquals(of(1, 2, 3), ofSet3(null, 1, 2, 3)); + } + + @Test + void testOfSet3WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptySet"); + assertEquals(of(1, 2, 3), ofSet3(wrongMethodHandle, 1, 2, 3)); + } + + @Test + void testOfSet4WithNull() { + assertEquals(of(1, 2, 3, 4), ofSet4(null, 1, 2, 3, 4)); + } + + @Test + void testOfSet4WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptySet"); + assertEquals(of(1, 2, 3, 4), ofSet4(wrongMethodHandle, 1, 2, 3, 4)); + } + + @Test + void testOfSet5WithNull() { + assertEquals(of(1, 2, 3, 4, 5), ofSet5(null, 1, 2, 3, 4, 5)); + } + + @Test + void testOfSet5WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptySet"); + assertEquals(of(1, 2, 3, 4, 5), ofSet5(wrongMethodHandle, 1, 2, 3, 4, 5)); + } + + @Test + void testOfSet6WithNull() { + assertEquals(of(1, 2, 3, 4, 5, 6), ofSet6(null, 1, 2, 3, 4, 5, 6)); + } + + @Test + void testOfSet6WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptySet"); + assertEquals(of(1, 2, 3, 4, 5, 6), ofSet6(wrongMethodHandle, 1, 2, 3, 4, 5, 6)); + } + + @Test + void testOfSet7WithNull() { + assertEquals(of(1, 2, 3, 4, 5, 6, 7), ofSet7(null, 1, 2, 3, 4, 5, 6, 7)); + } + + @Test + void testOfSet7WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptySet"); + assertEquals(of(1, 2, 3, 4, 5, 6, 7), ofSet7(wrongMethodHandle, 1, 2, 3, 4, 5, 6, 7)); + } + + @Test + void testOfSet8WithNull() { + assertEquals(of(1, 2, 3, 4, 5, 6, 7, 8), ofSet8(null, 1, 2, 3, 4, 5, 6, 7, 8)); + } + + @Test + void testOfSet8WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptySet"); + assertEquals(of(1, 2, 3, 4, 5, 6, 7, 8), ofSet8(wrongMethodHandle, 1, 2, 3, 4, 5, 6, 7, 8)); + } + + @Test + void testOfSet9WithNull() { + assertEquals(of(1, 2, 3, 4, 5, 6, 7, 8, 9), ofSet9(null, 1, 2, 3, 4, 5, 6, 7, 8, 9)); + } + + @Test + void testOfSet9WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptySet"); + assertEquals(of(1, 2, 3, 4, 5, 6, 7, 8, 9), ofSet9(wrongMethodHandle, 1, 2, 3, 4, 5, 6, 7, 8, 9)); + } + + @Test + void testOfSet10WithNull() { + assertEquals(of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ofSet10(null, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + } + + @Test + void testOfSet10WithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptySet"); + assertEquals(of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ofSet10(wrongMethodHandle, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + } + + @Test + void testOfSetElementsWithNull() { + Integer[] elements = {1, 2, 3}; + assertEquals(of(elements), ofSetElements(null, elements)); + } + + @Test + void testOfSetElementsWithWrongMethodHandle() { + MethodHandle wrongMethodHandle = findPublicStatic(java.util.Collections.class, "emptySet"); + Integer[] elements = {1, 2, 3}; + assertEquals(of(elements), ofSetElements(wrongMethodHandle, elements)); + } } \ No newline at end of file