void (@NotNull Project project, PsiClass psiClass) { try { final PsiManager manager = PsiManager.getInstance(project); final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); final PsiJavaFile javaFile = (PsiJavaFile)psiClass.getContainingFile(); for (PsiMethod method : psiClass.getMethods()) { final PsiMethodCallExpression[] methodCalls = getTestCaseCalls(method); if (method.isConstructor()) { convertJUnitConstructor(method); } else { if (!javaFile.getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_5)) { addMethodJavadoc(factory, method); } else { if (TestNGUtil.containsJunitAnnotations(method)) { convertJunitAnnotations(factory, method); } else { addMethodAnnotations(factory, method); } } } for (PsiMethodCallExpression methodCall : methodCalls) { PsiMethod assertMethod = methodCall.resolveMethod(); if (assertMethod == null) { continue; } @NonNls String methodName = assertMethod.getName(); PsiExpression[] expressions = methodCall.getArgumentList().getExpressions(); final PsiStatement methodCallStatement = PsiTreeUtil.getParentOfType(methodCall, PsiStatement.class); LOG.assertTrue(methodCallStatement != null); final String qualifierTemplate = methodCall.getMethodExpression().getQualifierExpression() != null ? "$qualifier$." : ""; final String searchTemplate; final String replaceTemplate; if ("assertNull".equals(methodName) || "assertNotNull".equals(methodName) || "assertTrue".equals(methodName) || "assertFalse".equals(methodName)) { boolean hasMessage = expressions.length == 2; searchTemplate = qualifierTemplate + "$method$($object$ " + (hasMessage ? ",$msg$" : "") + ")"; replaceTemplate = "org.testng.Assert.$method$(" + (hasMessage ? "$msg$," : "") + "$object$)"; } else if ("fail".equals(methodName)) { boolean hasMessage = expressions.length == 1; searchTemplate = qualifierTemplate + "$method$(" + (hasMessage ? "$msg$" : "") + ")"; replaceTemplate = "org.testng.Assert.$method$(" + (hasMessage ? "$msg$" : "") + ")"; } else if ("assertThat".equals(methodName)) { String paramTemplate = (expressions.length == 3 ? "$msg$," : "") + "$actual$, $matcher$"; searchTemplate = qualifierTemplate + "assertThat(" + paramTemplate + ")"; replaceTemplate = "org.hamcrest.MatcherAssert.assertThat(" + paramTemplate +")"; } else { boolean hasMessage = hasMessage(methodCall); if ((hasMessage && expressions.length == 4) || (!hasMessage && expressions.length == 3)) { searchTemplate = qualifierTemplate + "$method$"; replaceTemplate = "org.testng.AssertJUnit.$method$"; } else { String replaceMethodWildCard = "$method$"; if (methodName.equals("assertArrayEquals")) { replaceMethodWildCard = "assertEquals"; } searchTemplate = qualifierTemplate + "$method$(" + (hasMessage ? "$msg$, " : "") + "$expected$, $actual$" + ")"; replaceTemplate = "org.testng.Assert." + replaceMethodWildCard + "($actual$, $expected$ " + (hasMessage ? ", $msg$" : "") + ")"; } } TypeConversionDescriptor.replaceExpression(methodCall, searchTemplate, replaceTemplate); } } final PsiClass superClass = psiClass.getSuperClass(); if (superClass != null && "junit.framework.TestCase".equals(superClass.getQualifiedName())) { final PsiReferenceList extendsList = psiClass.getExtendsList(); LOG.assertTrue(extendsList != null); for (PsiJavaCodeReferenceElement element : extendsList.getReferenceElements()) { element.delete(); } } final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project); codeStyleManager.optimizeImports(javaFile);//delete unused imports codeStyleManager.shortenClassReferences(javaFile); } catch (IncorrectOperationException e) { LOG.error("Error converting testcase", e); } }