diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/AllGroovyTestSuite.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/AllGroovyTestSuite.java new file mode 100644 index 000000000000..fc3b8a862b86 --- /dev/null +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/AllGroovyTestSuite.java @@ -0,0 +1,12 @@ +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.plugins.groovy; + +import org.jetbrains.plugins.groovy.util.AllTestsSuite; +import org.jetbrains.plugins.groovy.util.SlowPolicy; +import org.jetbrains.plugins.groovy.util.TestPackage; +import org.junit.runner.RunWith; + +@RunWith(AllTestsSuite.class) +@TestPackage(value = "org.jetbrains.plugins.groovy", policy = SlowPolicy.ALL) +public class AllGroovyTestSuite { +} diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/CompoundTestLibrary.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/CompoundTestLibrary.java index b7e946e35a47..39112505fa0c 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/CompoundTestLibrary.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/CompoundTestLibrary.java @@ -1,25 +1,21 @@ -// Copyright 2000-2019 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 org.jetbrains.plugins.groovy +package org.jetbrains.plugins.groovy; -import com.intellij.openapi.module.Module -import com.intellij.openapi.roots.ModifiableRootModel -import groovy.transform.CompileStatic -import org.jetbrains.annotations.NotNull +import com.intellij.openapi.module.Module; +import com.intellij.openapi.roots.ModifiableRootModel; +import org.jetbrains.annotations.NotNull; -@CompileStatic -final class CompoundTestLibrary implements TestLibrary { - - private final TestLibrary[] myLibraries - - CompoundTestLibrary(TestLibrary... libraries) { - assert libraries.length > 0 - myLibraries = libraries +public final class CompoundTestLibrary implements TestLibrary { + public CompoundTestLibrary(TestLibrary... libraries) { + assert libraries.length > 0; + myLibraries = libraries; } @Override - void addTo(@NotNull Module module, @NotNull ModifiableRootModel model) { - for (library in myLibraries) { - library.addTo(module, model) + public void addTo(@NotNull Module module, @NotNull ModifiableRootModel model) { + for (TestLibrary library : myLibraries) { + library.addTo(module, model); } } + + private final TestLibrary[] myLibraries; } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/FastGroovyTestSuite.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/FastGroovyTestSuite.java new file mode 100644 index 000000000000..5835a8582490 --- /dev/null +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/FastGroovyTestSuite.java @@ -0,0 +1,11 @@ +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.plugins.groovy; + +import org.jetbrains.plugins.groovy.util.AllTestsSuite; +import org.jetbrains.plugins.groovy.util.TestPackage; +import org.junit.runner.RunWith; + +@RunWith(AllTestsSuite.class) +@TestPackage("org.jetbrains.plugins.groovy") +public class FastGroovyTestSuite { +} diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/GrCommentTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/GrCommentTest.java index c07983766ba3..f28a6bfef8fc 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/GrCommentTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/GrCommentTest.java @@ -1,121 +1,119 @@ -// Copyright 2000-2018 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 org.jetbrains.plugins.groovy +package org.jetbrains.plugins.groovy; -import com.intellij.codeInsight.generation.actions.CommentByBlockCommentAction -import com.intellij.codeInsight.generation.actions.CommentByLineCommentAction -import com.intellij.openapi.actionSystem.AnAction -import org.jetbrains.annotations.NotNull -import org.jetbrains.plugins.groovy.lang.formatter.GroovyFormatterTestCase -import org.jetbrains.plugins.groovy.util.TestUtils +import com.intellij.codeInsight.generation.actions.CommentByBlockCommentAction; +import com.intellij.codeInsight.generation.actions.CommentByLineCommentAction; +import com.intellij.openapi.actionSystem.AnAction; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.groovy.lang.formatter.GroovyFormatterTestCase; +import org.jetbrains.plugins.groovy.util.TestUtils; /** * @author Max Medvedev */ -class GrCommentTest extends GroovyFormatterTestCase { +public class GrCommentTest extends GroovyFormatterTestCase { @Override protected String getBasePath() { - TestUtils.testDataPath + 'grComment/' + return TestUtils.getTestDataPath() + "grComment/"; } - void testUncommentLine() { - lineTest('''\ + public void testUncommentLine() { + lineTest(""" //print 2 -''', '''\ +""", """ print 2 -''') +"""); } - - void testBlock0() { - blockTest('''\ + public void testBlock0() { + blockTest(""" print 2 -''', '''\ +""", """ /*print 2*/ -''') +"""); } - void testUncommentBlock0() { - blockTest('''\ + public void testUncommentBlock0() { + blockTest(""" /*print 2*/ -''', '''\ +""", """ print 2 -''') +"""); } - void testBlock1() { - blockTest('''\ + public void testBlock1() { + blockTest(""" print 2 -''', '''\ +""", """ /* print 2 */ -''') +"""); } - void testUncommentBlock1() { - blockTest('''\ + public void testUncommentBlock1() { + blockTest(""" /* print 2 */ -''', '''\ +""", """ print 2 -''') +"""); } - void 'test line comment no indent'() { - lineTest '''\ + public void test_line_comment_no_indent() { + lineTest(""" def foo() { print 2 } -''', '''\ +""", """ def foo() { // print 2 } -''' +"""); } - void 'test line comment indent'() { - groovySettings.LINE_COMMENT_AT_FIRST_COLUMN = false - lineTest '''\ + public void test_line_comment_indent() { + getGroovySettings().LINE_COMMENT_AT_FIRST_COLUMN = false; + lineTest(""" def foo() { println 42 } -''', '''\ +""", """ def foo() { //println 42 } -''' +"""); } - void 'test line comment indent and space'() { - groovySettings.LINE_COMMENT_AT_FIRST_COLUMN = false - groovySettings.LINE_COMMENT_ADD_SPACE = true - lineTest '''\ + public void test_line_comment_indent_and_space() { + getGroovySettings().LINE_COMMENT_AT_FIRST_COLUMN = false; + getGroovySettings().LINE_COMMENT_ADD_SPACE = true; + lineTest(""" def foo() { println 42 } -''', '''\ +""", """ def foo() { // println 42 } -''' +"""); } - void lineTest(String before, String after) { - doTest(before, after, new CommentByLineCommentAction()) + public void lineTest(String before, String after) { + doTest(before, after, new CommentByLineCommentAction()); } - void blockTest(String before, String after) { - doTest(before, after, new CommentByBlockCommentAction()) + public void blockTest(String before, String after) { + doTest(before, after, new CommentByBlockCommentAction()); } private void doTest(@NotNull String before, @NotNull String after, final AnAction action) { - myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, before) - myFixture.testAction(action) - myFixture.checkResult(after) + myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, before); + myFixture.testAction(action); + myFixture.checkResult(after); } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyActionsTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyActionsTest.java index b6f295c39e90..25bc232249b2 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyActionsTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyActionsTest.java @@ -1,120 +1,110 @@ -// Copyright 2000-2018 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 org.jetbrains.plugins.groovy +package org.jetbrains.plugins.groovy; -import com.intellij.openapi.actionSystem.IdeActions -import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase -import org.jetbrains.plugins.groovy.util.TestUtils +import com.intellij.openapi.actionSystem.IdeActions; +import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase; +import org.jetbrains.plugins.groovy.util.TestUtils; -class GroovyActionsTest extends LightJavaCodeInsightFixtureTestCase { - - final String basePath = TestUtils.testDataPath + 'groovy/actions/' - - void testSelectWordBeforeMethod() { - doTestForSelectWord 1 +public class GroovyActionsTest extends LightJavaCodeInsightFixtureTestCase { + public void testSelectWordBeforeMethod() { + doTestForSelectWord(1); } - void testSWInGString() { doTestSelectWordUpTo 5 } + public void testSWInGString() { doTestSelectWordUpTo(5); } - void 'test select word in GString select line before injection'() { - doTestForSelectWord 2, '''\ -print """ + public void test_select_word_in_GString_select_line_before_injection() { + doTestForSelectWord(2, """ +print ""\" asddf asdf $b sfsasdf fdsas -""" -''', '''\ -print """ +""\" +""", """ +print ""\" asddf asdf $b sfsasdf fdsas -""" -''' +""\" +"""); } - void 'test select word in GString select line after injection'() { - doTestForSelectWord 2, '''\ -print """ + public void test_select_word_in_GString_select_line_after_injection() { + doTestForSelectWord(2, """ +print ""\" asddf asdf $b sfsasdf fdsas -""" -''', '''\ -print """ +""\" +""", """ +print ""\" asddf asdf $b sfsasdf fdsas -""" -''' +""\" +"""); } - void 'test select word in GString select line before end'() { - doTestForSelectWord 2, '''\ -print """ + public void test_select_word_in_GString_select_line_before_end() { + doTestForSelectWord(2, """ +print ""\" asddf asdf $b sfsasdf -fdsas fsss""" -''', '''\ -print """ +fdsas fsss""\" +""", """ +print ""\" asddf asdf $b sfsasdf -fdsas fsss""" -''' +fdsas fsss""\" +"""); } - void testSWInGStringMultiline() { doTestSelectWordUpTo 4 } + public void testSWInGStringMultiline() { doTestSelectWordUpTo(4); } - void testSWInGStringBegin() { doTestSelectWordUpTo 2 } + public void testSWInGStringBegin() { doTestSelectWordUpTo(2); } - void testSWInGStringEnd() { doTestSelectWordUpTo 2 } + public void testSWInGStringEnd() { doTestSelectWordUpTo(2); } - void testSWInParameterList() { doTestForSelectWord(3) } + public void testSWInParameterList() { doTestForSelectWord(3); } - void testSWInArgLabel1() { doTestForSelectWord(2) } + public void testSWInArgLabel1() { doTestForSelectWord(2); } - void testSWInArgLabel2() { doTestForSelectWord(2) } + public void testSWInArgLabel2() { doTestForSelectWord(2); } - void testSWInArgLabel3() { doTestForSelectWord(2) } + public void testSWInArgLabel3() { doTestForSelectWord(2); } - void testSWEscapesInString() { - doTestForSelectWord 1, - "String s = \"abc\\ndef\"", - "String s = \"abc\\ndef\"" + public void testSWEscapesInString() { + doTestForSelectWord(1, "String s = \"abc\\ndef\"", "String s = \"abc\\ndef\""); } - void testSWListLiteralArgument() { - doTestForSelectWord 2, -"foo([a], b)", -"foo([a], b)" + public void testSWListLiteralArgument() { + doTestForSelectWord(2, "foo([a], b)", "foo([a], b)"); } - void testSWMethodParametersBeforeQualifier() { - doTestForSelectWord 2, -"a.foo(b)", -"a.foo(b)" + public void testSWMethodParametersBeforeQualifier() { + doTestForSelectWord(2, "a.foo(b)", "a.foo(b)"); } - void testSWInCodeBlock() { doTestForSelectWord 5 } + public void testSWInCodeBlock() { doTestForSelectWord(5); } - void testElseBranch() { - doTestForSelectWord (3, '''\ + public void testElseBranch() { + doTestForSelectWord(3, """ def foo() { if (a){ } else { } } -''', '''\ +""", """ def foo() { if (a){ } else { } } -''') +"""); } - void testBlocksOfCode() { - doTestForSelectWord(8, '''\ + public void testBlocksOfCode() { + doTestForSelectWord(8, """ this.allOptions = [:]; confTag.option.each{ opt -> def value = opt.'@value'; @@ -132,7 +122,7 @@ this.allOptions = [:]; } this.macroExpander = macroExpander; -''', '''\ +""", """ this.allOptions = [:]; confTag.option.each{ opt -> def value = opt.'@value'; @@ -150,45 +140,45 @@ this.allOptions = [:]; } this.macroExpander = macroExpander; -''') +"""); } - void "test hippie completion in groovydoc"() { - def text = ''' -class A { + public void test_hippie_completion_in_groovydoc() { + String text = """ + class A { - /** long - */ - void longName() {} - void example() {} -} -''' - myFixture.configureByText 'a.groovy', text - performEditorAction(IdeActions.ACTION_HIPPIE_COMPLETION) - assert myFixture.editor.document.text.contains('** longName\n') - performEditorAction(IdeActions.ACTION_HIPPIE_COMPLETION) - myFixture.checkResult(text) + /** long + */ + void longName() {} + void example() {} + } + """; + myFixture.configureByText("a.groovy", text); + performEditorAction(IdeActions.ACTION_HIPPIE_COMPLETION); + assert myFixture.getEditor().getDocument().getText().contains("** longName\n"); + performEditorAction(IdeActions.ACTION_HIPPIE_COMPLETION); + myFixture.checkResult(text); } - void "test hippie completion with hyphenated match"() { - myFixture.configureByText 'a.groovy', ''' -foo = [ helloWorld: 1, "hello-world": { - hw - f - } -]''' - performEditorAction(IdeActions.ACTION_HIPPIE_COMPLETION) - assert myFixture.editor.document.text.contains(' hello-world\n') - performEditorAction(IdeActions.ACTION_HIPPIE_COMPLETION) - assert myFixture.editor.document.text.contains(' helloWorld\n') + public void test_hippie_completion_with_hyphenated_match() { + myFixture.configureByText("a.groovy", """ + foo = [ helloWorld: 1, "hello-world": { + hw + f + } + ]"""); + performEditorAction(IdeActions.ACTION_HIPPIE_COMPLETION); + assert myFixture.getEditor().getDocument().getText().contains(" hello-world\n"); + performEditorAction(IdeActions.ACTION_HIPPIE_COMPLETION); + assert myFixture.getEditor().getDocument().getText().contains(" helloWorld\n"); - myFixture.editor.caretModel.moveToOffset(myFixture.editor.document.text.indexOf(' f') + 2) - performEditorAction(IdeActions.ACTION_HIPPIE_COMPLETION) - assert myFixture.editor.document.text.contains(' foo\n') + myFixture.getEditor().getCaretModel().moveToOffset(myFixture.getEditor().getDocument().getText().indexOf(" f") + 2); + performEditorAction(IdeActions.ACTION_HIPPIE_COMPLETION); + assert myFixture.getEditor().getDocument().getText().contains(" foo\n"); } - void testSWforMemberWithDoc() { - doTestForSelectWord(4, '''\ + public void testSWforMemberWithDoc() { + doTestForSelectWord(4, """ class A { /** * abc @@ -197,7 +187,7 @@ class A { def bar(){} } -''', '''\ +""", """ class A { /** * abc @@ -206,67 +196,72 @@ class A { def bar(){} } -''') +"""); } - void testMultiLineStingSelection() { + public void testMultiLineStingSelection() { doTestForSelectWord(2, """ - print ''' - abc cde - xyz ahc - ''' - """, """ - print ''' - abc cde - xyz ahc - ''' - """) + print ''' + abc cde + xyz ahc + ''' + """, """ + print ''' + abc cde + xyz ahc + ''' +"""); doTestForSelectWord(3, """ - print ''' - abc cde - xyz ahc - ''' - """, """ - print ''' - abc cde - xyz ahc - ''' - """) - + print ''' + abc cde + xyz ahc + ''' + """, """ + print ''' + abc cde + xyz ahc + ''' + """); } private void doTestForSelectWord(int count, String input, String expected) { - myFixture.configureByText("a.groovy", input) - selectWord(count) - myFixture.checkResult(expected) + myFixture.configureByText("a.groovy", input); + selectWord(count); + myFixture.checkResult(expected); } private void doTestForSelectWord(int count) { - myFixture.configureByFile(getTestName(false) + ".groovy") - selectWord(count) - myFixture.checkResultByFile(getTestName(false) + "_after.groovy") + myFixture.configureByFile(getTestName(false) + ".groovy"); + selectWord(count); + myFixture.checkResultByFile(getTestName(false) + "_after.groovy"); } private void doTestSelectWordUpTo(int count) { - def testName = getTestName(false) - myFixture.configureByFile "${testName}_0.groovy" - myFixture.editor.settings.camelWords = true - count.times { - performEditorAction IdeActions.ACTION_EDITOR_SELECT_WORD_AT_CARET - myFixture.checkResultByFile "${testName}_${it + 1}.groovy" + final String testName = getTestName(false); + myFixture.configureByFile(testName + "_0.groovy"); + myFixture.getEditor().getSettings().setCamelWords(true); + for (int i = 0; i < count; i++) { + performEditorAction(IdeActions.ACTION_EDITOR_SELECT_WORD_AT_CARET); + myFixture.checkResultByFile(testName + "_" + (i + 1) + ".groovy"); } } - private def selectWord(int count) { - myFixture.editor.settings.camelWords = true + private void selectWord(int count) { + myFixture.getEditor().getSettings().setCamelWords(true); for (int i = 0; i < count; i++) { - performEditorAction(IdeActions.ACTION_EDITOR_SELECT_WORD_AT_CARET) + performEditorAction(IdeActions.ACTION_EDITOR_SELECT_WORD_AT_CARET); } } private void performEditorAction(final String actionId) { - myFixture.performEditorAction(actionId) + myFixture.performEditorAction(actionId); } + @Override + public final String getBasePath() { + return basePath; + } + + private final String basePath = TestUtils.getTestDataPath() + "groovy/actions/"; } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyGinqTestSuite.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyGinqTestSuite.java new file mode 100644 index 000000000000..7e8c824d4cb0 --- /dev/null +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyGinqTestSuite.java @@ -0,0 +1,11 @@ +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.plugins.groovy; + +import org.jetbrains.plugins.groovy.util.AllTestsSuite; +import org.jetbrains.plugins.groovy.util.TestPackage; +import org.junit.runner.RunWith; + +@RunWith(AllTestsSuite.class) +@TestPackage(value = "org.jetbrains.plugins.groovy.ext.ginq") +public class GroovyGinqTestSuite { +} diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyGotoDeclarationTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyGotoDeclarationTest.java index 960adc71fca1..92a1f887bae5 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyGotoDeclarationTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyGotoDeclarationTest.java @@ -1,29 +1,35 @@ -// Copyright 2000-2019 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 org.jetbrains.plugins.groovy +package org.jetbrains.plugins.groovy; -import com.intellij.testFramework.LightProjectDescriptor -import groovy.transform.CompileStatic -import org.jetbrains.plugins.groovy.util.TestUtils - -@CompileStatic -class GroovyGotoDeclarationTest extends LightGroovyTestCase { - - final String basePath = TestUtils.testDataPath + "gotoDeclaration/" - - final LightProjectDescriptor projectDescriptor = GroovyProjectDescriptors.GROOVY_LATEST +import com.intellij.testFramework.LightProjectDescriptor; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.groovy.util.TestUtils; +public class GroovyGotoDeclarationTest extends LightGroovyTestCase { private void doTest() { - def name = getTestName() - fixture.configureByFile "${name}.groovy" - fixture.performEditorAction "GotoDeclaration" - fixture.checkResultByFile("${name}_after.groovy") + final String name = getTestName(); + getFixture().configureByFile(name + ".groovy"); + getFixture().performEditorAction("GotoDeclaration"); + getFixture().checkResultByFile(name + "_after.groovy"); } - void 'test default constructor'() { - doTest() + public void testDefaultConstructor() { + doTest(); } - void 'test qualifier in new'() { - doTest() + public void testQualifierInNew() { + doTest(); } + + @Override + public final String getBasePath() { + return basePath; + } + + @Override + public final @NotNull LightProjectDescriptor getProjectDescriptor() { + return projectDescriptor; + } + + private final String basePath = TestUtils.getTestDataPath() + "gotoDeclaration/"; + private final LightProjectDescriptor projectDescriptor = GroovyProjectDescriptors.GROOVY_LATEST; } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyParserTestSuite.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyParserTestSuite.java new file mode 100644 index 000000000000..b4fefb4416c7 --- /dev/null +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyParserTestSuite.java @@ -0,0 +1,11 @@ +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.plugins.groovy; + +import org.jetbrains.plugins.groovy.util.AllTestsSuite; +import org.jetbrains.plugins.groovy.util.TestPackage; +import org.junit.runner.RunWith; + +@RunWith(AllTestsSuite.class) +@TestPackage(value = "org.jetbrains.plugins.groovy.lang.parser") +public class GroovyParserTestSuite { +} diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyWebReferenceTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyWebReferenceTest.java index 5016adad462f..025573308fb4 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyWebReferenceTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/GroovyWebReferenceTest.java @@ -1,37 +1,37 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package org.jetbrains.plugins.groovy +package org.jetbrains.plugins.groovy; -import com.intellij.openapi.paths.WebReference -import com.intellij.testFramework.LightProjectDescriptor -import groovy.transform.CompileStatic +import com.intellij.openapi.paths.WebReference; +import com.intellij.testFramework.LightProjectDescriptor; +import com.intellij.testFramework.fixtures.InjectionTestFixtureKt; +import org.jetbrains.annotations.NotNull; -import static com.intellij.testFramework.fixtures.InjectionTestFixtureKt.assertInjectedReference - -@CompileStatic -class GroovyWebReferenceTest extends LightGroovyTestCase { - final LightProjectDescriptor projectDescriptor = GroovyProjectDescriptors.GROOVY_LATEST - - void 'test web reference in strings'() { +public class GroovyWebReferenceTest extends LightGroovyTestCase { + public void test_web_reference_in_strings() { myFixture.configureByText("Demo.groovy", """ - class Demo { - static void main(String[] args) { - def doubleQuotes = "http://double:8080/app" - def singleQuotes = 'http://single:8080/app' - - def multilineSingle = ''' - https://multiline-single:8080/app - ''' - - def multilineDouble = \"\"\" - http://multiline-double:8080/app - \"\"\" - } - } - """) + class Demo { + static void main(String[] args) { + def doubleQuotes = "http://double:8080/app" + def singleQuotes = 'http://single:8080/app' + + def multilineSingle = ''' + https://multiline-single:8080/app + ''' + + def multilineDouble = ""\" + http://multiline-double:8080/app + ""\" + } + } + """); - assertInjectedReference(myFixture, WebReference.class, "http://double:8080/app") - assertInjectedReference(myFixture, WebReference.class, "http://single:8080/app") - assertInjectedReference(myFixture, WebReference.class, "https://multiline-single:8080/app") - assertInjectedReference(myFixture, WebReference.class, "http://multiline-double:8080/app") + InjectionTestFixtureKt.assertInjectedReference(myFixture, WebReference.class, "http://double:8080/app"); + InjectionTestFixtureKt.assertInjectedReference(myFixture, WebReference.class, "http://single:8080/app"); + InjectionTestFixtureKt.assertInjectedReference(myFixture, WebReference.class, "https://multiline-single:8080/app"); + InjectionTestFixtureKt.assertInjectedReference(myFixture, WebReference.class, "http://multiline-double:8080/app"); + } + + @Override + public final @NotNull LightProjectDescriptor getProjectDescriptor() { + return GroovyProjectDescriptors.GROOVY_LATEST; } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/LibraryLightProjectDescriptor.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/LibraryLightProjectDescriptor.java index 0897834d255f..c2740078cc69 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/LibraryLightProjectDescriptor.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/LibraryLightProjectDescriptor.java @@ -1,25 +1,21 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package org.jetbrains.plugins.groovy +package org.jetbrains.plugins.groovy; -import com.intellij.openapi.module.Module -import com.intellij.openapi.roots.ContentEntry -import com.intellij.openapi.roots.ModifiableRootModel -import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor -import groovy.transform.CompileStatic -import org.jetbrains.annotations.NotNull +import com.intellij.openapi.module.Module; +import com.intellij.openapi.roots.ContentEntry; +import com.intellij.openapi.roots.ModifiableRootModel; +import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor; +import org.jetbrains.annotations.NotNull; -@CompileStatic -class LibraryLightProjectDescriptor extends DefaultLightProjectDescriptor { - - private final TestLibrary myLibrary - - LibraryLightProjectDescriptor(TestLibrary library) { - myLibrary = library +public class LibraryLightProjectDescriptor extends DefaultLightProjectDescriptor { + public LibraryLightProjectDescriptor(TestLibrary library) { + myLibrary = library; } @Override - void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) { - super.configureModule(module, model, contentEntry) - myLibrary.addTo(module, model) + public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) { + super.configureModule(module, model, contentEntry); + myLibrary.addTo(module, model); } + + private final TestLibrary myLibrary; } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/LightGroovyTestCase.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/LightGroovyTestCase.java index 6af1a58310f6..b8318aba7277 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/LightGroovyTestCase.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/LightGroovyTestCase.java @@ -1,59 +1,62 @@ -// Copyright 2000-2019 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 org.jetbrains.plugins.groovy +package org.jetbrains.plugins.groovy; +import com.intellij.codeInspection.ex.EntryPointsManagerBase; +import com.intellij.openapi.application.PathManager; +import com.intellij.psi.PsiIntersectionType; +import com.intellij.psi.PsiType; +import com.intellij.testFramework.LightProjectDescriptor; +import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture; +import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase; +import junit.framework.TestCase; +import org.codehaus.groovy.runtime.DefaultGroovyMethods; +import org.codehaus.groovy.runtime.StringGroovyMethods; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -import com.intellij.codeInspection.ex.EntryPointsManagerBase -import com.intellij.psi.PsiIntersectionType -import com.intellij.psi.PsiType -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture -import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase -import groovy.transform.CompileStatic -import org.jetbrains.annotations.NonNls -import org.jetbrains.annotations.NotNull -import org.jetbrains.annotations.Nullable -abstract class LightGroovyTestCase extends LightJavaCodeInsightFixtureTestCase { +import java.util.Arrays; +import java.util.stream.Collectors; +public abstract class LightGroovyTestCase extends LightJavaCodeInsightFixtureTestCase { @NotNull - JavaCodeInsightTestFixture getFixture() { - myFixture + public JavaCodeInsightTestFixture getFixture() { + return myFixture; } @Override - void setUp() throws Exception { - super.setUp() + public void setUp() throws Exception { + super.setUp(); // avoid PSI/document/model changes are not allowed during highlighting - EntryPointsManagerBase.DEAD_CODE_EP_NAME.getExtensionList() + EntryPointsManagerBase.DEAD_CODE_EP_NAME.getExtensionList(); } @Override - void tearDown() throws Exception { - super.tearDown() + public void tearDown() throws Exception { + super.tearDown(); } @Override @NotNull protected LightProjectDescriptor getProjectDescriptor() { - return GroovyProjectDescriptors.GROOVY_2_1 + return GroovyProjectDescriptors.GROOVY_2_1; } /** * Return relative path to the test data. Path is relative to the - * {@link com.intellij.openapi.application.PathManager#getHomePath()} + * {@link PathManager#getHomePath()} * * @return relative path to the test data. */ @Override @NonNls - protected String getBasePath() { null } - + protected String getBasePath() { return null; } protected void addGroovyTransformField() { - myFixture.addClass('''package groovy.transform; public @interface Field{}''') + myFixture.addClass("package groovy.transform; public @interface Field{}"); } - protected void addGroovyObject() throws IOException { - myFixture.addClass('''\ + protected void addGroovyObject() { + myFixture.addClass(""" package groovy.lang; public interface GroovyObject { java.lang.Object invokeMethod(java.lang.String s, java.lang.Object o); @@ -62,50 +65,48 @@ public interface GroovyObject { groovy.lang.MetaClass getMetaClass(); void setMetaClass(groovy.lang.MetaClass metaClass); } -''') +"""); } - - public static final String IMPORT_COMPILE_STATIC = 'import groovy.transform.CompileStatic' - void addCompileStatic() { - myFixture.addClass('''\ + public void addCompileStatic() { + myFixture.addClass(""" package groovy.transform; public @interface CompileStatic{ } -''') +"""); } protected void addBigDecimal() { - myFixture.addClass('''\ + myFixture.addClass(""" package java.math; public class BigDecimal extends Number implements Comparable { } -''') +"""); } protected void addBigInteger() { - myFixture.addClass('''\ + myFixture.addClass(""" package java.math; public class BigInteger extends Number implements Comparable { } -''') +"""); } protected void addHashSet() { - myFixture.addClass('''\ + myFixture.addClass(""" package java.util; public class HashSet extends AbstractSet implements Set, Cloneable, java.io.Serializable {} -''') +"""); } protected final void addAnnotationCollector() { - myFixture.addClass '''\ + myFixture.addClass(""" package groovy.transform; @java.lang.annotation.Documented @@ -115,7 +116,7 @@ public @interface AnnotationCollector { String processor() default "org.codehaus.groovy.transform.AnnotationCollectorTransform"; Class[] value() default {}; } -''' +"""); } /*void addHashMap() { @@ -132,15 +133,14 @@ public class HashMap extends AbstractMap implements Map, Cloneabl }*/ protected final void addTestCase() { - myFixture.addClass('''\ - + myFixture.addClass(""" // IntelliJ API Decompiler stub source generated from a class file // Implementation of methods is not available -package junit.framework; + package junit.framework; -@SuppressWarnings({"Contract", "MethodOverridesStaticMethodOfSuperclass", "RedundantThrows"}) -public abstract class TestCase extends junit.framework.Assert implements junit.framework.Test { + @SuppressWarnings({"Contract", "MethodOverridesStaticMethodOfSuperclass", "RedundantThrows"}) + public abstract class TestCase extends junit.framework.Assert implements junit.framework.Test { private java.lang.String fName; public TestCase() { /* compiled code */ } @@ -245,39 +245,44 @@ public abstract class TestCase extends junit.framework.Assert implements junit.f public void setName(java.lang.String name) { /* compiled code */ } } -''') +"""); } - @CompileStatic - static void assertType(@Nullable String expected, @Nullable PsiType actual) { - if (expected == null) { - assert actual == null - return + public static void assertType(@Nullable String expected, @Nullable PsiType actual) { + if (expected == null){ + assertNull(actual); + return; } - assert actual != null - if (actual instanceof PsiIntersectionType) { - assertEquals(expected, genIntersectionTypeText(actual)) + assertNotNull(actual); + if (actual instanceof PsiIntersectionType){ + TestCase.assertEquals(expected, genIntersectionTypeText((PsiIntersectionType)actual)); } else { - assertEquals(expected, actual.canonicalText) + TestCase.assertEquals(expected, actual.getCanonicalText()); } } private static String genIntersectionTypeText(PsiIntersectionType t) { - StringBuilder b = new StringBuilder('[') - for (PsiType c : t.conjuncts) { - b << c.canonicalText << ',' + StringBuilder b = new StringBuilder("["); + for(PsiType c : t.getConjuncts()){ + StringGroovyMethods.leftShift(StringGroovyMethods.leftShift(b, c.getCanonicalText()), ","); } - if (t.conjuncts) { - b.replace(b.length() - 1, b.length(), ']') + + if (DefaultGroovyMethods.asBoolean(t.getConjuncts())){ + b.replace(b.length() - 1, b.length(), "]"); } - return b + + return b.toString(); } - - @CompileStatic - String getTestName() { - return (getTestName(true) - 'test').split(' ')*.capitalize().join('').uncapitalize() + public String getTestName() { + String[] split = getTestName(true) + .replaceFirst("test", "") + .split(" "); + String joined = Arrays.stream(split) + .map(s -> StringGroovyMethods.capitalize(s)) + .collect(Collectors.joining()); + return StringGroovyMethods.uncapitalize(joined); } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/ReachingDefsTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/ReachingDefsTest.java index 1876eb9fc62e..30e85d4ef8e3 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/ReachingDefsTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/ReachingDefsTest.java @@ -1,103 +1,110 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package org.jetbrains.plugins.groovy +package org.jetbrains.plugins.groovy; -import com.intellij.psi.PsiElement -import com.intellij.psi.util.PsiTreeUtil -import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase -import org.jetbrains.annotations.NotNull -import org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils -import org.jetbrains.plugins.groovy.lang.psi.GrControlFlowOwner -import org.jetbrains.plugins.groovy.lang.psi.GroovyFile -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement -import org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.ControlFlowBuilder -import org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.GrAllVarsInitializedPolicy -import org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.GroovyControlFlow -import org.jetbrains.plugins.groovy.lang.psi.dataFlow.reachingDefs.FragmentVariableInfos -import org.jetbrains.plugins.groovy.lang.psi.dataFlow.reachingDefs.ReachingDefinitionsCollector -import org.jetbrains.plugins.groovy.lang.psi.dataFlow.reachingDefs.VariableInfo -import org.jetbrains.plugins.groovy.util.TestUtils +import com.intellij.psi.PsiElement; +import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase; +import junit.framework.TestCase; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils; +import org.jetbrains.plugins.groovy.lang.psi.GrControlFlowOwner; +import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; +import org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.ControlFlowBuilder; +import org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.GrAllVarsInitializedPolicy; +import org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.GroovyControlFlow; +import org.jetbrains.plugins.groovy.lang.psi.dataFlow.reachingDefs.FragmentVariableInfos; +import org.jetbrains.plugins.groovy.lang.psi.dataFlow.reachingDefs.ReachingDefinitionsCollector; +import org.jetbrains.plugins.groovy.lang.psi.dataFlow.reachingDefs.VariableInfo; +import org.jetbrains.plugins.groovy.util.TestUtils; -/** - * @auther ven - */ -class ReachingDefsTest extends LightJavaCodeInsightFixtureTestCase { +import java.util.List; - String basePath = TestUtils.testDataPath + 'groovy/reachingDefs/' +public class ReachingDefsTest extends LightJavaCodeInsightFixtureTestCase { + public void testAssign() { doTest(); } - void testAssign() { doTest() } + public void testClosure() { doTest(); } - void testClosure() { doTest() } + public void testClosure1() { doTest(); } - void testClosure1() { doTest() } + public void testEm1() { doTest(); } - void testEm1() { doTest() } + public void testEm2() { doTest(); } - void testEm2() { doTest() } + public void testEm3() { doTest(); } - void testEm3() { doTest() } + public void testIf1() { doTest(); } - void testIf1() { doTest() } + public void testInner() { doTest(); } - void testInner() { doTest() } + public void testLocal1() { doTest(); } - void testLocal1() { doTest() } + public void testLocal2() { doTest(); } - void testLocal2() { doTest() } + public void testSimpl1() { doTest(); } - void testSimpl1() { doTest() } + public void testSimpl2() { doTest(); } - void testSimpl2() { doTest() } + public void testSimpl3() { doTest(); } - void testSimpl3() { doTest() } + public void testWhile1() { doTest(); } - void testWhile1() { doTest() } + public void doTest() { + final List data = TestUtils.readInput(getTestDataPath() + getTestName(true) + ".test"); + String text = data.get(0); - void doTest() { - final List data = TestUtils.readInput(testDataPath + getTestName(true) + ".test") - String text = data.get(0) + myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, text); - myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, text) + int selStart = myFixture.getEditor().getSelectionModel().getSelectionStart(); + int selEnd = myFixture.getEditor().getSelectionModel().getSelectionEnd(); - int selStart = myFixture.editor.selectionModel.selectionStart - int selEnd = myFixture.editor.selectionModel.selectionEnd + final GroovyFile file = (GroovyFile)myFixture.getFile(); + final PsiElement start = file.findElementAt(selStart); + final PsiElement end = file.findElementAt(selEnd - 1); + final GrControlFlowOwner owner = PsiTreeUtil.getParentOfType(PsiTreeUtil.findCommonParent(start, end), GrControlFlowOwner.class, false); + assert owner != null; + GrStatement firstStatement = getStatement(start, owner); + GrStatement lastStatement = getStatement(end, owner); - final GroovyFile file = (GroovyFile)myFixture.file - final PsiElement start = file.findElementAt(selStart) - final PsiElement end = file.findElementAt(selEnd - 1) - final GrControlFlowOwner owner = PsiTreeUtil.getParentOfType(PsiTreeUtil.findCommonParent(start, end), GrControlFlowOwner, false) - assert owner != null - GrStatement firstStatement = getStatement(start, owner) - GrStatement lastStatement = getStatement(end, owner) + final GrControlFlowOwner flowOwner = ControlFlowUtils.findControlFlowOwner(firstStatement); + final GroovyControlFlow flow = ControlFlowBuilder.buildControlFlow(flowOwner, GrAllVarsInitializedPolicy.getInstance()); + final FragmentVariableInfos fragmentVariableInfos = + ReachingDefinitionsCollector.obtainVariableFlowInformation(firstStatement, lastStatement, flowOwner, flow); - final GrControlFlowOwner flowOwner = ControlFlowUtils.findControlFlowOwner(firstStatement) - final GroovyControlFlow flow = ControlFlowBuilder.buildControlFlow(flowOwner, GrAllVarsInitializedPolicy.getInstance()) - final FragmentVariableInfos fragmentVariableInfos = ReachingDefinitionsCollector.obtainVariableFlowInformation(firstStatement, lastStatement, flowOwner, flow) - - assertEquals(data.get(1), dumpInfo(fragmentVariableInfos).trim()) + TestCase.assertEquals(data.get(1), dumpInfo(fragmentVariableInfos).trim()); } private static String dumpInfo(FragmentVariableInfos fragmentVariableInfos) { - StringBuilder builder = new StringBuilder() - builder.append("input:\n") - for (VariableInfo info : fragmentVariableInfos.inputVariableNames) { - builder.append(info.name).append("\n") + StringBuilder builder = new StringBuilder(); + builder.append("input:\n"); + for (VariableInfo info : fragmentVariableInfos.getInputVariableNames()) { + builder.append(info.getName()).append("\n"); } - builder.append("output:\n") - for (VariableInfo info : fragmentVariableInfos.outputVariableNames) { - builder.append(info.name).append("\n") + builder.append("output:\n"); + for (VariableInfo info : fragmentVariableInfos.getOutputVariableNames()) { + builder.append(info.getName()).append("\n"); } - return builder.toString() + return builder.toString(); } private static GrStatement getStatement(@NotNull PsiElement element, PsiElement context) { - while (element.parent != context) { - element = element.parent - assert element != null + while (!element.getParent().equals(context)) { + element = element.getParent(); + assertNotNull(element); } - return (GrStatement) element + return (GrStatement)element; } + @Override + public String getBasePath() { + return basePath; + } + + public void setBasePath(String basePath) { + this.basePath = basePath; + } + + private String basePath = TestUtils.getTestDataPath() + "groovy/reachingDefs/"; } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/RepositoryTestLibrary.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/RepositoryTestLibrary.java index 95662437a6a4..527191f4f02f 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/RepositoryTestLibrary.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/RepositoryTestLibrary.java @@ -1,70 +1,72 @@ -// Copyright 2000-2019 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 org.jetbrains.plugins.groovy +package org.jetbrains.plugins.groovy; -import com.intellij.jarRepository.JarRepositoryManager -import com.intellij.jarRepository.RemoteRepositoryDescription -import com.intellij.openapi.application.WriteAction -import com.intellij.openapi.module.Module -import com.intellij.openapi.project.Project -import com.intellij.openapi.roots.DependencyScope -import com.intellij.openapi.roots.ModifiableRootModel -import com.intellij.openapi.roots.libraries.ui.OrderRoot -import com.intellij.project.IntelliJProjectConfiguration -import groovy.transform.CompileStatic -import org.jetbrains.annotations.NotNull -import org.jetbrains.idea.maven.utils.library.RepositoryLibraryProperties +import com.intellij.jarRepository.JarRepositoryManager; +import com.intellij.jarRepository.RemoteRepositoryDescription; +import com.intellij.openapi.application.WriteAction; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.DependencyScope; +import com.intellij.openapi.roots.ModifiableRootModel; +import com.intellij.openapi.roots.libraries.Library; +import com.intellij.openapi.roots.libraries.LibraryTable; +import com.intellij.openapi.roots.libraries.ui.OrderRoot; +import com.intellij.project.IntelliJProjectConfiguration; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.idea.maven.utils.library.RepositoryLibraryProperties; -@CompileStatic -final class RepositoryTestLibrary implements TestLibrary { +import java.util.Collection; +import java.util.List; - private final String[] myCoordinates - private final DependencyScope myDependencyScope - - RepositoryTestLibrary(String... coordinates) { - this(DependencyScope.COMPILE, coordinates) +public final class RepositoryTestLibrary implements TestLibrary { + public RepositoryTestLibrary(String... coordinates) { + this(DependencyScope.COMPILE, coordinates); } - RepositoryTestLibrary(String coordinates, DependencyScope dependencyScope) { - this(dependencyScope, coordinates) + public RepositoryTestLibrary(String coordinates, DependencyScope dependencyScope) { + this(dependencyScope, coordinates); } private RepositoryTestLibrary(DependencyScope dependencyScope, String... coordinates) { - assert coordinates.length > 0 - myCoordinates = coordinates - myDependencyScope = dependencyScope + assert coordinates.length > 0; + myCoordinates = coordinates; + myDependencyScope = dependencyScope; } @Override - void addTo(@NotNull Module module, @NotNull ModifiableRootModel model) { - def tableModel = model.moduleLibraryTable.modifiableModel - def library = tableModel.createLibrary(myCoordinates[0]) - def libraryModel = library.modifiableModel + public void addTo(@NotNull Module module, @NotNull ModifiableRootModel model) { + final LibraryTable.ModifiableModel tableModel = model.getModuleLibraryTable().getModifiableModel(); + Library library = tableModel.createLibrary(myCoordinates[0]); + final Library.ModifiableModel libraryModel = library.getModifiableModel(); - for (coordinates in myCoordinates) { - def roots = loadRoots(module.project, coordinates) - for (root in roots) { - libraryModel.addRoot(root.file, root.type) + for (String coordinates : myCoordinates) { + Collection roots = loadRoots(module.getProject(), coordinates); + for (OrderRoot root : roots) { + libraryModel.addRoot(root.getFile(), root.getType()); } } - WriteAction.runAndWait({ - libraryModel.commit() - tableModel.commit() - }) + WriteAction.runAndWait(() -> { + libraryModel.commit(); + tableModel.commit(); + }); - model.findLibraryOrderEntry(library).scope = myDependencyScope + model.findLibraryOrderEntry(library).setScope(myDependencyScope); } - static Collection loadRoots(Project project, String coordinates) { - def libraryProperties = new RepositoryLibraryProperties(coordinates, true) - def roots = JarRepositoryManager.loadDependenciesModal(project, libraryProperties, false, false, null, remoteRepositoryDescriptions) - assert !roots.isEmpty() - return roots + public static Collection loadRoots(Project project, String coordinates) { + RepositoryLibraryProperties libraryProperties = new RepositoryLibraryProperties(coordinates, true); + Collection roots = JarRepositoryManager.loadDependenciesModal(project, libraryProperties, false, false, null, getRemoteRepositoryDescriptions()); + assert !roots.isEmpty(); + return roots; } private static List getRemoteRepositoryDescriptions() { - IntelliJProjectConfiguration.remoteRepositoryDescriptions.collect { repository -> - new RemoteRepositoryDescription(repository.id, repository.name, repository.url) - } + return ContainerUtil.map(IntelliJProjectConfiguration.getRemoteRepositoryDescriptions(), repository -> { + return new RemoteRepositoryDescription(repository.getId(), repository.getName(), repository.getUrl()); + }); } + + private final String[] myCoordinates; + private final DependencyScope myDependencyScope; } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/SetupRule.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/SetupRule.java index f51f71ec8697..5cc1658e304d 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/SetupRule.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/SetupRule.java @@ -1,37 +1,45 @@ -// Copyright 2000-2019 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 org.jetbrains.plugins.groovy +package org.jetbrains.plugins.groovy; -import com.intellij.testFramework.EdtTestUtil -import com.intellij.testFramework.LightProjectDescriptor -import groovy.transform.CompileStatic -import org.junit.rules.TestRule -import org.junit.runner.Description -import org.junit.runners.model.Statement +import com.intellij.testFramework.EdtTestUtil; +import com.intellij.testFramework.LightProjectDescriptor; +import org.jetbrains.annotations.NotNull; +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; -import static org.jetbrains.plugins.groovy.GroovyProjectDescriptors.GROOVY_LATEST_REAL_JDK - -@CompileStatic -class SetupRule implements TestRule { - - final LightGroovyTestCase testCase = new LightGroovyTestCase() { - LightProjectDescriptor projectDescriptor = GROOVY_LATEST_REAL_JDK - } +import static org.jetbrains.plugins.groovy.GroovyProjectDescriptors.GROOVY_LATEST_REAL_JDK; +public class SetupRule implements TestRule { @Override - Statement apply(Statement base, Description description) { - new Statement() { + public Statement apply(final Statement base, Description description) { + return new Statement() { @Override - void evaluate() throws Throwable { - testCase.setUp() + public void evaluate() throws Throwable { + getTestCase().setUp(); try { - EdtTestUtil.runInEdtAndWait { - base.evaluate() - } + EdtTestUtil.runInEdtAndWait(() -> base.evaluate()); } finally { - testCase.tearDown() + getTestCase().tearDown(); } } - } + }; } + + public final LightGroovyTestCase getTestCase() { + return testCase; + } + + private final LightGroovyTestCase testCase = new LightGroovyTestCase() { + @Override + public @NotNull LightProjectDescriptor getProjectDescriptor() { + return projectDescriptor; + } + + public void setProjectDescriptor(LightProjectDescriptor projectDescriptor) { + this.projectDescriptor = projectDescriptor; + } + + private LightProjectDescriptor projectDescriptor = GROOVY_LATEST_REAL_JDK; + }; } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/SlowGroovyTestSuite.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/SlowGroovyTestSuite.java new file mode 100644 index 000000000000..981e0c12e59b --- /dev/null +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/SlowGroovyTestSuite.java @@ -0,0 +1,12 @@ +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.plugins.groovy; + +import org.jetbrains.plugins.groovy.util.AllTestsSuite; +import org.jetbrains.plugins.groovy.util.SlowPolicy; +import org.jetbrains.plugins.groovy.util.TestPackage; +import org.junit.runner.RunWith; + +@RunWith(AllTestsSuite.class) +@TestPackage(value = "org.jetbrains.plugins.groovy", policy = SlowPolicy.SLOW_ONLY) +public class SlowGroovyTestSuite { +} diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyUnwrapTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyUnwrapTest.java index 338f9c8b580a..738766ec6952 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyUnwrapTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyUnwrapTest.java @@ -1,106 +1,80 @@ -/* - * 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. - */ -package org.jetbrains.plugins.groovy.lang +package org.jetbrains.plugins.groovy.lang; -import com.intellij.codeInsight.unwrap.UnwrapHandler -import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase - -class GroovyUnwrapTest extends LightJavaCodeInsightFixtureTestCase { +import com.intellij.codeInsight.unwrap.UnwrapHandler; +import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase; +public class GroovyUnwrapTest extends LightJavaCodeInsightFixtureTestCase { private void assertUnwrapped(String codeBefore, String expectedCodeAfter) { - myFixture.configureByText("A.groovy", codeBefore) - new UnwrapHandler().invoke(project, myFixture.editor, myFixture.file) - myFixture.checkResult(expectedCodeAfter) + myFixture.configureByText("A.groovy", codeBefore); + new UnwrapHandler().invoke(getProject(), myFixture.getEditor(), myFixture.getFile()); + myFixture.checkResult(expectedCodeAfter); } - - void testUnwrapIf() { + public void testUnwrapIf() { assertUnwrapped(""" -if (true) { - a=1; - c = 3 - b=1; -} -""", -"""a=1; + if (true) { + a=1; + c = 3 + b=1; + } + """, """ +a=1; c = 3 -b=1;""") +b=1;"""); } - void testUnwrapFor1() { + public void testUnwrapFor1() { assertUnwrapped(""" -for(int i = 0; i < 10; i++) { - System.gc(); -} -""", "System.gc();") + for(int i = 0; i < 10; i++) { + System.gc(); + } + """, "System.gc();"); } - void testBraces() throws Exception { - assertUnwrapped("""\ + public void testBraces() throws Exception { + assertUnwrapped(""" { def x = 1 } -""", "def x = 1") +""", "def x = 1"); } - void testUnwrapParameterUnderArgumentList() throws Exception { - assertUnwrapped("xxx(1, yyy(1), 2)", - "xxx(1, 1, 2)") + public void testUnwrapParameterUnderArgumentList() { + assertUnwrapped("xxx(1, yyy(1), 2)", "xxx(1, 1, 2)"); } - void testTryWithCatches() throws Exception { - assertUnwrapped("try {\n" + - " int i;\n" + - "} catch(RuntimeException e) {\n" + - " int j;\n" + - "} catch(Exception e) {\n" + - " int k;\n" + - "}", - - "int i;") + public void testTryWithCatches() { + assertUnwrapped(""" + try { + int i; + } catch(RuntimeException e) { + int j; + } catch(Exception e) { + int k; + }""", "int i;"); } - void testConditionalThat() throws Exception { - assertUnwrapped("xxx(f ? '1' : '2');\n", - "xxx('1');\n") + public void testConditionalThat() { + assertUnwrapped("xxx(f ? '1' : '2');\n", "xxx('1');\n"); } - void testConditionalElse() throws Exception { - assertUnwrapped("xxx(f ? '1' : '2' + 3);\n", - "xxx('2' + 3);\n") + public void testConditionalElse() { + assertUnwrapped("xxx(f ? '1' : '2' + 3);\n", "xxx('2' + 3);\n"); } - void testConditionalFromParameterList2() throws Exception { - assertUnwrapped("xxx(11, f ? '1' : '2' + 3, 12);\n", - "xxx(11, '2' + 3, 12);\n") + public void testConditionalFromParameterList2() { + assertUnwrapped("xxx(11, f ? '1' : '2' + 3, 12);\n", "xxx(11, '2' + 3, 12);\n"); } - void testConditionalCond1() throws Exception { - assertUnwrapped("f ? \"1\" : \"2\" + 3", - "\"1\"") + public void testConditionalCond1() { + assertUnwrapped("f ? \"1\" : \"2\" + 3", "\"1\""); } - void testConditionalCond2() throws Exception { - assertUnwrapped("f ? \"1\" : \"2\" + 3", - "\"1\"") + public void testConditionalCond2() { + assertUnwrapped("f ? \"1\" : \"2\" + 3", "\"1\""); } - void testConditionalUnwrapUnderAssigmentExpression() throws Exception { - assertUnwrapped("String s = f ? \"1\" : \"2\";\n", - "String s = \"1\";\n") + public void testConditionalUnwrapUnderAssigmentExpression() { + assertUnwrapped("String s = f ? \"1\" : \"2\";\n", "String s = \"1\";\n"); } - } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrUncheckedAssignmentOfRawTypeTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrUncheckedAssignmentOfRawTypeTest.java index b8ace4296c27..3fc91e1cd666 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrUncheckedAssignmentOfRawTypeTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrUncheckedAssignmentOfRawTypeTest.java @@ -1,47 +1,44 @@ -// Copyright 2000-2019 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 org.jetbrains.plugins.groovy.lang.highlighting +package org.jetbrains.plugins.groovy.lang.highlighting; -import com.intellij.codeInspection.LocalInspectionTool -import groovy.transform.CompileStatic -import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyUncheckedAssignmentOfMemberOfRawTypeInspection -import org.jetbrains.plugins.groovy.util.GroovyLatestTest -import org.jetbrains.plugins.groovy.util.HighlightingTest -import org.junit.Test +import com.intellij.codeInspection.LocalInspectionTool; +import org.codehaus.groovy.runtime.StringGroovyMethods; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyUncheckedAssignmentOfMemberOfRawTypeInspection; +import org.jetbrains.plugins.groovy.util.GroovyLatestTest; +import org.jetbrains.plugins.groovy.util.HighlightingTest; +import org.junit.Test; -import static java.util.Collections.singletonList +import java.util.Collections; +import java.util.List; -@CompileStatic -class GrUncheckedAssignmentOfRawTypeTest extends GroovyLatestTest implements HighlightingTest { - - GrUncheckedAssignmentOfRawTypeTest() { - super('highlighting') +public class GrUncheckedAssignmentOfRawTypeTest extends GroovyLatestTest implements HighlightingTest { + public GrUncheckedAssignmentOfRawTypeTest() { + super("highlighting"); } @Override - String getTestName() { - return super.getTestName().capitalize() + public String getTestName() { + return StringGroovyMethods.capitalize(super.getTestName()); } - final Collection> inspections = singletonList(GroovyUncheckedAssignmentOfMemberOfRawTypeInspection) + @Test + public void rawMethodAccess() { fileHighlightingTest(); } @Test - void rawMethodAccess() { fileHighlightingTest() } + public void rawFieldAccess() { fileHighlightingTest(); } @Test - void rawFieldAccess() { fileHighlightingTest() } + public void rawArrayStyleAccess() { fileHighlightingTest(); } @Test - void rawArrayStyleAccess() { fileHighlightingTest() } + public void rawArrayStyleAccessToMap() { fileHighlightingTest(); } @Test - void rawArrayStyleAccessToMap() { fileHighlightingTest() } + public void rawArrayStyleAccessToList() { fileHighlightingTest(); } @Test - void rawArrayStyleAccessToList() { fileHighlightingTest() } - - @Test - void rawClosureReturnType() { - highlightingTest '''\ + public void rawClosureReturnType() { + highlightingTest(""" class A { A(T t) {this.t = t} @@ -54,6 +51,11 @@ class A { def a = new A(new Date()) Date d = a.cl() -''' +"""); + } + + @Override + public final @NotNull List> getInspections() { + return Collections.singletonList(GroovyUncheckedAssignmentOfMemberOfRawTypeInspection.class); } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/suites.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/suites.groovy deleted file mode 100644 index c2bf67563872..000000000000 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/suites.groovy +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -//file:noinspection NewGroovyClassNamingConvention -package org.jetbrains.plugins.groovy - -import org.jetbrains.plugins.groovy.util.AllTestsSuite -import org.jetbrains.plugins.groovy.util.SlowPolicy -import org.jetbrains.plugins.groovy.util.TestPackage -import org.junit.runner.RunWith - -@RunWith(AllTestsSuite.class) -@TestPackage("org.jetbrains.plugins.groovy") -class FastGroovyTestSuite {} - -@RunWith(AllTestsSuite.class) -@TestPackage(value = "org.jetbrains.plugins.groovy", policy = SlowPolicy.SLOW_ONLY) -class SlowGroovyTestSuite {} - -@RunWith(AllTestsSuite.class) -@TestPackage(value = "org.jetbrains.plugins.groovy", policy = SlowPolicy.ALL) -class AllGroovyTestSuite {} - -@RunWith(AllTestsSuite.class) -@TestPackage(value = "org.jetbrains.plugins.groovy.lang.parser") -class GroovyParserTestSuite {} - -@RunWith(AllTestsSuite.class) -@TestPackage(value = "org.jetbrains.plugins.groovy.ext.ginq") -class GroovyGinqTestSuite {} diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/util/Groovy25Test.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/util/Groovy25Test.java index 6213ffa86021..9fc38359c4f4 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/util/Groovy25Test.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/util/Groovy25Test.java @@ -1,15 +1,11 @@ -// Copyright 2000-2019 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 org.jetbrains.plugins.groovy.util +package org.jetbrains.plugins.groovy.util; -import com.intellij.testFramework.LightProjectDescriptor -import groovy.transform.CompileStatic -import org.jetbrains.plugins.groovy.GroovyProjectDescriptors - -@CompileStatic -abstract class Groovy25Test extends LightProjectTest { +import com.intellij.testFramework.LightProjectDescriptor; +import org.jetbrains.plugins.groovy.GroovyProjectDescriptors; +public abstract class Groovy25Test extends LightProjectTest { @Override - final LightProjectDescriptor getProjectDescriptor() { - GroovyProjectDescriptors.GROOVY_2_5 + public final LightProjectDescriptor getProjectDescriptor() { + return GroovyProjectDescriptors.GROOVY_2_5; } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/util/Groovy30Test.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/util/Groovy30Test.java index 5dca9a92eaa2..2f5b6c0f2f53 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/util/Groovy30Test.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/util/Groovy30Test.java @@ -1,15 +1,11 @@ -// Copyright 2000-2019 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 org.jetbrains.plugins.groovy.util +package org.jetbrains.plugins.groovy.util; -import com.intellij.testFramework.LightProjectDescriptor -import groovy.transform.CompileStatic -import org.jetbrains.plugins.groovy.GroovyProjectDescriptors - -@CompileStatic -abstract class Groovy30Test extends LightProjectTest { +import com.intellij.testFramework.LightProjectDescriptor; +import org.jetbrains.plugins.groovy.GroovyProjectDescriptors; +public abstract class Groovy30Test extends LightProjectTest { @Override - final LightProjectDescriptor getProjectDescriptor() { - GroovyProjectDescriptors.GROOVY_3_0 + public final LightProjectDescriptor getProjectDescriptor() { + return GroovyProjectDescriptors.GROOVY_3_0; } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/util/GroovyLatestTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/util/GroovyLatestTest.java index aa8b092fcd58..48a05e218f16 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/util/GroovyLatestTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/util/GroovyLatestTest.java @@ -1,17 +1,17 @@ -// Copyright 2000-2019 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 org.jetbrains.plugins.groovy.util +package org.jetbrains.plugins.groovy.util; -import com.intellij.testFramework.LightProjectDescriptor -import groovy.transform.CompileStatic -import groovy.transform.InheritConstructors -import org.jetbrains.plugins.groovy.GroovyProjectDescriptors - -@CompileStatic -@InheritConstructors -abstract class GroovyLatestTest extends LightProjectTest { +import com.intellij.testFramework.LightProjectDescriptor; +import org.jetbrains.plugins.groovy.GroovyProjectDescriptors; +public abstract class GroovyLatestTest extends LightProjectTest { @Override - final LightProjectDescriptor getProjectDescriptor() { - GroovyProjectDescriptors.GROOVY_2_5 + public final LightProjectDescriptor getProjectDescriptor() { + return GroovyProjectDescriptors.GROOVY_2_5; } + + public GroovyLatestTest(String testDataPath) { + super(testDataPath); + } + + public GroovyLatestTest() { } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/util/LightProjectTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/util/LightProjectTest.java index f06a0c52afd0..d554895f503c 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/util/LightProjectTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/util/LightProjectTest.java @@ -1,36 +1,37 @@ -// Copyright 2000-2019 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 org.jetbrains.plugins.groovy.util +package org.jetbrains.plugins.groovy.util; -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture -import groovy.transform.CompileStatic -import org.jetbrains.annotations.NotNull -import org.junit.Rule -import org.junit.rules.RuleChain -import org.junit.rules.TestName -import org.junit.rules.TestRule +import com.intellij.testFramework.LightProjectDescriptor; +import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture; +import org.jetbrains.annotations.NotNull; +import org.junit.Rule; +import org.junit.rules.RuleChain; +import org.junit.rules.TestName; +import org.junit.rules.TestRule; -@CompileStatic -abstract class LightProjectTest { - - private final TestName myTestName - private final FixtureRule myFixtureRule - public final @Rule TestRule myRules - - LightProjectTest(String testDataPath = '') { - myTestName = new TestName() - myFixtureRule = new FixtureRule(projectDescriptor, testDataPath) - myRules = RuleChain.outerRule(myTestName).around(myFixtureRule).around(new EdtRule()) +public abstract class LightProjectTest { + public LightProjectTest(String testDataPath) { + myTestName = new TestName(); + myFixtureRule = new FixtureRule(getProjectDescriptor(), testDataPath); + myRules = RuleChain.outerRule(myTestName).around(myFixtureRule).around(new EdtRule()); } - abstract LightProjectDescriptor getProjectDescriptor() + public LightProjectTest() { + this(""); + } - String getTestName() { - return myTestName.methodName + public abstract LightProjectDescriptor getProjectDescriptor(); + + public String getTestName() { + return myTestName.getMethodName(); } @NotNull - final JavaCodeInsightTestFixture getFixture() { - myFixtureRule.fixture + public final JavaCodeInsightTestFixture getFixture() { + return myFixtureRule.getFixture(); } + + private final TestName myTestName; + private final FixtureRule myFixtureRule; + + @Rule public final TestRule myRules; }