diff --git a/demo/java-demo/src/main/java/com/alibaba/demo/basic/DemoPrivateAccess.java b/demo/java-demo/src/main/java/com/alibaba/demo/basic/DemoPrivateAccess.java index 92eb513..5d7bbf4 100644 --- a/demo/java-demo/src/main/java/com/alibaba/demo/basic/DemoPrivateAccess.java +++ b/demo/java-demo/src/main/java/com/alibaba/demo/basic/DemoPrivateAccess.java @@ -46,7 +46,9 @@ public class DemoPrivateAccess { * private member method with arguments */ private String privateFuncWithArgs(List list, String str, int i) { - return list.stream().reduce((a, s) -> a + s).orElse("") + " + " + str + " + " + i; + return list.stream().reduce((a, s) -> a + s).orElse("") + + " + " + (str == null ? "null" : str) + + " + " + i; } } diff --git a/demo/java-demo/src/test/java/com/alibaba/demo/basic/DemoPrivateAccessorTest.java b/demo/java-demo/src/test/java/com/alibaba/demo/basic/DemoPrivateAccessorTest.java index ab04136..a9dac20 100644 --- a/demo/java-demo/src/test/java/com/alibaba/demo/basic/DemoPrivateAccessorTest.java +++ b/demo/java-demo/src/test/java/com/alibaba/demo/basic/DemoPrivateAccessorTest.java @@ -52,7 +52,13 @@ class DemoPrivateAccessorTest { void should_use_null_parameter() { set(demoPrivateAccess, "pi", null); assertNull(get(demoPrivateAccess, "pi")); - assertEquals("null + 1", invokeStatic(DemoPrivateAccess.class, "privateStaticFuncWithArgs", null, 1)); + + List list = new ArrayList() {{ add("a"); add("b"); add("c"); }}; + String value = invoke(demoPrivateAccess, "privateFuncWithArgs", list, null, 0); + assertEquals("abc + null + 0", value); + + value = invokeStatic(DemoPrivateAccess.class, "privateStaticFuncWithArgs", null, 1); + assertEquals("null + 1", value); } } diff --git a/testable-core/src/main/java/com/alibaba/testable/core/tool/PrivateAccessor.java b/testable-core/src/main/java/com/alibaba/testable/core/tool/PrivateAccessor.java index 645d7fd..1e08c56 100644 --- a/testable-core/src/main/java/com/alibaba/testable/core/tool/PrivateAccessor.java +++ b/testable-core/src/main/java/com/alibaba/testable/core/tool/PrivateAccessor.java @@ -109,10 +109,10 @@ public class PrivateAccessor { } Class commonClass = cls[0]; for (int i = 1; i < cls.length; i++) { - if (cls[i].isPrimitive()) { - return null; - } else if (cls[i] == null) { + if (cls[i] == null) { continue; + } else if (cls[i].isPrimitive()) { + return null; } commonClass = getCommonClassOf(commonClass, cls[i]); }