Skip to content

Commit

Permalink
优化beanTest,分析实际执行方法
Browse files Browse the repository at this point in the history
  • Loading branch information
leaderli committed Aug 20, 2024
1 parent 7b7c9e0 commit fa5aefe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.lang.reflect.Method;
import java.util.function.Supplier;

public class BeanMethod {
public class BeanMethod implements Supplier<Object> {

public final Object instance;
public final Method method;
Expand All @@ -21,4 +21,9 @@ public BeanMethod(Object instance, Method method, Supplier<Object> supplier) {
public String toString() {
return ClassUtil.shortName(method.getDeclaringClass()) + "#" + method.getName();
}

@Override
public Object get() {
return supplier.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContex
for (Method method : methods) {
if (instance != null || ModifierUtil.isStatic(method)) {
Object[] args = ArrayUtils.map(method.getParameterTypes(), Object.class, c -> PrimitiveEnum.get(c).zero_value);
Supplier<Object> testSupplier = () -> PrimitiveEnum.get(method.getReturnType()).read(RuntimeExceptionTransfer.get(() -> method.invoke(instance, args)));
Supplier<Object> testSupplier = () -> PrimitiveEnum.get(method.getReturnType()).read(RuntimeExceptionTransfer.get(() -> {
method.setAccessible(true);
return method.invoke(instance, args);
}));
BeanMethod beanMethod = new BeanMethod(instance, method, testSupplier);
MyTestTemplateInvocationContext templateInvocationContext = new MyTestTemplateInvocationContext(beanMethod);
invocationContexts.add(templateInvocationContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public void setGender(Integer gender) {
this.gender = gender;
}

private void privateMethod() {
this.age = 11;
}

@SuppressWarnings("InnerClassMayBeStatic")
private class Inner {
private String name = "1";
Expand Down

0 comments on commit fa5aefe

Please sign in to comment.