From b6fcfb989cbc9ab34408bd1991f0c5d11dcc52fc Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Wed, 4 Nov 2015 11:12:00 +0300 Subject: [PATCH] convert junit testcase to test-ng improved and fixed according (IDEA-138767) --- .../TypeConversionDescriptor.java | 14 +- .../testng/inspection/JUnitConvertTool.java | 198 ++++++++---------- .../testData/junit/afterBinaryAssertions.java | 23 ++ plugins/testng/testData/junit/afterDelta.java | 14 ++ plugins/testng/testData/junit/afterFail.java | 20 +- .../testData/junit/afterIncompatible.java | 11 + .../testData/junit/afterUnaryAssertions.java | 17 ++ .../junit/beforeBinaryAssertions.java | 28 +++ .../testng/testData/junit/beforeDelta.java | 16 ++ .../testData/junit/beforeIncompatible.java | 13 ++ .../testData/junit/beforeUnaryAssertions.java | 21 ++ .../inspection/BaseTestNGInspectionsTest.java | 2 +- .../ConvertJUnitInspectionTest.java | 16 ++ plugins/testng/testng.iml | 1 + 14 files changed, 270 insertions(+), 124 deletions(-) create mode 100644 plugins/testng/testData/junit/afterBinaryAssertions.java create mode 100644 plugins/testng/testData/junit/afterDelta.java create mode 100644 plugins/testng/testData/junit/afterIncompatible.java create mode 100644 plugins/testng/testData/junit/afterUnaryAssertions.java create mode 100644 plugins/testng/testData/junit/beforeBinaryAssertions.java create mode 100644 plugins/testng/testData/junit/beforeDelta.java create mode 100644 plugins/testng/testData/junit/beforeIncompatible.java create mode 100644 plugins/testng/testData/junit/beforeUnaryAssertions.java diff --git a/java/typeMigration/src/com/intellij/refactoring/typeMigration/TypeConversionDescriptor.java b/java/typeMigration/src/com/intellij/refactoring/typeMigration/TypeConversionDescriptor.java index cf078612db09..3c259544b5db 100644 --- a/java/typeMigration/src/com/intellij/refactoring/typeMigration/TypeConversionDescriptor.java +++ b/java/typeMigration/src/com/intellij/refactoring/typeMigration/TypeConversionDescriptor.java @@ -11,6 +11,7 @@ import com.intellij.structuralsearch.MatchOptions; import com.intellij.structuralsearch.plugin.replace.ReplaceOptions; import com.intellij.structuralsearch.plugin.replace.impl.Replacer; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -81,14 +82,21 @@ public class TypeConversionDescriptor extends TypeConversionDescriptorBase { @Override public PsiExpression replace(PsiExpression expression) { if (getExpression() != null) expression = getExpression(); - final Project project = expression.getProject(); + return replaceExpression(expression, getStringToReplace(), getReplaceByString()); + } + + @NotNull + public static PsiExpression replaceExpression(@NotNull PsiExpression expression, + String stringToReplace, + String replaceByString) { + Project project = expression.getProject(); final ReplaceOptions options = new ReplaceOptions(); final MatchOptions matchOptions = options.getMatchOptions(); matchOptions.setFileType(StdFileTypes.JAVA); final Replacer replacer = new Replacer(project, null); - final String replacement = replacer.testReplace(expression.getText(), getStringToReplace(), getReplaceByString(), options); + final String replacement = replacer.testReplace(expression.getText(), stringToReplace, replaceByString, options); return (PsiExpression)JavaCodeStyleManager.getInstance(project).shortenClassReferences(expression.replace( - JavaPsiFacade.getInstance(project).getElementFactory().createExpressionFromText(replacement, expression))); + JavaPsiFacade.getInstance(project).getElementFactory().createExpressionFromText(replacement, expression))); } @Override diff --git a/plugins/testng/src/com/theoryinpractice/testng/inspection/JUnitConvertTool.java b/plugins/testng/src/com/theoryinpractice/testng/inspection/JUnitConvertTool.java index 546a891582c5..5ace6bb7c33d 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/inspection/JUnitConvertTool.java +++ b/plugins/testng/src/com/theoryinpractice/testng/inspection/JUnitConvertTool.java @@ -24,12 +24,20 @@ import com.intellij.psi.*; import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.util.PsiElementFilter; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.refactoring.typeMigration.TypeConversionDescriptor; +import com.intellij.util.Function; import com.intellij.util.IncorrectOperationException; +import com.intellij.util.SmartList; +import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.containers.HashMap; import com.theoryinpractice.testng.util.TestNGUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; +import java.util.Map; + /** * @author Hani Suleiman Date: Aug 3, 2005 Time: 3:34:56 AM */ @@ -37,8 +45,19 @@ public class JUnitConvertTool extends BaseJavaLocalInspectionTool { private static final Logger LOG = Logger.getInstance("TestNG QuickFix"); private static final String DISPLAY_NAME = "Convert JUnit Tests to TestNG"; + private static final Map ANNOTATIONS_MAP; + public static final String QUICKFIX_NAME = "Convert TestCase to TestNG"; + static { + ANNOTATIONS_MAP = new HashMap(); + ANNOTATIONS_MAP.put("org.junit.Test", "@org.testng.annotations.Test"); + ANNOTATIONS_MAP.put("org.junit.BeforeClass", "@org.testng.annotations.BeforeClass"); + ANNOTATIONS_MAP.put("org.junit.Before", "@org.testng.annotations.BeforeMethod"); + ANNOTATIONS_MAP.put("org.junit.AfterClass", "@org.testng.annotations.AfterClass"); + ANNOTATIONS_MAP.put("org.junit.After", "@org.testng.annotations.AfterMethod"); + } + @NotNull @Override public String getGroupDisplayName() { @@ -91,7 +110,11 @@ public class JUnitConvertTool extends BaseJavaLocalInspectionTool { final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); final PsiJavaFile javaFile = (PsiJavaFile)psiClass.getContainingFile(); + final List convertedElements = new SmartList(); + for (PsiMethod method : psiClass.getMethods()) { + final PsiMethodCallExpression[] methodCalls = getTestCaseCalls(method); + if (method.isConstructor()) { convertJUnitConstructor(method); } @@ -101,94 +124,55 @@ public class JUnitConvertTool extends BaseJavaLocalInspectionTool { } else { if (TestNGUtil.containsJunitAnnotions(method)) { - convertJunitAnnotions(factory, method); + convertedElements.addAll(convertJunitAnnotations(factory, method)); } else { - addMethodAnnotations(factory, method); + convertedElements.add(addMethodAnnotations(factory, method)); } } } - final PsiMethodCallExpression[] methodCalls = getTestCaseCalls(method); for (PsiMethodCallExpression methodCall : methodCalls) { PsiMethod assertMethod = methodCall.resolveMethod(); if (assertMethod == null) { continue; } - PsiAssertStatement assertStatement = null; @NonNls String methodName = assertMethod.getName(); PsiExpression[] expressions = methodCall.getArgumentList().getExpressions(); final PsiStatement methodCallStatement = PsiTreeUtil.getParentOfType(methodCall, PsiStatement.class); LOG.assertTrue(methodCallStatement != null); - if ("assertTrue".equals(methodName) || "assertFalse".equals(methodName)) { - if (expressions.length == 1) { - assertStatement = createAssert(factory, null, methodCall); - final PsiExpression assertCondition = assertStatement.getAssertCondition(); - LOG.assertTrue(assertCondition != null); - assertCondition.replace(expressions[0]); - } - else if (expressions.length == 2) { - assertStatement = createAssert(factory, expressions[0], methodCall); - final PsiExpression assertCondition = assertStatement.getAssertCondition(); - LOG.assertTrue(assertCondition != null); - assertCondition.replace(expressions[1]); - } - - if ("assertFalse".equals(methodName) && assertStatement != null) { - PsiExpression assertCondition = assertStatement.getAssertCondition(); - LOG.assertTrue(assertCondition != null); - assertCondition.replace(factory.createExpressionFromText("!(" + assertCondition.getText() + ')', - PsiTreeUtil.getParentOfType(assertCondition, - PsiMethodCallExpression.class))); - } - } - else if ("assertNull".equals(methodName) || "assertNotNull".equals(methodName)) { - String operator = "assertNull".equals(methodName) ? "==" : "!="; - if (expressions.length == 1) { - assertStatement = createAssert(factory, null, methodCall); - PsiExpression expression = - factory.createExpressionFromText(expressions[0].getText() + ' ' + operator + " null", assertStatement); - final PsiExpression assertCondition = assertStatement.getAssertCondition(); - LOG.assertTrue(assertCondition != null); - assertCondition.replace(expression); - } - else if (expressions.length == 2) { - assertStatement = createAssert(factory, expressions[0], methodCall.getParent()); - PsiExpression expression = - factory.createExpressionFromText(expressions[1].getText() + ' ' + operator + " null", assertStatement); - final PsiExpression assertCondition = assertStatement.getAssertCondition(); - LOG.assertTrue(assertCondition != null); - assertCondition.replace(expression); - } + 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)) { - if (expressions.length == 0) { - assertStatement = createAssert(factory, null, methodCall); - } - else if (expressions.length == 1) { - assertStatement = createAssert(factory, expressions[0], methodCall); - } + 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 { - //if it's a 3 arg, the error message goes at the end - PsiElement inserted = null; - if (expressions.length == 2) { - final PsiExpression qualifierExpression = methodCall.getMethodExpression().getQualifierExpression(); - final String text = "org.testng." + (qualifierExpression == null ? "Assert." : "") + methodCall.getText() + ";"; - inserted = methodCallStatement - .replace(factory.createStatementFromText(text, methodCall.getParent())); - } - else if (expressions.length == 3) { - @NonNls String call = "org.testng.Assert." + methodName + '(' + expressions[2].getText() + ", " + expressions[1].getText() + - ", " + expressions[0].getText() + ");"; - inserted = methodCallStatement.replace(factory.createStatementFromText(call, methodCall.getParent())); - } - if (inserted != null) { - JavaCodeStyleManager.getInstance(project).shortenClassReferences(inserted); + 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$" : "") + ")"; } } - if (assertStatement != null) { - methodCallStatement.replace(assertStatement); - } + convertedElements.add(TypeConversionDescriptor.replaceExpression(methodCall, searchTemplate, replaceTemplate)); } } final PsiClass superClass = psiClass.getSuperClass(); @@ -199,38 +183,47 @@ public class JUnitConvertTool extends BaseJavaLocalInspectionTool { element.delete(); } } - JavaCodeStyleManager.getInstance(project).optimizeImports(javaFile);//delete unused imports + final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project); + codeStyleManager.optimizeImports(javaFile);//delete unused imports + codeStyleManager.shortenClassReferences(javaFile); } catch (IncorrectOperationException e) { LOG.error("Error converting testcase", e); } } - - - private static void convertJunitAnnotions(PsiElementFactory factory, PsiMethod method) throws IncorrectOperationException { - PsiAnnotation[] annotations = method.getModifierList().getAnnotations(); - for (PsiAnnotation annotation : annotations) { - PsiAnnotation newAnnotation = null; - if ("org.junit.Test".equals(annotation.getQualifiedName())) { - newAnnotation = factory.createAnnotationFromText("@org.testng.annotations.Test", method); - } - else if ("org.junit.BeforeClass".equals(annotation.getQualifiedName())) { - newAnnotation = factory.createAnnotationFromText("@org.testng.annotations.BeforeClass", method); - } - else if ("org.junit.Before".equals(annotation.getQualifiedName())) { - newAnnotation = factory.createAnnotationFromText("@org.testng.annotations.BeforeMethod", method); - } - else if ("org.junit.AfterClass".equals(annotation.getQualifiedName())) { - newAnnotation = factory.createAnnotationFromText("@org.testng.annotations.AfterClass", method); - } - else if ("org.junit.After".equals(annotation.getQualifiedName())) { - newAnnotation = factory.createAnnotationFromText("@org.testng.annotations.AfterMethod", method); - } - if (newAnnotation != null) { - JavaCodeStyleManager.getInstance(annotation.getProject()).shortenClassReferences(annotation.replace(newAnnotation)); + private static boolean hasMessage(PsiMethodCallExpression expression) { + final PsiExpression[] expressions = expression.getArgumentList().getExpressions(); + if (expressions.length == 4) { + return true; + } + final PsiMethod method = expression.resolveMethod(); + LOG.assertTrue(method != null); + for (PsiParameter parameter : method.getParameterList().getParameters()) { + final PsiType type = parameter.getType(); + if (type instanceof PsiClassType) { + final PsiClass resolvedClass = ((PsiClassType)type).resolve(); + if (resolvedClass != null && CommonClassNames.JAVA_LANG_STRING.equals(resolvedClass.getQualifiedName())) { + return true; + } } } + return false; + } + + private static List convertJunitAnnotations(final PsiElementFactory factory, final PsiMethod method) throws IncorrectOperationException { + PsiAnnotation[] annotations = method.getModifierList().getAnnotations(); + return ContainerUtil.mapNotNull(annotations, new Function() { + @Override + public PsiElement fun(PsiAnnotation annotation) { + final String testNgAnnotation = ANNOTATIONS_MAP.get(annotation.getQualifiedName()); + if (testNgAnnotation != null) { + final PsiAnnotation newAnnotation = factory.createAnnotationFromText("@org.testng.annotations.Test", method); + return annotation.replace(newAnnotation); + } + return null; + } + }); } private static void convertJUnitConstructor(PsiMethod method) { @@ -336,7 +329,7 @@ public class JUnitConvertTool extends BaseJavaLocalInspectionTool { } } - private static void addMethodAnnotations(PsiElementFactory factory, PsiMethod method) throws IncorrectOperationException { + private static PsiElement addMethodAnnotations(PsiElementFactory factory, PsiMethod method) throws IncorrectOperationException { PsiAnnotation annotation = null; if (method.getName().startsWith("test")) { annotation = factory.createAnnotationFromText("@org.testng.annotations.Test", method); @@ -348,24 +341,9 @@ public class JUnitConvertTool extends BaseJavaLocalInspectionTool { annotation = factory.createAnnotationFromText("@org.testng.annotations.AfterMethod", method); } if (annotation != null) { - JavaCodeStyleManager.getInstance(annotation.getProject()).shortenClassReferences(method.getModifierList().addAfter(annotation, null)); + return method.getModifierList().addAfter(annotation, null); } - } - - private static PsiAssertStatement createAssert(PsiElementFactory factory, PsiExpression description, PsiElement context) - throws IncorrectOperationException { - PsiAssertStatement assertStatement; - if (description == null) { - assertStatement = (PsiAssertStatement)factory.createStatementFromText("assert false;", context.getParent()); - return assertStatement; - } - else { - assertStatement = (PsiAssertStatement)factory.createStatementFromText("assert false : \"x\";", context.getParent()); - final PsiExpression assertDescription = assertStatement.getAssertDescription(); - assert assertDescription != null; - assertDescription.replace(description); - } - return assertStatement; + return null; } } } diff --git a/plugins/testng/testData/junit/afterBinaryAssertions.java b/plugins/testng/testData/junit/afterBinaryAssertions.java new file mode 100644 index 000000000000..329874af175d --- /dev/null +++ b/plugins/testng/testData/junit/afterBinaryAssertions.java @@ -0,0 +1,23 @@ +import org.testng.Assert; +import org.testng.annotations.Test; + +public class SampleTest { + + @Test + public void differentAssertions() { + Assert.assertEquals(true ? new Integer(1) : null, new Integer(1), "message"); + Assert.assertEquals(true ? new Integer(1) : null, new Integer(1)); + Assert.assertNotEquals(new Integer(2), new Integer(1), "message"); + Assert.assertNotEquals(new Integer(2), new Integer(1)); + Assert.assertEquals(true ? new long[0] : null, new long[0], "message"); + Assert.assertEquals(true ? new long[0] : null, new long[0]); + Assert.assertEquals(true ? 1L : 0, 1L); + Assert.assertEquals(true ? 1L : 0, 1L, "message"); + Assert.assertSame(true ? Integer.valueOf(1) : null, (Object) Integer.valueOf(1), "message"); + Assert.assertSame(true ? Integer.valueOf(1) : null, (Object) Integer.valueOf(1)); + Assert.assertNotSame(true ? new Object() : null, new Object(), "message"); + Assert.assertNotSame(true ? new Object() : null, new Object()); + Assert.assertEquals(true ? new Object[0] : null, new Object[0], "message"); + Assert.assertEquals(true ? new Object[0] : null, new Object[0]); + } +} \ No newline at end of file diff --git a/plugins/testng/testData/junit/afterDelta.java b/plugins/testng/testData/junit/afterDelta.java new file mode 100644 index 000000000000..938d3352ebda --- /dev/null +++ b/plugins/testng/testData/junit/afterDelta.java @@ -0,0 +1,14 @@ +import org.testng.AssertJUnit; +import org.testng.annotations.Test; + +public class SampleTest { + + @Test + public void differentAssertions() { + AssertJUnit.assertArrayEquals("message", new double[0], true ? new double[0] : null, 0d); + AssertJUnit.assertArrayEquals(new double[0], true ? new double[0] : null, 0d); + AssertJUnit.assertEquals("message", 0d, 1d, 2d); + AssertJUnit.assertEquals(1d, 2d, 0d); + + } +} \ No newline at end of file diff --git a/plugins/testng/testData/junit/afterFail.java b/plugins/testng/testData/junit/afterFail.java index f4100b8a7b8f..6ecf97d0da5c 100644 --- a/plugins/testng/testData/junit/afterFail.java +++ b/plugins/testng/testData/junit/afterFail.java @@ -1,17 +1,17 @@ import org.testng.Assert; import org.testng.annotations.Test; -public class Testt { +public class Testt { @Test public void test() { - Assert.assertEquals("description", "2", "1"); - assert "" != null; - assert !(false); - assert true : "true"; - Assert.assertNotSame("2", "1", "not same"); - assert null == null; - assert null == null : "description"; - Assert.assertSame("2", "1", "description"); - assert false : "fail"; + Assert.assertEquals("description", "2", "1"); + Assert.assertNotNull(""); + Assert.assertFalse(false); + Assert.assertTrue(true, "true"); + Assert.assertNotSame("2", "1", "not same"); + Assert.assertNull(null); + Assert.assertNull(null, "description"); + Assert.assertSame("2", "1", "description"); + Assert.fail("fail"); } } \ No newline at end of file diff --git a/plugins/testng/testData/junit/afterIncompatible.java b/plugins/testng/testData/junit/afterIncompatible.java new file mode 100644 index 000000000000..f5330e9fd92d --- /dev/null +++ b/plugins/testng/testData/junit/afterIncompatible.java @@ -0,0 +1,11 @@ +import org.hamcrest.Matchers; +import org.testng.annotations.Test; + +public class SampleTest { + + @Test + public void differentAssertions() { + org.hamcrest.MatcherAssert.assertThat(1, Matchers.is(1)); + org.hamcrest.MatcherAssert.assertThat("reason", 1, Matchers.is(1)); + } +} \ No newline at end of file diff --git a/plugins/testng/testData/junit/afterUnaryAssertions.java b/plugins/testng/testData/junit/afterUnaryAssertions.java new file mode 100644 index 000000000000..3fbc7ebb2dd3 --- /dev/null +++ b/plugins/testng/testData/junit/afterUnaryAssertions.java @@ -0,0 +1,17 @@ +import org.testng.Assert; +import org.testng.annotations.Test; + +public class SampleTest { + + @Test + public void differentAssertions() { + Assert.assertTrue(true, "message"); + Assert.assertTrue(true); + Assert.assertFalse(false, "message"); + Assert.assertFalse(false); + Assert.assertNotNull(new Object(), "message"); + Assert.assertNotNull(new Object()); + Assert.assertNull(null, "message"); + Assert.assertNull(null); + } +} \ No newline at end of file diff --git a/plugins/testng/testData/junit/beforeBinaryAssertions.java b/plugins/testng/testData/junit/beforeBinaryAssertions.java new file mode 100644 index 000000000000..7f3694ae69e1 --- /dev/null +++ b/plugins/testng/testData/junit/beforeBinaryAssertions.java @@ -0,0 +1,28 @@ +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; + +public class SampleTest { + + @Test + public void differentAssertions() { + assertEquals("message", new Integer(1), true ? new Integer(1) : null); + assertEquals(new Integer(1), true ? new Integer(1) : null); + assertNotEquals("message", new Integer(1), new Integer(2)); + assertNotEquals(new Integer(1), new Integer(2)); + assertArrayEquals("message", new long[0], true ? new long[0] : null); + assertArrayEquals(new long[0], true ? new long[0] : null); + assertEquals(1L, true ? 1L : 0); + assertEquals("message", 1L, true ? 1L : 0); + assertSame("message", (Object) Integer.valueOf(1), true ? Integer.valueOf(1) : null); + assertSame((Object) Integer.valueOf(1), true ? Integer.valueOf(1) : null); + assertNotSame("message", new Object(), true ? new Object() : null); + assertNotSame(new Object(), true ? new Object() : null); + assertEquals("message", new Object[0], true ? new Object[0] : null); + assertEquals(new Object[0], true ? new Object[0] : null); + } +} \ No newline at end of file diff --git a/plugins/testng/testData/junit/beforeDelta.java b/plugins/testng/testData/junit/beforeDelta.java new file mode 100644 index 000000000000..de06456c89ce --- /dev/null +++ b/plugins/testng/testData/junit/beforeDelta.java @@ -0,0 +1,16 @@ +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +public class SampleTest { + + @Test + public void differentAssertions() { + assertArrayEquals("message", new double[0], true ? new double[0] : null, 0d); + assertArrayEquals(new double[0], true ? new double[0] : null, 0d); + assertEquals("message", 0d, 1d, 2d); + assertEquals(1d, 2d, 0d); + + } +} \ No newline at end of file diff --git a/plugins/testng/testData/junit/beforeIncompatible.java b/plugins/testng/testData/junit/beforeIncompatible.java new file mode 100644 index 000000000000..1e3996539c48 --- /dev/null +++ b/plugins/testng/testData/junit/beforeIncompatible.java @@ -0,0 +1,13 @@ +import org.hamcrest.Matchers; +import org.junit.Test; + +import static org.junit.Assert.assertThat; + +public class SampleTest { + + @Test + public void differentAssertions() { + assertThat(1, Matchers.is(1)); + assertThat("reason", 1, Matchers.is(1)); + } +} \ No newline at end of file diff --git a/plugins/testng/testData/junit/beforeUnaryAssertions.java b/plugins/testng/testData/junit/beforeUnaryAssertions.java new file mode 100644 index 000000000000..9efa37a55189 --- /dev/null +++ b/plugins/testng/testData/junit/beforeUnaryAssertions.java @@ -0,0 +1,21 @@ +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +public class SampleTest { + + @Test + public void differentAssertions() { + assertTrue("message", true); + assertTrue(true); + assertFalse("message", false); + assertFalse(false); + assertNotNull("message", new Object()); + assertNotNull(new Object()); + assertNull("message", null); + assertNull(null); + } +} \ No newline at end of file diff --git a/plugins/testng/testSources/com/theoryinpractice/testng/inspection/BaseTestNGInspectionsTest.java b/plugins/testng/testSources/com/theoryinpractice/testng/inspection/BaseTestNGInspectionsTest.java index 35d85ed73fa2..afa95696cb29 100644 --- a/plugins/testng/testSources/com/theoryinpractice/testng/inspection/BaseTestNGInspectionsTest.java +++ b/plugins/testng/testSources/com/theoryinpractice/testng/inspection/BaseTestNGInspectionsTest.java @@ -56,7 +56,7 @@ public abstract class BaseTestNGInspectionsTest extends JavaCodeInsightFixtureTe break; } } - Assert.assertNotNull(resultAction); + Assert.assertNotNull(resultAction, "action isn't found"); myFixture.launchAction(resultAction); myFixture.checkResultByFile(AFTER + testName + ".java"); } diff --git a/plugins/testng/testSources/com/theoryinpractice/testng/inspection/ConvertJUnitInspectionTest.java b/plugins/testng/testSources/com/theoryinpractice/testng/inspection/ConvertJUnitInspectionTest.java index cd1b15558e70..e02f8ade7510 100644 --- a/plugins/testng/testSources/com/theoryinpractice/testng/inspection/ConvertJUnitInspectionTest.java +++ b/plugins/testng/testSources/com/theoryinpractice/testng/inspection/ConvertJUnitInspectionTest.java @@ -40,6 +40,22 @@ public class ConvertJUnitInspectionTest extends BaseTestNGInspectionsTest { doTest(); } + public void testUnaryAssertions() { + doTest(); + } + + public void testBinaryAssertions() { + doTest(); + } + + public void testIncompatible() { + doTest(); + } + + public void testDelta() { + doTest(); + } + @Override protected String getBasePath() { return PluginPathManager.getPluginHomePathRelative("testng") + "/testData/junit"; diff --git a/plugins/testng/testng.iml b/plugins/testng/testng.iml index c029eb836755..734fff07f107 100644 --- a/plugins/testng/testng.iml +++ b/plugins/testng/testng.iml @@ -25,6 +25,7 @@ +