From f5f360bc6ec72d784b4ca3ccb2f10d9de2f594f9 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Sun, 31 Dec 2017 12:46:45 +0100 Subject: [PATCH] IG: check constructor calls to support JMockit (IDEA-184438) --- .../codeInspection/inspection-black-list.txt | 1 - ...tMethodWithoutAssertionInspectionBase.java | 21 ++++----------- .../TestMethodWithoutAssertion.java | 10 +++++++ ...tMethodWithoutAssertionInspectionTest.java | 27 +++++++++---------- 4 files changed, 27 insertions(+), 32 deletions(-) diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/inspection-black-list.txt b/platform/analysis-impl/src/com/intellij/codeInspection/inspection-black-list.txt index 1b5fa78a2466..08124d458e19 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/inspection-black-list.txt +++ b/platform/analysis-impl/src/com/intellij/codeInspection/inspection-black-list.txt @@ -137,7 +137,6 @@ com.siyeh.ig.javabeans.ClassWithoutNoArgConstructorInspection com.siyeh.ig.javadoc.UnnecessaryJavaDocLinkInspection com.siyeh.ig.jdk.AutoBoxingInspection com.siyeh.ig.junit.TestCaseWithNoTestMethodsInspection -com.siyeh.ig.junit.TestMethodWithoutAssertionInspection com.siyeh.ig.logging.ClassWithMultipleLoggersInspection com.siyeh.ig.logging.ClassWithoutLoggerInspection com.siyeh.ig.logging.LoggerInitializedWithForeignClassInspection diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/TestMethodWithoutAssertionInspectionBase.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/TestMethodWithoutAssertionInspectionBase.java index 710d3734745a..be3e7c13de22 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/TestMethodWithoutAssertionInspectionBase.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/junit/TestMethodWithoutAssertionInspectionBase.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.siyeh.ig.junit; @@ -34,7 +22,7 @@ public class TestMethodWithoutAssertionInspectionBase extends BaseInspection { @SuppressWarnings("PublicField") public boolean assertKeywordIsAssertion; public TestMethodWithoutAssertionInspectionBase() { - methodMatcher = new MethodMatcher(true, "assertionMethods") + methodMatcher = new MethodMatcher(false, "assertionMethods") .add(JUnitCommonClassNames.ORG_JUNIT_ASSERT, "assert.*|fail.*") .add(JUnitCommonClassNames.JUNIT_FRAMEWORK_ASSERT, "assert.*|fail.*") .add(JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_ASSERTIONS, "assert.*|fail.*") @@ -45,6 +33,7 @@ public class TestMethodWithoutAssertionInspectionBase extends BaseInspection { .add("org.mockito.InOrder", "verify") .add("org.junit.rules.ExpectedException", "expect.*") .add("org.hamcrest.MatcherAssert", "assertThat") + .add("mockit.Verifications", "Verifications") .finishDefault(); } @@ -150,11 +139,11 @@ public class TestMethodWithoutAssertionInspectionBase extends BaseInspection { } @Override - public void visitMethodCallExpression(@NotNull PsiMethodCallExpression call) { + public void visitCallExpression(@NotNull PsiCallExpression call) { if (containsAssertion) { return; } - super.visitMethodCallExpression(call); + super.visitCallExpression(call); if (methodMatcher.matches(call)) { containsAssertion = true; } diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/test_method_without_assertion/TestMethodWithoutAssertion.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/test_method_without_assertion/TestMethodWithoutAssertion.java index 7660fa6d4045..4c93835931b4 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/test_method_without_assertion/TestMethodWithoutAssertion.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/test_method_without_assertion/TestMethodWithoutAssertion.java @@ -3,6 +3,7 @@ package com.siyeh.igtest.junit; import junit.framework.TestCase; import org.junit.Test; import org.junit.Assert; +import mockit.*; public class TestMethodWithoutAssertion extends TestCase { @@ -57,4 +58,13 @@ public class TestMethodWithoutAssertion extends TestCase private void check() { Assert.assertTrue(true); } + + @Test + public void testExecuteReverseAcknowledgement(@Mocked final Object messageDAO) { + System.out.println(messageDAO); + + new Verifications() {{ + messageDAO.toString(); + }}; + } } diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/TestMethodWithoutAssertionInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/TestMethodWithoutAssertionInspectionTest.java index 4178db05223e..ccdd97deec99 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/TestMethodWithoutAssertionInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/junit/TestMethodWithoutAssertionInspectionTest.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.siyeh.ig.junit; @@ -54,9 +42,18 @@ public class TestMethodWithoutAssertionInspectionTest extends LightInspectionTes "}", "package junit.framework;" + - "public abstract class TestCase extends Assert {}" - }; + "public abstract class TestCase extends Assert {}", + "package mockit;" + + "public abstract class Verifications {" + + " protected Verifications() {}" + + "}", + + "package mockit;" + + "@java.lang.annotation.Retention(value=RUNTIME)\n" + + "@java.lang.annotation.Target(value={FIELD,PARAMETER})" + + "public @interface Mocked {}" + }; } @Nullable