mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-24 11:20:26 +08:00
allow constructor with parameter of same type as class under constructing
This commit is contained in:
parent
4f3e3f0093
commit
8ebe2a5d0c
@ -204,7 +204,7 @@ public class OmniConstructor {
|
||||
} else {
|
||||
Object[] args = new Object[types.length];
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
args[i] = newInstance(types[i], classPool, level + 1);
|
||||
args[i] = types[i].equals(clazz) ? null : newInstance(types[i], classPool, level + 1);
|
||||
}
|
||||
return constructor.newInstance(args);
|
||||
}
|
||||
@ -217,7 +217,7 @@ public class OmniConstructor {
|
||||
Class<?>[] types = constructor.getParameterTypes();
|
||||
if (types.length == 1 && types[0].equals(Void.class)) {
|
||||
return constructor;
|
||||
} else if (types.length < minimalParametersSize && !anyMatch(types, clazz)) {
|
||||
} else if (types.length < minimalParametersSize) {
|
||||
minimalParametersSize = types.length;
|
||||
bestConstructor = constructor;
|
||||
}
|
||||
@ -225,16 +225,4 @@ public class OmniConstructor {
|
||||
return bestConstructor;
|
||||
}
|
||||
|
||||
private static boolean anyMatch(Class<?>[] types, Class<?> clazz) {
|
||||
for (Class<?> t : types) {
|
||||
if (clazz.getName().equals(t.getName())) {
|
||||
return true;
|
||||
}
|
||||
if (clazz.getSuperclass() != null && clazz.getSuperclass().getName().equals(t.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user