/** * Finds a method using the ASM method node * * @param methodNode The ASM method node, not null * @return The method, null if not found */ protected Method getMethod(MethodInsnNode methodNode) { String internalClassName = methodNode.owner; String className = internalClassName.replace('/', '.'); String methodName = methodNode.name; String methodDescriptor = methodNode.desc; Class<?> clazz = getClassWithName(className); Method[] methods = clazz.getMethods(); for (Method method : methods) { if (methodName.equals(method.getName()) && methodDescriptor.equals(getMethodDescriptor(method))) { return method; } } return null; }
public static StackTraceElement[] getInvocationStackTrace(Class<?> invokedInterface, boolean included) { StackTraceElement[] currentStackTrace = Thread.currentThread().getStackTrace(); for (int i = currentStackTrace.length - 1; i >= 0; i--) { String className = currentStackTrace[i].getClassName(); Class<?> clazz; try { clazz = getClassWithName(className); } catch (UnitilsException e) { // unable to load class, this should never happen for the class we are looking for continue; } if (invokedInterface.isAssignableFrom(clazz) || isProxyClassName(className)) { int index = included ? i : i + 1; return getStackTraceStartingFrom(currentStackTrace, index); } } return null; }
/** * @param configuration The Unitils configuration, not null */ public void init(Properties configuration) { super.init(configuration); String configurationImplClassName = getString(PROPKEY_CONFIGURATION_CLASS_NAME, configuration); configurationObjectClass = ReflectionUtils.getClassWithName(configurationImplClassName); }
/** * @return The default {@link DataSetFactory} class as configured in unitils */ protected DataSetFactory getDefaultDataSetFactory() { Class<? extends DataSetFactory> dataSetFactoryClass = getClassWithName(getAnnotationPropertyDefault(DbUnitModule.class, DataSet.class, "factory", configuration)); return getDataSetFactory(dataSetFactoryClass); }
/** * @return The default {@link DataSetLoadStrategy} class as configured in unitils */ protected DataSetLoadStrategy getDefaultDataSetLoadStrategy() { Class<? extends DataSetLoadStrategy> dataSetLoadStrategyClassName = getClassWithName(getAnnotationPropertyDefault(DbUnitModule.class, DataSet.class, "loadStrategy", configuration)); return createInstanceOfType(dataSetLoadStrategyClassName, false); }
/** * Locates the argument matchers for the given proxy method invocation. * * @param proxyInvocation The method invocation, not null * @param fromLineNr The begin line-nr of the invocation * @param toLineNr The end line-nr of the invocation (could be different from the begin line-nr if the invocation is written on more than 1 line) * @param index The index of the matcher on that line, 1 for the first, 2 for the second etc * @return The argument indexes, empty if there are no matchers */ public static List<Integer> getArgumentMatcherIndexes(ProxyInvocation proxyInvocation, int fromLineNr, int toLineNr, int index) { Class<?> testClass = getClassWithName(proxyInvocation.getInvokedAt().getClassName()); String testMethodName = proxyInvocation.getInvokedAt().getMethodName(); Method method = proxyInvocation.getMethod(); return getArgumentMatcherIndexes(testClass, testMethodName, method, fromLineNr, toLineNr, index); }