diff --git a/java/java-tests/testData/inspection/testOnly/constructor/expected.xml b/java/java-tests/testData/inspection/testOnly/constructor/expected.xml
new file mode 100644
index 000000000000..6845ecd4c261
--- /dev/null
+++ b/java/java-tests/testData/inspection/testOnly/constructor/expected.xml
@@ -0,0 +1,17 @@
+
+
+
+ B.java
+ 5
+
+ A()
+ A()
+ <default>
+
+ A
+ A
+
+
+ Test-only method is called in production code
+
+
diff --git a/java/java-tests/testData/inspection/testOnly/constructor/src/A.java b/java/java-tests/testData/inspection/testOnly/constructor/src/A.java
new file mode 100644
index 000000000000..e96e056615e2
--- /dev/null
+++ b/java/java-tests/testData/inspection/testOnly/constructor/src/A.java
@@ -0,0 +1,6 @@
+public class A {
+ @org.jetbrains.annotations.TestOnly
+ public A() {}
+
+ public A(String ignore) {}
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/testOnly/constructor/src/B.java b/java/java-tests/testData/inspection/testOnly/constructor/src/B.java
new file mode 100644
index 000000000000..277a4cda341f
--- /dev/null
+++ b/java/java-tests/testData/inspection/testOnly/constructor/src/B.java
@@ -0,0 +1,8 @@
+import org.jetbrains.annotations.TestOnly;
+
+public class B {
+ public void foo() {
+ new A();
+ new A("ignore");
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/testOnly/insideInner/expected.xml b/java/java-tests/testData/inspection/testOnly/insideInner/expected.xml
new file mode 100644
index 000000000000..d4d91ff59e22
--- /dev/null
+++ b/java/java-tests/testData/inspection/testOnly/insideInner/expected.xml
@@ -0,0 +1,18 @@
+
+
+
+ A.java
+ 17
+
+ void production()
+ production()
+ <default>
+
+ A
+ A
+
+
+ Test-only method is called in production code
+
+
+
diff --git a/java/java-tests/testData/inspection/testOnly/insideInner/src/A.java b/java/java-tests/testData/inspection/testOnly/insideInner/src/A.java
new file mode 100644
index 000000000000..5c3cd06b5896
--- /dev/null
+++ b/java/java-tests/testData/inspection/testOnly/insideInner/src/A.java
@@ -0,0 +1,21 @@
+public class A {
+ @org.jetbrains.annotations.TestOnly
+ public void foo() {}
+
+ @org.jetbrains.annotations.TestOnly
+ public void test() {
+ new Runnable() {
+ public void run() {
+ foo();
+ }
+ };
+ }
+
+ public void production() {
+ new Runnable() {
+ public void run() {
+ foo();
+ }
+ };
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/testOnly/insideInner/src/C.java b/java/java-tests/testData/inspection/testOnly/insideInner/src/C.java
new file mode 100644
index 000000000000..f7a819544f4d
--- /dev/null
+++ b/java/java-tests/testData/inspection/testOnly/insideInner/src/C.java
@@ -0,0 +1,10 @@
+public class C {
+ @org.junit.Test
+ public void foo() {
+ new Runnable() {
+ public void run() {
+ new A().foo();
+ }
+ };
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/testOnly/insideInner/test/D.java b/java/java-tests/testData/inspection/testOnly/insideInner/test/D.java
new file mode 100644
index 000000000000..85262a057b5f
--- /dev/null
+++ b/java/java-tests/testData/inspection/testOnly/insideInner/test/D.java
@@ -0,0 +1,11 @@
+import org.jetbrains.annotations.TestOnly;
+
+public class D {
+ public void test() {
+ new Runnable() {
+ public void run() {
+ new A().foo();
+ }
+ };
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/testOnly/simple/expected.xml b/java/java-tests/testData/inspection/testOnly/simple/expected.xml
new file mode 100644
index 000000000000..e58ea407e9c0
--- /dev/null
+++ b/java/java-tests/testData/inspection/testOnly/simple/expected.xml
@@ -0,0 +1,33 @@
+
+
+
+ A.java
+ 6
+
+ void production()
+ production()
+ <default>
+
+ A
+ A
+
+
+ Test-only method is called in production code
+
+
+
+ B.java
+ 3
+
+ void production()
+ production()
+ <default>
+
+ B
+ B
+
+
+ Test-only method is called in production code
+
+
+
diff --git a/java/java-tests/testData/inspection/testOnly/simple/src/A.java b/java/java-tests/testData/inspection/testOnly/simple/src/A.java
new file mode 100644
index 000000000000..3a35d4059a21
--- /dev/null
+++ b/java/java-tests/testData/inspection/testOnly/simple/src/A.java
@@ -0,0 +1,8 @@
+public class A {
+ @org.jetbrains.annotations.TestOnly
+ public void test() {}
+
+ public void production() {
+ test();
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/testOnly/simple/src/B.java b/java/java-tests/testData/inspection/testOnly/simple/src/B.java
new file mode 100644
index 000000000000..18096db185dc
--- /dev/null
+++ b/java/java-tests/testData/inspection/testOnly/simple/src/B.java
@@ -0,0 +1,10 @@
+public class B {
+ public void production() {
+ new A().test();
+ }
+
+ @org.jetbrains.annotations.TestOnly
+ public void test() {
+ new A().test();
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/testOnly/simple/src/C.java b/java/java-tests/testData/inspection/testOnly/simple/src/C.java
new file mode 100644
index 000000000000..f61a2529def3
--- /dev/null
+++ b/java/java-tests/testData/inspection/testOnly/simple/src/C.java
@@ -0,0 +1,6 @@
+public class C {
+ @org.junit.Test
+ public void foo() {
+ new A().test();
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/testOnly/simple/test/D.java b/java/java-tests/testData/inspection/testOnly/simple/test/D.java
new file mode 100644
index 000000000000..bb6fc9142c98
--- /dev/null
+++ b/java/java-tests/testData/inspection/testOnly/simple/test/D.java
@@ -0,0 +1,7 @@
+import org.jetbrains.annotations.TestOnly;
+
+public class D {
+ public void foo() {
+ new A().test();
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/testOnly/unresolved/expected.xml b/java/java-tests/testData/inspection/testOnly/unresolved/expected.xml
new file mode 100644
index 000000000000..4704d91e891d
--- /dev/null
+++ b/java/java-tests/testData/inspection/testOnly/unresolved/expected.xml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/testOnly/unresolved/src/A.java b/java/java-tests/testData/inspection/testOnly/unresolved/src/A.java
new file mode 100644
index 000000000000..99d34078bb2b
--- /dev/null
+++ b/java/java-tests/testData/inspection/testOnly/unresolved/src/A.java
@@ -0,0 +1,7 @@
+import org.jetbrains.annotations.TestOnly;
+
+public class A {
+ public void foo() {
+ unresolved();
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/TestOnlyInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/TestOnlyInspectionTest.java
new file mode 100644
index 000000000000..91b0ee7db989
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/TestOnlyInspectionTest.java
@@ -0,0 +1,47 @@
+package com.intellij.codeInspection;
+
+import com.intellij.analysis.AnalysisScope;
+import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
+import com.intellij.codeInspection.testOnly.TestOnlyInspection;
+import com.intellij.openapi.vfs.LocalFileSystem;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.testFramework.InspectionTestCase;
+import com.intellij.testFramework.PsiTestUtil;
+import org.jetbrains.annotations.NotNull;
+
+public class TestOnlyInspectionTest extends InspectionTestCase {
+ @Override
+ protected void setupRootModel(String testDir, VirtualFile[] sourceDir, String jdkName) {
+ super.setupRootModel(testDir, sourceDir, jdkName);
+ VirtualFile projectDir = LocalFileSystem.getInstance().findFileByPath(testDir);
+ VirtualFile test = projectDir.findChild("test");
+ if (test != null) PsiTestUtil.addSourceRoot(myModule, test, true);
+ }
+
+ @NotNull
+ @Override
+ protected AnalysisScope createAnalysisScope(VirtualFile sourceDir) {
+ return new AnalysisScope(myModule);
+ }
+
+ public void testSimple() throws Exception {
+ doTest();
+ }
+
+ public void testInsideInner() throws Exception {
+ doTest();
+ }
+
+ public void testConstructor() throws Exception {
+ doTest();
+ }
+
+ public void testUnresolved() throws Exception {
+ doTest(); // shouldn't throw
+ }
+
+ private void doTest() throws Exception {
+ TestOnlyInspection i = new TestOnlyInspection();
+ doTest("testOnly/" + getTestName(true), new LocalInspectionToolWrapper(i), "java 1.5");
+ }
+}
\ No newline at end of file