/** * Get tests for tested method that have filled rules rows data for testing * its functionality. Run methods and tests with empty test cases are not * being processed. If you need to get all test methods, including run * methods and empty ones, use * {@link #isTestForMethod(IOpenMethod, IOpenMethod)}. */ public static IOpenMethod[] testers(IOpenMethod tested) { List<IOpenMethod> res = new ArrayList<IOpenMethod>(); for (IOpenMethod tester : tested.getDeclaringClass().getMethods()) { if (isTester(tester) && isTestForMethod(tester, tested)) { res.add(tester); } } return res.toArray(new IOpenMethod[res.size()]); }
/** * Gets all test methods for method by uri. * * @param tableUri uri for method table * @return all test methods, including tests with test cases, runs with * filled runs, tests without cases(empty), runs without any * parameters and tests without cases and runs. */ public IOpenMethod[] getTestAndRunMethods(String tableUri) { IOpenMethod method = getMethod(tableUri); if (method != null) { List<IOpenMethod> res = new ArrayList<IOpenMethod>(); Collection<IOpenMethod> methods = compiledOpenClass.getOpenClassWithErrors().getMethods(); for (IOpenMethod tester : methods) { if (ProjectHelper.isTestForMethod(tester, method)) { res.add(tester); } } return res.toArray(new IOpenMethod[0]); } return null; }
/** * Gets all test methods for method by uri. * * @param tableUri uri for method table * @return all test methods, including tests with test cases, runs with * filled runs, tests without cases(empty), runs without any * parameters and tests without cases and runs. */ public IOpenMethod[] getTestAndRunMethods(String tableUri) { IOpenMethod method = getMethod(tableUri); if (method != null) { List<IOpenMethod> res = new ArrayList<IOpenMethod>(); Collection<IOpenMethod> methods = compiledOpenClass.getOpenClassWithErrors().getMethods(); for (IOpenMethod tester : methods) { if (ProjectHelper.isTestForMethod(tester, method)) { res.add(tester); } } return res.toArray(new IOpenMethod[0]); } return null; }
/** * If tester is an instance of {@link TestSuiteMethod} and tested method * object in tester is equal to tested we consider tester is test for tested * method. */ public static boolean isTestForMethod(IOpenMethod tester, IOpenMethod tested) { if (!(tester instanceof TestSuiteMethod)) { return false; } IOpenMethod toTest = ((TestSuiteMethod) tester).getTestedMethod(); if (toTest == tested) { return true; } if (toTest instanceof OpenMethodDispatcher) { if (((OpenMethodDispatcher) toTest).getCandidates().contains(tested)) { return true; } } if (tested instanceof MethodDelegator) { return isTestForMethod(tester, tested.getMethod()); } if (tested instanceof OpenMethodDispatcher) { return isTestForMethod(tester, ((OpenMethodDispatcher) tested).getTargetMethod()); } return false; }