Error testing inspections

Hi all,
this is my test method:

public class MyInspectionVisitorTest extends LightInspectionTestCase {
    @Nullable
    @Override
    protected
InspectionProfileEntry getInspection() {
        return new MyInspection();
    }
    public void testWithPrimitiveType() {
         doTest("class Bean {\n" +
            "  private int foo;\n" +
            "  public int getFoo() { return foo; }\n" +
            "}");
    }
...
}

and it works fine. But when i change primitive type to any, like String for example.

public void
testNoPrimitiveType() {
    doTest("class Bean {\n" +
            "  private String foo;\n" +
            "  public String getFoo() { return foo; }\n" +
            "}");
}
I got error.

org.junit.ComparisonFailure: X.java: Extra (2:11/6) :'String' (Cannot resolve symbol 'String') [HighlightInfoTypeImpl[severity=ERROR, key=WRONG_REFERENCES_ATTRIBUTES]]
X.java: Extra (3:10/6) :'String' (Cannot resolve symbol 'String') [HighlightInfoTypeImpl[severity=ERROR, key=WRONG_REFERENCES_ATTRIBUTES]]

  <Click to see difference>


     at org.junit.Assert.assertEquals(Assert.java:115)
     at com.intellij.testFramework.ExpectedHighlightingData.compareTexts(ExpectedHighlightingData.java:472)
     at com.intellij.testFramework.ExpectedHighlightingData.checkResult(ExpectedHighlightingData.java:456)
     at com.intellij.testFramework.ExpectedHighlightingData.checkResult(ExpectedHighlightingData.java:407)
     at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.collectAndCheckHighlighting(CodeInsightTestFixtureImpl.java:1670)
     at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.collectAndCheckHighlighting(CodeInsightTestFixtureImpl.java:1632)
     at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.collectAndCheckHighlighting(CodeInsightTestFixtureImpl.java:1624)
     at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.testHighlighting(CodeInsightTestFixtureImpl.java:538)
     at com.siyeh.ig.LightInspectionTestCase.doTest(LightInspectionTestCase.java:90)
     at com.github.profeg.intellijGetterBooleanInspection.GetterBooleanInspectionVisitorTest.testNoPrimitiveType(GetterBooleanInspectionVisitorTest.java:16)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     at java.lang.reflect.Method.invoke(Method.java:497)
     at junit.framework.TestCase.runTest(TestCase.java:176)
     at com.intellij.testFramework.UsefulTestCase.access$001(UsefulTestCase.java:81)
     at com.intellij.testFramework.UsefulTestCase$2.run(UsefulTestCase.java:319)
     at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$2.invoke(EdtTestUtil.kt:29)
     at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$2.invoke(EdtTestUtil.kt:23)
     at com.intellij.testFramework.EdtTestUtil$Companion.runInEdtAndWait(EdtTestUtil.kt:37)
     at com.intellij.testFramework.EdtTestUtil$Companion.runInEdtAndWait(EdtTestUtil.kt:29)
     at com.intellij.testFramework.EdtTestUtil.runInEdtAndWait(EdtTestUtil.kt)
     at com.intellij.testFramework.UsefulTestCase.invokeTestRunnable(UsefulTestCase.java:351)
     at com.intellij.testFramework.UsefulTestCase.runTest(UsefulTestCase.java:335)
     at com.intellij.testFramework.UsefulTestCase.defaultRunBare(UsefulTestCase.java:362)
     at com.intellij.testFramework.UsefulTestCase$3.run(UsefulTestCase.java:419)
     at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$1.invoke(EdtTestUtil.kt:25)
     at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$1.invoke(EdtTestUtil.kt:23)
     at com.intellij.testFramework.EdtTestUtilKt$sam$Runnable$a15fd9f8.run(EdtTestUtil.kt)
     at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:301)
     at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
     at java.awt.EventQueue.access$500(EventQueue.java:97)
     at java.awt.EventQueue$3.run(EventQueue.java:709)
     at java.awt.EventQueue$3.run(EventQueue.java:703)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
     at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
     at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:360)
     at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
     at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
     at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Any ideas?
1 comment
Comment actions Permalink

You have to provide a JDK for your your test. Override getProjectDescriptor(), and supply a valid path in getSdk():

@Override
@NotNull
protected LightProjectDescriptor getProjectDescriptor() {
return new DefaultLightProjectDescriptor() {
@Override
public Sdk getSdk() {
return JavaSdk.getInstance().createJdk("jdk-1.8", "C:\\Program Files\\Java\\jdk1.8.0_112\\jre");
}

@Override
public void configureModule(@NotNull final Module module, @NotNull final ModifiableRootModel model, @NotNull final ContentEntry contentEntry) {
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_1_8);
}
};
}

 

See https://github.com/Omikron-Data-Quality-GmbH/equals-and-hashcode-reloaded/blob/master/src/test/java/net/omikron/FieldNotUsedInEqualsHashCodeInspectionTest.java for a full example.

 

 

0

Please sign in to leave a comment.