private void doGenerate( final Editor editor, final PsiFile file, final PsiClass targetClass, final TestFramework framework) { if (framework instanceof JavaTestFramework && ((JavaTestFramework) framework).isSingleConfig()) { PsiElement alreadyExist = null; switch (myMethodKind) { case SET_UP: alreadyExist = framework.findSetUpMethod(targetClass); break; case TEAR_DOWN: alreadyExist = framework.findTearDownMethod(targetClass); break; default: break; } if (alreadyExist instanceof PsiMethod) { editor.getCaretModel().moveToOffset(alreadyExist.getNavigationElement().getTextOffset()); HintManager.getInstance() .showErrorHint( editor, "Method " + ((PsiMethod) alreadyExist).getName() + " already exists"); return; } } if (!CommonRefactoringUtil.checkReadOnlyStatus(file)) return; WriteCommandAction.runWriteCommandAction( file.getProject(), new Runnable() { @Override public void run() { try { PsiDocumentManager.getInstance(file.getProject()).commitAllDocuments(); PsiMethod method = generateDummyMethod(editor, file); if (method == null) return; TestIntegrationUtils.runTestMethodTemplate( myMethodKind, framework, editor, targetClass, method, "name", false, null); } catch (IncorrectOperationException e) { HintManager.getInstance() .showErrorHint(editor, "Cannot generate method: " + e.getMessage()); LOG.warn(e); } } }); }
@Override public void evaluate() throws Throwable { // do multithreaded magic TestFramework.runManyTimes(testCase, runs); // invoke the actual test method afterwards super.evaluate(); }