use of com.amazonaws.xray.exceptions.AlreadyEmittedException in project aws-xray-sdk-java by aws.
the class EntityTest method numberOfMutatingMethodsThatThrewException.
private MutatingMethodCount numberOfMutatingMethodsThatThrewException(Entity entity, Class klass) {
int numberOfMutatingMethods = 0;
int numberOfMutatingMethodsThatThrewException = 0;
for (Method m : klass.getMethods()) {
if (mutatingMethodPrefixes.stream().anyMatch((prefix) -> {
return m.getName().startsWith(prefix);
})) {
numberOfMutatingMethods++;
try {
List<Parameter> parameters = Arrays.asList(m.getParameters());
List<? extends Object> arguments = parameters.stream().map((parameter) -> {
try {
Class<?> argumentClass = parameter.getType();
if (boolean.class.equals(argumentClass)) {
return false;
} else if (double.class.equals(argumentClass)) {
return 0.0d;
} else {
return argumentClass.getConstructor().newInstance();
}
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
}
return null;
}).collect(Collectors.toList());
m.invoke(entity, arguments.toArray());
} catch (InvocationTargetException ite) {
if (ite.getCause() instanceof AlreadyEmittedException) {
numberOfMutatingMethodsThatThrewException++;
}
} catch (IllegalAccessException e) {
}
}
}
return new MutatingMethodCount(numberOfMutatingMethods, numberOfMutatingMethodsThatThrewException);
}
Aggregations