This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 5afd9b9a91 junit jupiter
5afd9b9a91 is described below
commit 5afd9b9a917b0c460a76b766a24379044f86d1a7
Author: Eric Milles <[email protected]>
AuthorDate: Mon Mar 2 12:53:54 2026 -0600
junit jupiter
---
src/spec/test/DesignPatternsTest.groovy | 146 ++++++++++++++-------
src/spec/test/StyleGuideTest.groovy | 5 +-
src/spec/test/SyntaxTest.groovy | 41 +++++-
src/spec/test/semantics/OptionalityTest.groovy | 9 +-
src/test/groovy/bugs/Groovy3596Bug.groovy | 5 +-
src/test/groovy/bugs/Groovy3721Bug.groovy | 5 +-
src/test/groovy/bugs/Groovy3768Bug.groovy | 5 +-
src/test/groovy/bugs/Groovy3817Bug.groovy | 5 +-
src/test/groovy/bugs/Groovy3857Bug.groovy | 5 +-
src/test/groovy/bugs/Groovy3989Bug.groovy | 5 +-
src/test/groovy/bugs/Groovy4025Bug.groovy | 11 +-
src/test/groovy/bugs/Groovy4043Bug.groovy | 5 +-
src/test/groovy/bugs/Groovy4081Bug.groovy | 7 +-
src/test/groovy/bugs/Groovy4151Bug.groovy | 9 +-
src/test/groovy/bugs/Groovy4169Bug.groovy | 5 +-
src/test/groovy/bugs/Groovy4190Bug.groovy | 6 +-
src/test/groovy/bugs/Groovy4325Bug.groovy | 5 +-
src/test/groovy/bugs/Groovy4356Bug.groovy | 11 +-
src/test/groovy/bugs/Groovy4614Bug.groovy | 5 +-
src/test/groovy/bugs/Groovy6271Bug.groovy | 5 +-
src/test/groovy/bugs/Groovy6792Bug.groovy | 23 ++--
src/test/groovy/bugs/Groovy7922Bug.groovy | 4 +-
src/test/groovy/bugs/Groovy7925Bug.groovy | 5 +-
src/test/groovy/bugs/Groovy8066Bug.groovy | 5 +-
src/test/groovy/bugs/Groovy8342Bug.groovy | 5 +-
src/test/groovy/bugs/Groovy8405Bug.groovy | 7 +-
src/test/groovy/bugs/Groovy8549Bug.groovy | 5 +-
src/test/groovy/bugs/Groovy8595Bug.groovy | 6 +-
src/test/groovy/bugs/Groovy8797Bug.groovy | 5 +-
.../closures/AnnotationClosureTest.groovy | 18 ++-
.../groovy/gls/ch08/s04/FormalParameterTest.groovy | 8 +-
.../classes/methods/RepetitiveMethodTest.groovy | 6 +-
src/test/groovy/gls/enums/EnumTest.groovy | 54 +++++++-
.../invocation/GroovyObjectInheritanceTest.groovy | 11 +-
.../gls/invocation/MethodDeclarationTest.groovy | 7 +-
.../gls/invocation/MethodSelectionTest.groovy | 24 +++-
.../invocation/StaticMethodInvocationTest.groovy | 48 +++----
.../gls/property/MetaClassOverridingTest.groovy | 9 +-
.../gls/scope/BlockScopeVisibilityTest.groovy | 14 +-
.../gls/scope/ClassVariableHidingTest.groovy | 8 +-
src/test/groovy/gls/scope/FinalAccessTest.groovy | 8 +-
.../MultipleDefinitionOfSameVariableTest.groovy | 20 ++-
src/test/groovy/gls/scope/NameResolvingTest.groovy | 13 +-
src/test/groovy/gls/scope/StaticScopeTest.groovy | 21 ++-
.../groovy/gls/sizelimits/StringSizeTest.groovy | 11 +-
.../groovy/gls/statements/DeclarationTest.groovy | 17 ++-
src/test/groovy/gls/statements/ReturnTest.groovy | 12 +-
src/test/groovy/gls/syntax/AssertTest.groovy | 22 ++--
.../groovy/gls/syntax/BinaryLiteralTest.groovy | 6 +-
.../gls/syntax/MethodCallValidationTest.groovy | 8 +-
.../groovy/gls/syntax/NumberLiteralTest.groovy | 11 +-
.../gls/syntax/OldClosureSyntaxRemovalTest.groovy | 6 +-
.../gls/syntax/OldPropertySyntaxRemovalTest.groovy | 6 +-
src/test/groovy/gls/syntax/OldSpreadTest.groovy | 8 +-
src/test/groovy/gls/syntax/ParsingTest.groovy | 8 +-
.../gls/syntax/UnderscoreInNumbersTest.groovy | 8 +-
.../types/BooleanExpressionConversionTest.groovy | 14 +-
src/test/groovy/gls/types/GroovyCastTest.groovy | 11 +-
.../gls/types/OperationsResultTypeTest.groovy | 5 +-
.../groovy/AbstractClassAndInterfaceTest.groovy | 36 +++--
.../groovy/groovy/MethodInBadPositionTest.groovy | 20 +--
src/test/groovy/groovy/ModifiersTest.groovy | 31 +++--
src/test/groovy/groovy/StaticThisTest.groovy | 14 +-
src/test/groovy/groovy/TryCatchTest.groovy | 14 +-
.../groovy/transform/stc/Groovy7880Bug.groovy | 5 +-
src/test/groovy/groovy/util/MiscScriptTest.groovy | 9 +-
.../AutoFinalTransformBlackBoxTest.groovy | 18 +--
.../groovy/transform/SortableTransformTest.groovy | 14 +-
.../groovy/transform/SourceURITransformTest.groovy | 6 +-
.../groovy/gls/CompilableTestSupport.groovy | 43 +++++-
.../groovy-jmx/src/spec/test/JmxTest.groovy | 11 +-
.../src/spec/test/servlet/GroovyServletTest.groovy | 5 +-
.../src/spec/test/SwingBuilderTest.groovy | 6 +-
.../src/spec/test/TemplateEnginesTest.groovy | 11 +-
74 files changed, 764 insertions(+), 266 deletions(-)
diff --git a/src/spec/test/DesignPatternsTest.groovy
b/src/spec/test/DesignPatternsTest.groovy
index 14d80c9559..a8bb145591 100644
--- a/src/spec/test/DesignPatternsTest.groovy
+++ b/src/spec/test/DesignPatternsTest.groovy
@@ -17,10 +17,11 @@
* under the License.
*/
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
+final class DesignPatternsTest extends CompilableTestSupport {
-class DesignPatternsTest extends CompilableTestSupport {
-
+ @Test
void testAbstractFactory() {
shouldCompile '''
// tag::abstract_factory_example1[]
@@ -125,6 +126,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testAdapterDelegation() {
shouldCompile '''
// tag::adapter_delegation_classes[]
@@ -171,6 +173,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testAdapterInheritanceClosuresExpandoMetaClass() {
shouldCompile '''
// tag::adapter_inheritance_classes[]
@@ -244,6 +247,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testBouncerNullCheck() {
shouldCompile '''
// tag::bouncer_null_check[]
@@ -278,6 +282,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testBouncerValidation() {
shouldCompile '''
// tag::bouncer_validation[]
@@ -325,6 +330,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testCommand() {
shouldCompile '''
// tag::command_traditional[]
@@ -471,6 +477,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testChainOfResponsibility() {
shouldCompile '''
// tag::chain_of_responsibility[]
@@ -690,6 +697,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testCompositeCode() {
shouldCompile '''
// tag::composite_code[]
@@ -728,6 +736,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testDecoratorLogger() {
shouldCompile '''
// tag::decorator_logger_class[]
@@ -848,6 +857,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testDecoratorCalc() {
shouldCompile '''
// tag::decorator_calc_class[]
@@ -904,6 +914,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testDecoratorSql() {
shouldCompile '''
@Grab('org.apache.groovy:groovy-sql:4.0.0-beta-2')
@@ -929,6 +940,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testDecoratorSpring() {
shouldCompile '''
package util // to match bean wiring
@@ -955,62 +967,60 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testDecoratorGpars() {
- try {
- shouldCompile '''
- // tag::decorator_gpars[]
- @Grab('org.codehaus.gpars:gpars:0.10')
- import static groovyx.gpars.GParsPool.withPool
+ shouldCompile '''
+ // tag::decorator_gpars[]
+ @Grab('org.codehaus.gpars:gpars:0.10')
+ import static groovyx.gpars.GParsPool.withPool
- interface Document {
- void print()
- String getText()
- }
+ interface Document {
+ void print()
+ String getText()
+ }
- class DocumentImpl implements Document {
- def document
- void print() { println document }
- String getText() { document }
- }
+ class DocumentImpl implements Document {
+ def document
+ void print() { println document }
+ String getText() { document }
+ }
- def words(String text) {
- text.replaceAll('[^a-zA-Z]', '
').trim().split("\\\\s+")*.toLowerCase()
- }
+ def words(String text) {
+ text.replaceAll('[^a-zA-Z]', '
').trim().split("\\\\s+")*.toLowerCase()
+ }
- def avgWordLength = {
- def words = words(it.text)
- sprintf "Avg Word Length: %4.2f", words*.size().sum() /
words.size()
- }
- def modeWord = {
- def wordGroups = words(it.text).groupBy
{it}.collectEntries { k, v -> [k, v.size()] }
- def maxSize = wordGroups*.value.max()
- def maxWords = wordGroups.findAll { it.value == maxSize }
- "Mode Word(s): ${maxWords*.key.join(', ')} ($maxSize
occurrences)"
- }
- def wordCount = { d -> "Word Count: " + words(d.text).size() }
+ def avgWordLength = {
+ def words = words(it.text)
+ sprintf "Avg Word Length: %4.2f", words*.size().sum() /
words.size()
+ }
+ def modeWord = {
+ def wordGroups = words(it.text).groupBy {it}.collectEntries {
k, v -> [k, v.size()] }
+ def maxSize = wordGroups*.value.max()
+ def maxWords = wordGroups.findAll { it.value == maxSize }
+ "Mode Word(s): ${maxWords*.key.join(', ')} ($maxSize
occurrences)"
+ }
+ def wordCount = { d -> "Word Count: " + words(d.text).size() }
- def asyncDecorator(Document d, Closure c) {
- ProxyGenerator.INSTANCE.instantiateDelegate([print: {
- withPool {
- def result = c.callAsync(d)
- d.print()
- println result.get()
- }
- }], [Document], d)
- }
-
- Document d = asyncDecorator(asyncDecorator(asyncDecorator(
- new DocumentImpl(document:"This is the file with the
words in it\\n\\t\\nDo you see the words?\\n"),
- // new DocumentImpl(document: new
File('AsyncDecorator.groovy').text),
- wordCount), modeWord), avgWordLength)
- d.print()
- // end::decorator_gpars[]
- '''
- } catch (UnsupportedClassVersionError e) {
- // running on an older JDK
- }
+ def asyncDecorator(Document d, Closure c) {
+ ProxyGenerator.INSTANCE.instantiateDelegate([print: {
+ withPool {
+ def result = c.callAsync(d)
+ d.print()
+ println result.get()
+ }
+ }], [Document], d)
+ }
+
+ Document d = asyncDecorator(asyncDecorator(asyncDecorator(
+ new DocumentImpl(document:"This is the file with the words
in it\\n\\t\\nDo you see the words?\\n"),
+ // new DocumentImpl(document: new
File('AsyncDecorator.groovy').text),
+ wordCount), modeWord), avgWordLength)
+ d.print()
+ // end::decorator_gpars[]
+ '''
}
+ @Test
void testDelegationExpandoMetaClass() {
shouldCompile '''
// tag::delegation_delegator[]
@@ -1082,6 +1092,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testDelegationAnnotation() {
shouldCompile '''
// tag::delegation_annotation[]
@@ -1107,6 +1118,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testFlyweight() {
shouldCompile '''
// tag::flyweight_boeing797[]
@@ -1166,6 +1178,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testIterator() {
shouldCompile '''
// tag::iterator_example[]
@@ -1189,6 +1202,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testLoanMyResource() {
shouldCompile '''
// tag::loan_my_resource_example[]
@@ -1243,6 +1257,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testMonoids() {
assertScript '''
// tag::monoids_intro[]
@@ -1353,6 +1368,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testNullObjectSimpleExample() {
shouldCompile '''
// tag::null_object_simple_example[]
@@ -1394,6 +1410,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testNullObjectTreeExample() {
shouldCompile '''
// tag::null_object_tree_example[]
@@ -1429,6 +1446,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testNullObjectTreeExample2() {
shouldCompile '''
// tag::null_object_tree_example2[]
@@ -1470,6 +1488,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testObserverExample() {
assertScript '''
// tag::observer_classic[]
@@ -1629,6 +1648,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testPimpMyLibraryExample() {
shouldCompile '''
// tag::pimp_my_library_example[]
@@ -1654,6 +1674,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testProxyClient() {
shouldCompile '''
// tag::proxy_client[]
@@ -1676,6 +1697,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testProxyServer() {
shouldCompile '''
// tag::proxy_server[]
@@ -1701,6 +1723,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testSingletonVoteCollector() {
shouldCompile '''
// tag::singleton_vote_collector[]
@@ -1732,6 +1755,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testSingletonMetaProgramming() {
shouldCompile '''
// tag::singleton_meta_programming_classes[]
@@ -1772,6 +1796,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testSingletonGuice() {
shouldCompile '''
// tag::singleton_guice[]
@@ -1813,6 +1838,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testSingletonGuice2() {
shouldCompile '''
// tag::singleton_guice2[]
@@ -1840,6 +1866,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testSingletonSpring() {
shouldCompile '''
// tag::singleton_spring[]
@@ -1883,6 +1910,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testStateExample() {
shouldCompile '''
// tag::state_example[]
@@ -1967,6 +1995,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testStateVariation1() {
shouldCompile '''
// tag::state_variation1_interface[]
@@ -1980,6 +2009,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testStateVariation2() {
shouldCompile '''
interface State { }
@@ -2000,6 +2030,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testStateVariation3() {
shouldCompile '''
// tag::state_variation2_classes[]
@@ -2090,6 +2121,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testStateVariation4() {
shouldCompile '''
// tag::state_variation31[]
@@ -2234,6 +2266,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testStrategyTraditional() {
assertScript '''
// tag::strategy_traditional[]
@@ -2275,6 +2308,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testStrategyGroovyWay() {
assertScript '''
// tag::strategy_groovy_way[]
@@ -2297,6 +2331,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testStrategyLambdaWithSAMInterface() {
assertScript '''
// tag::strategy_lambdas_with_explicit_interface[]
@@ -2323,6 +2358,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testStrategyLambdaBiFunction() {
assertScript '''
// tag::strategy_lambdas_using_bifunction[]
@@ -2347,6 +2383,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testTemplateMethod() {
assertScript '''
// tag::template_method_example[]
@@ -2376,6 +2413,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testTemplateMethod2() {
assertScript '''
// tag::template_method_example2[]
@@ -2395,6 +2433,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testTemplateMethod3() {
assertScript '''
// tag::template_method_example5[]
@@ -2405,6 +2444,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testVisitorSimpleExample() {
assertScript '''
import groovy.transform.ToString
@@ -2492,6 +2532,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testVisitorSimpleExample2() {
assertScript '''
import groovy.transform.ToString
@@ -2539,6 +2580,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testVisitorSimpleExample3() {
assertScript '''
import groovy.transform.ToString
@@ -2596,6 +2638,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testVisitorAdvancedExample() {
assertScript '''
// tag::visitor_advanced_example[]
@@ -2648,6 +2691,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testVisitorAdvancedExample3() {
assertScript '''
// tag::visitor_advanced_example3[]
@@ -2704,6 +2748,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testVisitorAdvancedExample4() {
assertScript '''
// tag::visitor_advanced_example4[]
@@ -2744,6 +2789,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testVisitorAdvancedExample5() {
assertScript '''
// tag::visitor_advanced_example5[]
diff --git a/src/spec/test/StyleGuideTest.groovy
b/src/spec/test/StyleGuideTest.groovy
index 9dd9dd2ab7..7fa51961f2 100644
--- a/src/spec/test/StyleGuideTest.groovy
+++ b/src/spec/test/StyleGuideTest.groovy
@@ -16,10 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class StyleGuideTest extends CompilableTestSupport {
+final class StyleGuideTest {
+ @Test
void testDataStructures() {
// tag::data_structures[]
def list = [1, 4, 6, 9]
diff --git a/src/spec/test/SyntaxTest.groovy b/src/spec/test/SyntaxTest.groovy
index 98138933f2..d80a7c989c 100644
--- a/src/spec/test/SyntaxTest.groovy
+++ b/src/spec/test/SyntaxTest.groovy
@@ -18,9 +18,13 @@
*/
import gls.CompilableTestSupport
import org.codehaus.groovy.control.CompilationFailedException
+import org.junit.jupiter.api.Test
-class SyntaxTest extends CompilableTestSupport {
+import static groovy.test.GroovyAssert.shouldFail
+final class SyntaxTest extends CompilableTestSupport {
+
+ @Test
void testOctalLiteral() {
// tag::octal_literal_example[]
int xInt = 077
@@ -43,6 +47,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::octal_literal_example[]
}
+ @Test
void testHexadecimalLiteral() {
// tag::hexadecimal_literal_example[]
int xInt = 0x77
@@ -68,6 +73,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::hexadecimal_literal_example[]
}
+ @Test
void testBinaryLiteral() {
// tag::binary_literal_example[]
int xInt = 0b10101111
@@ -90,6 +96,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::binary_literal_example[]
}
+ @Test
void testUnderscoreInNumber() {
// tag::underscore_in_number_example[]
long creditCardNumber = 1234_5678_9012_3456L
@@ -103,6 +110,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::underscore_in_number_example[]
}
+ @Test
void testNumberTypeSuffixes() {
// tag::number_type_suffixes_example[]
assert 42I == Integer.valueOf('42')
@@ -122,6 +130,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::number_type_suffixes_example[]
}
+ @Test
void testVariableStoreBooleanValue() {
shouldCompile '''
@groovy.transform.Field boolean booleanField
@@ -136,6 +145,7 @@ class SyntaxTest extends CompilableTestSupport {
'''
}
+ @Test
void testValidIdentifiers() {
// tag::valid_identifiers[]
def name
@@ -145,6 +155,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::valid_identifiers[]
}
+ @Test
void testInvalidIdentifiers() {
shouldNotCompile '''
// tag::invalid_identifiers[]
@@ -155,6 +166,7 @@ class SyntaxTest extends CompilableTestSupport {
'''
}
+ @Test
void testAllKeywordsAreValidIdentifiersFollowingADot() {
shouldCompile '''
def foo = [:]
@@ -200,6 +212,7 @@ class SyntaxTest extends CompilableTestSupport {
'''
}
+ @Test
void testShebangCommentLine() {
def script = '''\
// tag::shebang_comment_line[]
@@ -211,6 +224,7 @@ class SyntaxTest extends CompilableTestSupport {
shouldCompile script.stripIndent().split('\n')[1..2].join('\n')
}
+ @Test
void testSingleLineComment() {
// tag::single_line_comment[]
// a standalone single line comment
@@ -218,6 +232,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::single_line_comment[]
}
+ @Test
void testMultilineComment() {
// tag::multiline_comment[]
/* a standalone multiline comment
@@ -228,6 +243,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::multiline_comment[]
}
+ @Test
void testGroovyDocComment() {
shouldCompile '''
// tag::groovydoc_comment[]
@@ -252,6 +268,7 @@ class SyntaxTest extends CompilableTestSupport {
'''
}
+ @Test
void testQuotedIdentifier() {
// tag::quoted_id[]
def map = [:]
@@ -280,6 +297,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::quoted_id_with_all_strings[]
}
+ @Test
void testStrings() {
// tag::string_0[]
// end::string_0[]
@@ -305,12 +323,14 @@ class SyntaxTest extends CompilableTestSupport {
// end::string_5[]
}
+ @Test
void testStringConcatenationWithPlus() {
// tag::string_plus[]
assert 'ab' == 'a' + 'b'
// end::string_plus[]
}
+ @Test
void testGString() {
// tag::gstring_1[]
def name = 'Guillaume' // a plain string
@@ -357,6 +377,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::gstring_6[]
}
+ @Test
void testCharacters() {
// tag::char[]
char c1 = 'A' // <1>
@@ -370,6 +391,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::char[]
}
+ @Test
void testInterpolatingClosuresInGstrings() {
// tag::closure_in_gstring_1[]
def sParameterLessClosure = "1 + 2 == ${-> 3}" // <1>
@@ -393,6 +415,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::closure_in_gstring_2[]
}
+ @Test
void testGStringCoercerdToStringInMethodCallExpectingString() {
assertScript '''
// tag::java_gstring_interop_1[]
@@ -411,6 +434,7 @@ class SyntaxTest extends CompilableTestSupport {
'''
}
+ @Test
void testStringGStringHashCode() {
// tag::gstring_hashcode_1[]
assert "one: ${1}".hashCode() != "one: 1".hashCode()
@@ -424,6 +448,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::gstring_hashcode_2[]
}
+ @Test
void testTripleSingleQuotedString() {
// tag::triple_single_0[]
'''a triple-single-quoted string'''
@@ -454,6 +479,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::triple_single_3[]
}
+ @Test
void testTripleDoubleQuotedString() {
// tag::triple_double_1[]
def name = 'Groovy'
@@ -471,6 +497,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::triple_double_1[]
}
+ @Test
void testSlashyString() {
// tag::slashy_1[]
def fooPattern = /.*foo.*/
@@ -504,6 +531,7 @@ class SyntaxTest extends CompilableTestSupport {
'''
}
+ @Test
void testDollarSlashyString() {
// tag::dollar_slashy_1[]
def name = "Guillaume"
@@ -536,6 +564,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::dollar_slashy_1[]
}
+ @Test
void testIntegralNumberDeclarations() {
// tag::int_decl[]
// primitive types
@@ -557,6 +586,7 @@ class SyntaxTest extends CompilableTestSupport {
assert bi instanceof BigInteger
}
+ @Test
void testDecimalNumberDeclarations() {
// tag::float_decl[]
// primitive types
@@ -580,6 +610,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::float_exp[]
}
+ @Test
void testWideningIntegralValueTypes() {
// positive values
// tag::wide_int_positive[]
@@ -626,6 +657,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::wide_int_negative[]
}
+ @Test
void testNumberPower() {
// tag::number_power[]
// base and exponent are ints and the result can be represented by an
Integer
@@ -668,6 +700,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::number_power[]
}
+ @Test
void testLists() {
// tag::list_1[]
def numbers = [1, 2, 3] // <1>
@@ -720,6 +753,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::multi_dim_list[]
}
+ @Test
void testArrays() {
// tag::array_1[]
String[] arrStr = ['Ananas', 'Banana', 'Kiwi'] // <1>
@@ -751,6 +785,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::array_3[]
}
+ @Test
void testMaps() {
// tag::map_def_access[]
def colors = [red: '#FF0000', green: '#00FF00', blue: '#0000FF'] //
<1>
@@ -796,6 +831,7 @@ class SyntaxTest extends CompilableTestSupport {
// end::variable_key_2[]
}
+ @Test
void testReservedKeywords() {
def rk = '''
// tag::reserved_keywords[]
@@ -883,6 +919,7 @@ class SyntaxTest extends CompilableTestSupport {
}
}
+ @Test
void testContextualKeywords() {
def ck = '''
// tag::contextual_keywords[]
@@ -926,6 +963,7 @@ class SyntaxTest extends CompilableTestSupport {
}
}
+ @Test
void testOtherReservedWords() {
def rw = '''
// tag::reserved_words[]
@@ -966,7 +1004,6 @@ class SyntaxTest extends CompilableTestSupport {
def $it = true
"""
}
-
}
}
}
diff --git a/src/spec/test/semantics/OptionalityTest.groovy
b/src/spec/test/semantics/OptionalityTest.groovy
index 4cc760aa1f..b2c18c9221 100644
--- a/src/spec/test/semantics/OptionalityTest.groovy
+++ b/src/spec/test/semantics/OptionalityTest.groovy
@@ -19,9 +19,11 @@
package semantics
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class OptionalityTest extends CompilableTestSupport {
+final class OptionalityTest extends CompilableTestSupport {
+ @Test
void testOptionalParentheses() {
// tag::optional_parentheses[]
println 'Hello World'
@@ -29,6 +31,7 @@ class OptionalityTest extends CompilableTestSupport {
// end::optional_parentheses[]
}
+ @Test
void testRequiredParentheses() {
// tag::required_parentheses[]
println()
@@ -36,6 +39,7 @@ class OptionalityTest extends CompilableTestSupport {
// end::required_parentheses[]
}
+ @Test
void testOptionalSemicolons() {
// tag::single_statement_with_semicolon[]
assert true;
@@ -46,12 +50,14 @@ class OptionalityTest extends CompilableTestSupport {
// end::single_statement_without_semicolon[]
}
+ @Test
void testRequiredSemicolons() {
// tag::statements_separated_by_semicolon[]
boolean a = true; assert a
// end::statements_separated_by_semicolon[]
}
+ @Test
void testOptionalReturn() {
assertScript '''
// tag::return_keyword[]
@@ -71,6 +77,7 @@ class OptionalityTest extends CompilableTestSupport {
'''
}
+ @Test
void testOptionalPublic() {
shouldCompile '''
// tag::public_keyword[]
diff --git a/src/test/groovy/bugs/Groovy3596Bug.groovy
b/src/test/groovy/bugs/Groovy3596Bug.groovy
index a810a865cf..94d5871449 100644
--- a/src/test/groovy/bugs/Groovy3596Bug.groovy
+++ b/src/test/groovy/bugs/Groovy3596Bug.groovy
@@ -19,8 +19,11 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy3596Bug extends CompilableTestSupport {
+final class Groovy3596Bug extends CompilableTestSupport {
+
+ @Test
void testMapReferenceWithGenericsTypeParameters() {
shouldCompile """
interface TypeDescriptor3596 {}
diff --git a/src/test/groovy/bugs/Groovy3721Bug.groovy
b/src/test/groovy/bugs/Groovy3721Bug.groovy
index 56f5331a3e..07d30f278c 100644
--- a/src/test/groovy/bugs/Groovy3721Bug.groovy
+++ b/src/test/groovy/bugs/Groovy3721Bug.groovy
@@ -19,8 +19,11 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy3721Bug extends CompilableTestSupport {
+final class Groovy3721Bug extends CompilableTestSupport {
+
+ @Test
void testCompilationWithDuplicateJavaBeanProperties() {
shouldNotCompile """
class Foo3721V1 {
diff --git a/src/test/groovy/bugs/Groovy3768Bug.groovy
b/src/test/groovy/bugs/Groovy3768Bug.groovy
index 191ad80719..49b715e50c 100644
--- a/src/test/groovy/bugs/Groovy3768Bug.groovy
+++ b/src/test/groovy/bugs/Groovy3768Bug.groovy
@@ -19,8 +19,11 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy3768Bug extends CompilableTestSupport {
+final class Groovy3768Bug extends CompilableTestSupport {
+
+ @Test
void testLocalVariableMarkedStatic() {
shouldNotCompile """
diff --git a/src/test/groovy/bugs/Groovy3817Bug.groovy
b/src/test/groovy/bugs/Groovy3817Bug.groovy
index c0c0d09c77..165805b71e 100644
--- a/src/test/groovy/bugs/Groovy3817Bug.groovy
+++ b/src/test/groovy/bugs/Groovy3817Bug.groovy
@@ -19,8 +19,11 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy3817Bug extends CompilableTestSupport {
+final class Groovy3817Bug extends CompilableTestSupport {
+
+ @Test
void testUsageOfRangeExpressionJustAfterTryCatch() {
shouldCompile """
try { println "nix" }
diff --git a/src/test/groovy/bugs/Groovy3857Bug.groovy
b/src/test/groovy/bugs/Groovy3857Bug.groovy
index 97ac9233c9..c424d878ee 100644
--- a/src/test/groovy/bugs/Groovy3857Bug.groovy
+++ b/src/test/groovy/bugs/Groovy3857Bug.groovy
@@ -19,8 +19,11 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy3857Bug extends CompilableTestSupport {
+final class Groovy3857Bug extends CompilableTestSupport {
+
+ @Test
void testInterfaceDefWithGenericsFollowedByANewLine() {
shouldCompile """
public interface MyMy <T extends Object>
diff --git a/src/test/groovy/bugs/Groovy3989Bug.groovy
b/src/test/groovy/bugs/Groovy3989Bug.groovy
index 74f3472c2a..34bb35c263 100644
--- a/src/test/groovy/bugs/Groovy3989Bug.groovy
+++ b/src/test/groovy/bugs/Groovy3989Bug.groovy
@@ -19,8 +19,11 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy3989Bug extends CompilableTestSupport {
+final class Groovy3989Bug extends CompilableTestSupport {
+
+ @Test
void testOverridingFinalMethods() {
shouldNotCompile """
class A {
diff --git a/src/test/groovy/bugs/Groovy4025Bug.groovy
b/src/test/groovy/bugs/Groovy4025Bug.groovy
index 406d9ed179..75cd4062f3 100644
--- a/src/test/groovy/bugs/Groovy4025Bug.groovy
+++ b/src/test/groovy/bugs/Groovy4025Bug.groovy
@@ -19,9 +19,12 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy4025Bug extends CompilableTestSupport {
- public void testAMethodWithBodyInAnInterface() {
+final class Groovy4025Bug extends CompilableTestSupport {
+
+ @Test
+ void testAMethodWithBodyInAnInterface() {
shouldNotCompile """
interface ITest {
def foo(a, b) {
@@ -30,7 +33,9 @@ class Groovy4025Bug extends CompilableTestSupport {
}
"""
}
- public void testAbstractMethodInAClass() {
+
+ @Test
+ void testAbstractMethodInAClass() {
shouldNotCompile """
abstract class Test {
abstract foo(a, b) {
diff --git a/src/test/groovy/bugs/Groovy4043Bug.groovy
b/src/test/groovy/bugs/Groovy4043Bug.groovy
index 40ce99619f..865437474b 100644
--- a/src/test/groovy/bugs/Groovy4043Bug.groovy
+++ b/src/test/groovy/bugs/Groovy4043Bug.groovy
@@ -19,8 +19,11 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy4043Bug extends CompilableTestSupport {
+final class Groovy4043Bug extends CompilableTestSupport {
+
+ @Test
void testResolveInnerClsDefByAParent() {
shouldCompile """
class A4043 {
diff --git a/src/test/groovy/bugs/Groovy4081Bug.groovy
b/src/test/groovy/bugs/Groovy4081Bug.groovy
index 6ca87bd712..1dcad9d10a 100644
--- a/src/test/groovy/bugs/Groovy4081Bug.groovy
+++ b/src/test/groovy/bugs/Groovy4081Bug.groovy
@@ -19,9 +19,12 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy4081Bug extends CompilableTestSupport {
- public void testEnumConstructorCallFromOutsideEnum() {
+final class Groovy4081Bug extends CompilableTestSupport {
+
+ @Test
+ void testEnumConstructorCallFromOutsideEnum() {
shouldNotCompile """
enum Alphabet {
A(1), Z(26)
diff --git a/src/test/groovy/bugs/Groovy4151Bug.groovy
b/src/test/groovy/bugs/Groovy4151Bug.groovy
index a4325ce4a5..7bd68cd85c 100644
--- a/src/test/groovy/bugs/Groovy4151Bug.groovy
+++ b/src/test/groovy/bugs/Groovy4151Bug.groovy
@@ -19,15 +19,18 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy4151Bug extends CompilableTestSupport {
+final class Groovy4151Bug extends CompilableTestSupport {
+
+ @Test
void testPrintThisInGString() {
- shouldCompile """
+ shouldCompile '''
class C4151 {
class S4151 {
S4151() { println "$this" }
}
}
- """
+ '''
}
}
diff --git a/src/test/groovy/bugs/Groovy4169Bug.groovy
b/src/test/groovy/bugs/Groovy4169Bug.groovy
index 8d9f5179f3..9f46d50aa0 100644
--- a/src/test/groovy/bugs/Groovy4169Bug.groovy
+++ b/src/test/groovy/bugs/Groovy4169Bug.groovy
@@ -19,8 +19,11 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy4169Bug extends CompilableTestSupport {
+final class Groovy4169Bug extends CompilableTestSupport {
+
+ @Test
void testClosureParameterWithAnnotations() {
shouldCompile """
import java.lang.annotation.*
diff --git a/src/test/groovy/bugs/Groovy4190Bug.groovy
b/src/test/groovy/bugs/Groovy4190Bug.groovy
index 508053de8e..9c63370a8b 100644
--- a/src/test/groovy/bugs/Groovy4190Bug.groovy
+++ b/src/test/groovy/bugs/Groovy4190Bug.groovy
@@ -19,8 +19,11 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy4190Bug extends CompilableTestSupport {
+final class Groovy4190Bug extends CompilableTestSupport {
+
+ @Test
void testGenericsUsageInMethodCall() {
shouldCompile """
class Test4190<E> {
@@ -39,6 +42,7 @@ class Groovy4190Bug extends CompilableTestSupport {
"""
}
+ @Test
void testGenericsUsageInMethodCall2() {
shouldCompile """
class Test4190V2<K,V> {
diff --git a/src/test/groovy/bugs/Groovy4325Bug.groovy
b/src/test/groovy/bugs/Groovy4325Bug.groovy
index ef2cdbe062..36959697d3 100644
--- a/src/test/groovy/bugs/Groovy4325Bug.groovy
+++ b/src/test/groovy/bugs/Groovy4325Bug.groovy
@@ -19,8 +19,11 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy4325Bug extends CompilableTestSupport {
+final class Groovy4325Bug extends CompilableTestSupport {
+
+ @Test
void testMultipleDefaultCases() {
shouldNotCompile """
def foo() {
diff --git a/src/test/groovy/bugs/Groovy4356Bug.groovy
b/src/test/groovy/bugs/Groovy4356Bug.groovy
index 750a2a7e4f..1d744ef174 100644
--- a/src/test/groovy/bugs/Groovy4356Bug.groovy
+++ b/src/test/groovy/bugs/Groovy4356Bug.groovy
@@ -19,9 +19,11 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy4356Bug extends CompilableTestSupport {
+final class Groovy4356Bug extends CompilableTestSupport {
+ @Test
void testDeclareGenericPropertyInNestedClassWithGenericTypeAtNestedLevel()
{
shouldCompile """
class OuterS1<T1> {
@@ -33,6 +35,7 @@ class Groovy4356Bug extends CompilableTestSupport {
"""
}
+ @Test
void testDeclareGenericParameterInStaticMethodWithMethodLevelGenericType()
{
shouldCompile """
class TestS2 {
@@ -41,6 +44,7 @@ class Groovy4356Bug extends CompilableTestSupport {
"""
}
+ @Test
void testDeclareGenericLocalVarInStaticMethodWithMethodLevelGenericType() {
shouldCompile """
class TestS3 {
@@ -51,6 +55,7 @@ class Groovy4356Bug extends CompilableTestSupport {
"""
}
+ @Test
void testDeclareGenericPropertyOfInnerClassWithGenericTypeAtOuterLevel() {
shouldCompile """
class Outer<T4> {
@@ -62,6 +67,7 @@ class Groovy4356Bug extends CompilableTestSupport {
"""
}
+ @Test
void testDeclareGenericPropertyOfNestedClassWithGenericTypeAtOuterLevel() {
shouldNotCompile """
class Outer<T5> {
@@ -73,6 +79,7 @@ class Groovy4356Bug extends CompilableTestSupport {
"""
}
+ @Test
void testDeclareGenericStaticPropertyOfClassWithGenericType() {
shouldNotCompile """
class Test1<T6> {
@@ -81,6 +88,7 @@ class Groovy4356Bug extends CompilableTestSupport {
"""
}
+ @Test
void testDeclareGenericParameterInStaticMethodOfClassWithGenericType() {
shouldNotCompile """
class Test2<T7> {
@@ -89,6 +97,7 @@ class Groovy4356Bug extends CompilableTestSupport {
"""
}
+ @Test
void testDeclareGenericLocalVarInStaticMethodOfClassWithGenericType() {
shouldNotCompile """
class Test3<T8> {
diff --git a/src/test/groovy/bugs/Groovy4614Bug.groovy
b/src/test/groovy/bugs/Groovy4614Bug.groovy
index 5ffcc26789..c8810df08e 100644
--- a/src/test/groovy/bugs/Groovy4614Bug.groovy
+++ b/src/test/groovy/bugs/Groovy4614Bug.groovy
@@ -19,9 +19,11 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy4614Bug extends CompilableTestSupport {
+final class Groovy4614Bug extends CompilableTestSupport {
+ @Test
void testStaticOnOuterClassForbidden() {
shouldNotCompile """
static class StaticOuterClass {}
@@ -34,4 +36,3 @@ class Groovy4614Bug extends CompilableTestSupport {
"""
}
}
-
diff --git a/src/test/groovy/bugs/Groovy6271Bug.groovy
b/src/test/groovy/bugs/Groovy6271Bug.groovy
index 3f51b7b534..437b650a0c 100644
--- a/src/test/groovy/bugs/Groovy6271Bug.groovy
+++ b/src/test/groovy/bugs/Groovy6271Bug.groovy
@@ -20,8 +20,9 @@ package bugs
import gls.CompilableTestSupport
import groovy.test.NotYetImplemented
+import org.junit.jupiter.api.Test
-class Groovy6271Bug extends CompilableTestSupport {
+final class Groovy6271Bug extends CompilableTestSupport {
/*
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
@@ -37,7 +38,7 @@
TestScripttestTraitWithCompileStaticAndCoercedClosure0.groovy: 33: [Static type
2 errors
*/
- @NotYetImplemented
+ @NotYetImplemented @Test
void testGroovy6271Bug() {
shouldCompile '''
@Grab('org.functionaljava:functionaljava:3.1')
diff --git a/src/test/groovy/bugs/Groovy6792Bug.groovy
b/src/test/groovy/bugs/Groovy6792Bug.groovy
index 28c2b01470..13a2958872 100644
--- a/src/test/groovy/bugs/Groovy6792Bug.groovy
+++ b/src/test/groovy/bugs/Groovy6792Bug.groovy
@@ -19,31 +19,36 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.AfterEach
+import org.junit.jupiter.api.Test
-class Groovy6792Bug extends CompilableTestSupport {
+final class Groovy6792Bug extends CompilableTestSupport {
+
+ @Test
void testMethodWithSpecialCharsInName() {
- assertScript """
+ assertScript '''
class Foo {
static ",{}()|!?foo@#\\\$%^&*-=]\\\\bar'\\""(){ Foo.name }
}
assert Foo.",{}()|!?foo@#\\\$%^&*-=]\\\\bar'\\""() == 'Foo'
- """
+ '''
}
+ @Test
void testMethodWithInvalidName() {
// currently groovy.compiler.strictNames is experimental
System.setProperty('groovy.compiler.strictNames', 'true')
- def message = shouldNotCompile """
+
+ def message = shouldNotCompile '''
class Foo {
def "bar.baz"(){}
}
- """
+ '''
assert message.contains("You are not allowed to have '.' in a method
name")
}
- @Override
- protected void tearDown() throws Exception {
- super.tearDown()
- System.setProperty('groovy.compiler.strictNames', 'false')
+ @AfterEach
+ void tearDown() {
+ System.clearProperty('groovy.compiler.strictNames')
}
}
diff --git a/src/test/groovy/bugs/Groovy7922Bug.groovy
b/src/test/groovy/bugs/Groovy7922Bug.groovy
index e4ffdbf24e..35fb0733ae 100644
--- a/src/test/groovy/bugs/Groovy7922Bug.groovy
+++ b/src/test/groovy/bugs/Groovy7922Bug.groovy
@@ -19,9 +19,11 @@
package bugs;
import gls.CompilableTestSupport;
+import org.junit.jupiter.api.Test
-public class Groovy7922Bug extends CompilableTestSupport {
+final class Groovy7922Bug extends CompilableTestSupport {
+ @Test
void testMethodSelection() {
def message = shouldNotCompile '''
import groovy.transform.CompileStatic
diff --git a/src/test/groovy/bugs/Groovy7925Bug.groovy
b/src/test/groovy/bugs/Groovy7925Bug.groovy
index cb5261fe35..f17570e9a8 100644
--- a/src/test/groovy/bugs/Groovy7925Bug.groovy
+++ b/src/test/groovy/bugs/Groovy7925Bug.groovy
@@ -19,8 +19,11 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy7925Bug extends CompilableTestSupport {
+final class Groovy7925Bug extends CompilableTestSupport {
+
+ @Test
void testThisAndSuperOnLHS() {
def message = shouldNotCompile '''
super += true
diff --git a/src/test/groovy/bugs/Groovy8066Bug.groovy
b/src/test/groovy/bugs/Groovy8066Bug.groovy
index 1f16c9051a..7a1c01c4f6 100644
--- a/src/test/groovy/bugs/Groovy8066Bug.groovy
+++ b/src/test/groovy/bugs/Groovy8066Bug.groovy
@@ -19,8 +19,11 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy8066Bug extends CompilableTestSupport {
+final class Groovy8066Bug extends CompilableTestSupport {
+
+ @Test
void testTraitWithProtectedFieldShouldGiveCompileError() {
def message = shouldNotCompile """
trait Foo {
diff --git a/src/test/groovy/bugs/Groovy8342Bug.groovy
b/src/test/groovy/bugs/Groovy8342Bug.groovy
index 63c106abb4..2fbde18427 100644
--- a/src/test/groovy/bugs/Groovy8342Bug.groovy
+++ b/src/test/groovy/bugs/Groovy8342Bug.groovy
@@ -19,8 +19,11 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy8342Bug extends CompilableTestSupport {
+final class Groovy8342Bug extends CompilableTestSupport {
+
+ @Test
void testCorrectHandlingForArrayOfGenericType() {
shouldCompile '''
@groovy.transform.CompileStatic
diff --git a/src/test/groovy/bugs/Groovy8405Bug.groovy
b/src/test/groovy/bugs/Groovy8405Bug.groovy
index d5321eb8ed..e8955777d1 100644
--- a/src/test/groovy/bugs/Groovy8405Bug.groovy
+++ b/src/test/groovy/bugs/Groovy8405Bug.groovy
@@ -19,8 +19,11 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy8405Bug extends CompilableTestSupport {
+final class Groovy8405Bug extends CompilableTestSupport {
+
+ @Test
void test() {
assertScript '''
import groovy.transform.CompileStatic
@@ -45,8 +48,6 @@ class Groovy8405Bug extends CompilableTestSupport {
assert 'hi' == string
}
}
-
'''
}
-
}
diff --git a/src/test/groovy/bugs/Groovy8549Bug.groovy
b/src/test/groovy/bugs/Groovy8549Bug.groovy
index 144f6b8569..44b6b737a9 100644
--- a/src/test/groovy/bugs/Groovy8549Bug.groovy
+++ b/src/test/groovy/bugs/Groovy8549Bug.groovy
@@ -19,8 +19,11 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy8549Bug extends CompilableTestSupport {
+final class Groovy8549Bug extends CompilableTestSupport {
+
+ @Test
void testNumberWithVarSlotLoader() {
assertScript """
import groovy.transform.CompileStatic
diff --git a/src/test/groovy/bugs/Groovy8595Bug.groovy
b/src/test/groovy/bugs/Groovy8595Bug.groovy
index f9e6f9c251..8f238dfa87 100644
--- a/src/test/groovy/bugs/Groovy8595Bug.groovy
+++ b/src/test/groovy/bugs/Groovy8595Bug.groovy
@@ -19,8 +19,11 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy8595Bug extends CompilableTestSupport {
+final class Groovy8595Bug extends CompilableTestSupport {
+
+ @Test
void testGroovy8595() {
shouldCompile '''
@groovy.transform.CompileStatic
@@ -41,6 +44,7 @@ class Groovy8595Bug extends CompilableTestSupport {
'''
}
+ @Test
void testMethodCallInPropertyExpression() {
shouldCompile '''
@groovy.transform.CompileStatic
diff --git a/src/test/groovy/bugs/Groovy8797Bug.groovy
b/src/test/groovy/bugs/Groovy8797Bug.groovy
index d46050f4fd..d299211fa7 100644
--- a/src/test/groovy/bugs/Groovy8797Bug.groovy
+++ b/src/test/groovy/bugs/Groovy8797Bug.groovy
@@ -19,8 +19,11 @@
package bugs
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy8797Bug extends CompilableTestSupport {
+final class Groovy8797Bug extends CompilableTestSupport {
+
+ @Test
void testStaticBooleanIsPropertyInStaticContext() {
shouldCompile """
class C {
diff --git
a/src/test/groovy/gls/annotations/closures/AnnotationClosureTest.groovy
b/src/test/groovy/gls/annotations/closures/AnnotationClosureTest.groovy
index ba3a902a06..51d81d5b09 100644
--- a/src/test/groovy/gls/annotations/closures/AnnotationClosureTest.groovy
+++ b/src/test/groovy/gls/annotations/closures/AnnotationClosureTest.groovy
@@ -19,6 +19,7 @@
package gls.annotations.closures
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
@@ -30,6 +31,7 @@ final class AnnotationClosureTest extends
CompilableTestSupport {
def answer() { 42 }
}
+ @Test
void testGep3InClosure() {
shouldCompile '''
@interface Bar{Class value();}
@@ -40,6 +42,7 @@ final class AnnotationClosureTest extends
CompilableTestSupport {
'''
}
+ @Test
void testAllowedAsValueForAnnotationElementOfTypeClass() {
shouldCompile '''
import gls.annotations.closures.AnnWithClassElement
@@ -50,7 +53,7 @@ final class AnnotationClosureTest extends
CompilableTestSupport {
}
// TODO: two compile errors instead of one, odd error message
-
+ @Test
void testNotAllowedAsValueForAnnotationElementOfOtherType() {
shouldNotCompile '''
import gls.annotations.closures.AnnWithStringElement
@@ -60,16 +63,19 @@ final class AnnotationClosureTest extends
CompilableTestSupport {
'''
}
+ @Test
void testIsCompiledToPublicClass() {
def closureClass =
ClassWithAnnClosure.getAnnotation(AnnWithClassElement).elem()
assert Modifier.isPublic(closureClass.modifiers)
}
+ @Test
void testDefaultValueIsCompiledToPublicClass() {
def closureClass =
ClosureAsDefaultValue.getAnnotation(AnnWithDefaultValue).elem()
assert Modifier.isPublic(closureClass.modifiers)
}
+ @Test
void testCanBeUsedAsDefaultValue() {
def closureClass =
ClosureAsDefaultValue.getAnnotation(AnnWithDefaultValue).elem()
def closure = closureClass.newInstance(null, null)
@@ -77,6 +83,7 @@ final class AnnotationClosureTest extends
CompilableTestSupport {
assert closure.call() == 3
}
+ @Test
void testCanBeNested() {
def closureClass =
NestedClosure.getAnnotation(AnnWithClassElement).elem()
def closure = closureClass.newInstance(null, null)
@@ -84,6 +91,7 @@ final class AnnotationClosureTest extends
CompilableTestSupport {
assert closure.call(9) == 9
}
+ @Test
void testWorksOnInnerClass() {
def closureClass =
ClassWithAnnClosure.InnerClassWithAnnClosure.getAnnotation(AnnWithClassElement).elem()
def closure = closureClass.newInstance(null, null)
@@ -91,6 +99,7 @@ final class AnnotationClosureTest extends
CompilableTestSupport {
assert closure.call() == 3
}
+ @Test
void testWorksOnNestedClass() {
def closureClass =
ClassWithAnnClosure.NestedClassWithAnnClosure.getAnnotation(AnnWithClassElement).elem()
def closure = closureClass.newInstance(null, null)
@@ -98,6 +107,7 @@ final class AnnotationClosureTest extends
CompilableTestSupport {
assert closure.call() == 3
}
+ @Test
void testWorksOnNestedAnnotation() {
def closureClass =
NestedAnnotation.getAnnotation(AnnWithNestedAnn).elem().elem()
def closure = closureClass.newInstance(null, null)
@@ -105,6 +115,7 @@ final class AnnotationClosureTest extends
CompilableTestSupport {
assert closure.call() == 3
}
+ @Test
void testWorksOnNestedAnnotationWithDefaultValue() {
def closureClass =
NestedAnnotationWithDefault.getAnnotation(AnnWithNestedAnnWithDefault).elem().elem()
def closure = closureClass.newInstance(null, null)
@@ -112,6 +123,7 @@ final class AnnotationClosureTest extends
CompilableTestSupport {
assert closure.call() == 3
}
+ @Test
void testWorksOnAnnotationWithArray() {
def closureClasses =
ClassWithAnnArrayClosure.getAnnotation(AnnWithClassArrayElement).elem()
assert closureClasses?.size() == 2
@@ -119,6 +131,7 @@ final class AnnotationClosureTest extends
CompilableTestSupport {
assert closureClasses[1].newInstance(null, null)() == 5
}
+ @Test
void testMayContainGString() {
def closureClass =
ClosureWithGString.getAnnotation(AnnWithClassElement).elem()
def closure = closureClass.newInstance(null, null)
@@ -126,6 +139,7 @@ final class AnnotationClosureTest extends
CompilableTestSupport {
assert closure.call([1, 2, 3]) == "list has 3 elements"
}
+ @Test
void testDoesNoHarmOnAnnotationWithSourceRetention() {
shouldCompile '''
import java.lang.annotation.*
@@ -140,6 +154,7 @@ final class AnnotationClosureTest extends
CompilableTestSupport {
'''
}
+ @Test
void testDoesNoHarmOnAnnotationWithClassRetention() {
shouldCompile '''
import java.lang.annotation.*
@@ -155,6 +170,7 @@ final class AnnotationClosureTest extends
CompilableTestSupport {
}
// GROOVY-7033
+ @Test
void testAnnotationOnAnonymousInnerClassMethod() {
assertScript '''
import java.lang.annotation.*
diff --git a/src/test/groovy/gls/ch08/s04/FormalParameterTest.groovy
b/src/test/groovy/gls/ch08/s04/FormalParameterTest.groovy
index 2748cd804d..dccb061fe4 100644
--- a/src/test/groovy/gls/ch08/s04/FormalParameterTest.groovy
+++ b/src/test/groovy/gls/ch08/s04/FormalParameterTest.groovy
@@ -19,6 +19,7 @@
package gls.ch08.s04
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
/**
* a formal parameter is a parameter to a method, this parameter must work
@@ -26,8 +27,9 @@ import gls.CompilableTestSupport
* is not possible for formal parameters. The type is given through the
* method signature.
*/
-class FormalParameterTest extends CompilableTestSupport {
+final class FormalParameterTest extends CompilableTestSupport {
+ @Test
void testPrimitiveParameterAssignment() {
// test int and long as they have different lengths on in the bytecode
assert intMethod(1i, 2i) == 2i
@@ -80,6 +82,7 @@ class FormalParameterTest extends CompilableTestSupport {
}
}
+ @Test
void testVariableArity() {
def l1 = dump(22, 'Ken', 'Barclay')
def l2 = ["name: Ken age: 22", "name: Barclay age: 22"]
@@ -87,5 +90,4 @@ class FormalParameterTest extends CompilableTestSupport {
assert it == l2[i]
}
}
-
-}
\ No newline at end of file
+}
diff --git a/src/test/groovy/gls/classes/methods/RepetitiveMethodTest.groovy
b/src/test/groovy/gls/classes/methods/RepetitiveMethodTest.groovy
index e9824f23b3..a09e71e238 100644
--- a/src/test/groovy/gls/classes/methods/RepetitiveMethodTest.groovy
+++ b/src/test/groovy/gls/classes/methods/RepetitiveMethodTest.groovy
@@ -19,9 +19,11 @@
package gls.classes.methods
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class RepetitiveMethodTest extends CompilableTestSupport {
+final class RepetitiveMethodTest extends CompilableTestSupport {
+ @Test
void testRepetitiveMethod() {
def message = shouldNotCompile('''
class A {
@@ -32,6 +34,7 @@ class RepetitiveMethodTest extends CompilableTestSupport {
assert message.contains('duplicates another method of the same
signature')
}
+ @Test
void testRepetitiveMethodsAllowedForProperties() {
shouldCompile '''
class PropertyOverride {
@@ -49,6 +52,7 @@ class RepetitiveMethodTest extends CompilableTestSupport {
'''
}
+ @Test
void testRepetitiveConstructor() {
def message = shouldNotCompile('''
class A {
diff --git a/src/test/groovy/gls/enums/EnumTest.groovy
b/src/test/groovy/gls/enums/EnumTest.groovy
index c490ea04d6..dc5b92085d 100644
--- a/src/test/groovy/gls/enums/EnumTest.groovy
+++ b/src/test/groovy/gls/enums/EnumTest.groovy
@@ -19,35 +19,43 @@
package gls.enums
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
+
+import static groovy.test.GroovyAssert.shouldFail
/**
* Tests various properties of enums.
*/
-class EnumTest extends CompilableTestSupport {
+final class EnumTest extends CompilableTestSupport {
+ @Test
void testValues() {
assert UsCoin.values().size() == 4
assert UsCoin.values().toList().sum{ it.value } == 41
}
+ @Test
void testNext() {
def coin = UsCoin.penny
def coins = [coin++, coin++, coin++, coin++, coin]
assert coins == [UsCoin.penny, UsCoin.nickel, UsCoin.dime,
UsCoin.quarter, UsCoin.penny]
}
+ @Test
void testPrevious() {
def coin = UsCoin.quarter
def coins = [coin--, coin--, coin--, coin--, coin]
assert coins == [UsCoin.quarter, UsCoin.dime, UsCoin.nickel,
UsCoin.penny, UsCoin.quarter]
}
+ @Test
void testRange() {
def coinRange1 = UsCoin.penny..UsCoin.dime
assert (UsCoin.nickel in coinRange1)
assert !(UsCoin.quarter in coinRange1)
}
+ @Test
void testMinValue() {
assert UsCoin.MIN_VALUE == UsCoin.penny
shouldFail(MissingPropertyException) {
@@ -55,6 +63,7 @@ class EnumTest extends CompilableTestSupport {
}
}
+ @Test
void testMaxValue() {
assert UsCoin.MAX_VALUE == UsCoin.quarter
shouldFail(MissingPropertyException) {
@@ -62,6 +71,7 @@ class EnumTest extends CompilableTestSupport {
}
}
+ @Test
void testComparators() {
assert UsCoin.nickel <=> UsCoin.penny == 1
assert UsCoin.nickel <=> UsCoin.nickel == 0
@@ -72,6 +82,7 @@ class EnumTest extends CompilableTestSupport {
assert UsCoin.nickel >= UsCoin.nickel
}
+ @Test
void testStepWithRange() {
def coinRange2 = UsCoin.nickel..UsCoin.quarter
def coins = coinRange2.toList()
@@ -92,6 +103,7 @@ class EnumTest extends CompilableTestSupport {
assert coins == [UsCoin.quarter]
}
+ @Test
void testStepWithReverseRange() {
def coinRange2 = UsCoin.quarter..UsCoin.nickel
def coins = coinRange2.toList()
@@ -112,6 +124,7 @@ class EnumTest extends CompilableTestSupport {
assert coins == [UsCoin.nickel]
}
+ @Test
void testEnumWithSingleListInConstructor() {
assertScript '''
enum ListEnum1 {
@@ -137,6 +150,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-3214
+ @Test
void testSingleListDoesNoInfluenceMaps() {
// the fix for GROOVY-2933 caused map["taku"] to become map[(["take])]
instead
assertScript '''
@@ -154,6 +168,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-3276
+ @Test
void testMutipleValuesDontGetWronglyWrappedInList() {
// the fix for GROOVY-3214 caused multiple values passed in an enum
const to get wrapped in an extra ListExpression
assertScript '''
@@ -174,6 +189,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-3161
+ @Test
void testStaticEnumFieldWithEnumValues() {
def allColors = GroovyColors3161.ALL_COLORS
assert allColors.size() == 3
@@ -183,6 +199,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-7025
+ @Test
void testStaticEnumFieldFromInit() {
def err = shouldNotCompile '''
enum E {
@@ -230,6 +247,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-3283
+ @Test
void testImportStaticMoreThanOneEnum() {
assertScript '''
enum Foo3283 { A,B }
@@ -244,6 +262,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-3284
+ @Test
void testCallBehaviorOnEnum() {
// test the usage in a non-script class first
for (f in Foo3284) {
@@ -276,6 +295,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-3483
+ @Test
void testClassResolutionForInnerEnumsWithPackageName() {
assertScript '''
package familie
@@ -297,6 +317,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-3110
+ @Test
void testInnerEnumUsedInDefiningClassWithUnqualifiedEnumNameUsed() {
assertScript '''
class C {
@@ -321,6 +342,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-11198
+ @Test
void testInnerEnumInitWithUnqualifiedOuterClassField() {
assertScript '''
class C {
@@ -338,6 +360,7 @@ class EnumTest extends CompilableTestSupport {
'''
}
+ @Test
void testInnerEnumInitWithUnqualifiedOuterClassValue() {
assertScript '''
class C {
@@ -356,12 +379,14 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-3693
+ @Test
void testStaticFieldInitValuesInAStaticBlock() {
// trigger enum class load to test it - asserts are present in the enum
GroovyColors3693.r
}
// GROOVY-2443
+ @Test
void testCustomMethodOnEnum() {
assertScript '''
enum Day {
@@ -375,6 +400,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-3985
+ @Test
void testEnumConstantSubClassINITMethodOverrideINITOfEnumClass() {
try {
// cause loading of enum that causes its fields to be set and
@@ -386,6 +412,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-3996
+ @Test
void testEnumStaticInitWithAFieldUsingEnumValues() {
assertScript '''
enum Color3996 {
@@ -401,6 +428,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-3986
+ @Test
void testEnumWithTopLevelNoBracketsMethodCall() {
assertScript '''
enum Color3986 {
@@ -413,6 +441,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-3047
+ @Test
void testEnumConstantSeparators() {
shouldCompile '''
enum Foo0 { X }
@@ -450,6 +479,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-4268
+ @Test
void testEnumWithSingleValueAndClassField() {
shouldCompile '''
enum EnumWithSingleValueAndClassField {
@@ -460,6 +490,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-4444
+ @Test
void testConstructorChainingInEnum() {
assertScript '''
enum Foo4444 {
@@ -491,6 +522,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-6065
+ @Test
void testOverridingMethodsWithExplicitConstructor() {
assertScript '''
enum Country {
@@ -507,6 +539,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-6747
+ @Test
void testOverridingMethodsWithExplicitConstructor2() {
assertScript '''
enum Codes {
@@ -531,6 +564,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-4641
+ @Test
void testAbstractMethodOverriding() {
assertScript '''
enum Day {
@@ -567,6 +601,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-5756
+ @Test
void testInnerClosureDefinitions() {
assertScript '''
enum E {
@@ -589,6 +624,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-4794
+ @Test
void testLenientTypeDefinitions() {
assertScript '''
enum E {
@@ -605,6 +641,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-4485
+ @Test
void testNamedArgs() {
assertScript '''
enum ExportFormat {
@@ -625,6 +662,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-6250
+ @Test
void testGenericMethodOverriding() {
assertScript '''
interface IVisitor<InputType, OutputType> {
@@ -649,6 +687,7 @@ class EnumTest extends CompilableTestSupport {
'''
}
+ @Test
void testVargsConstructor() {
assertScript '''
enum Test {
@@ -664,6 +703,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-7342
+ @Test
void testLastEnumValueIsAnnotatedWithoutTrailingComma() {
assertScript '''
import java.lang.annotation.ElementType;
@@ -686,6 +726,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-7773
+ @Test
void testEnumWithPropertiesAndDanglingComma() {
assertScript '''
enum UsState {
@@ -701,6 +742,7 @@ class EnumTest extends CompilableTestSupport {
'''
}
+ @Test
void testEnumConstantsTakePrecedenceOverClassProperties() {
assertScript '''
@Deprecated
@@ -713,6 +755,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-6747
+ @Test
void testEnumConstructorHasPrivateModifier() {
assertScript '''
enum Foo {
@@ -724,6 +767,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-8360
+ @Test
void testNestedEnumHasStaticModifier() {
assertScript '''
class Foo {
@@ -740,6 +784,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-8360
+ @Test
void testDeeplyNestedEnumHasStaticModifier() {
assertScript '''
class Foo {
@@ -758,6 +803,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-8360
+ @Test
void testNestedEnumHasStaticModifierSC() {
assertScript '''
@groovy.transform.CompileStatic
@@ -779,6 +825,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-8360
+ @Test
void testDeeplyNestedEnumHasStaticModifierSC() {
assertScript '''
@groovy.transform.CompileStatic
@@ -802,6 +849,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-9523
+ @Test
void testEnumConstMethodCallsAnEnumPrivateMethod() {
assertScript '''
class Foo {
@@ -825,6 +873,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-7024
+ @Test
void testEnumConstructorCallsOuterClassStaticMethod() {
assertScript '''
class Outer {
@@ -845,6 +894,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-10811
+ @Test
void testIllegalModifiers() {
for (mod in ['','public','@groovy.transform.PackageScope']) {
shouldCompile """
@@ -878,6 +928,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-10811
+ @Test
void testConstructorCheck() {
shouldNotCompile '''
enum E {
@@ -897,6 +948,7 @@ class EnumTest extends CompilableTestSupport {
}
// GROOVY-10811
+ @Test
void testSuperCtorCall() {
shouldNotCompile '''
enum E {
diff --git a/src/test/groovy/gls/invocation/GroovyObjectInheritanceTest.groovy
b/src/test/groovy/gls/invocation/GroovyObjectInheritanceTest.groovy
index f10cdd4fdd..fd8eb664d5 100644
--- a/src/test/groovy/gls/invocation/GroovyObjectInheritanceTest.groovy
+++ b/src/test/groovy/gls/invocation/GroovyObjectInheritanceTest.groovy
@@ -19,8 +19,11 @@
package gls.invocation
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class GroovyObjectInheritanceTest extends CompilableTestSupport {
+final class GroovyObjectInheritanceTest extends CompilableTestSupport {
+
+ @Test
void testInheritanceWithGetProperty() {
assertScript """
class Foo {
@@ -40,6 +43,7 @@ class GroovyObjectInheritanceTest extends
CompilableTestSupport {
"""
}
+ @Test
void testInheritanceWithSetProperty() {
assertScript """
class Foo {
@@ -63,6 +67,7 @@ class GroovyObjectInheritanceTest extends
CompilableTestSupport {
"""
}
+ @Test
void testInheritanceWithInvokeMethod() {
assertScript """
class Foo {
@@ -82,6 +87,7 @@ class GroovyObjectInheritanceTest extends
CompilableTestSupport {
"""
}
+ @Test
void testMetaClassFieldInheritance() {
assertScript """
class Foo {}
@@ -91,6 +97,7 @@ class GroovyObjectInheritanceTest extends
CompilableTestSupport {
"""
}
+ @Test
void testStandardInheritance() {
assertScript """
class Foo{}
@@ -115,4 +122,4 @@ class GroovyObjectInheritanceTest extends
CompilableTestSupport {
assert Bar.class.declaredMethods.find{it.name=="invokeMethod"}==null
"""
}
-}
\ No newline at end of file
+}
diff --git a/src/test/groovy/gls/invocation/MethodDeclarationTest.groovy
b/src/test/groovy/gls/invocation/MethodDeclarationTest.groovy
index 07470105f6..28faca7cd3 100644
--- a/src/test/groovy/gls/invocation/MethodDeclarationTest.groovy
+++ b/src/test/groovy/gls/invocation/MethodDeclarationTest.groovy
@@ -18,9 +18,12 @@
*/
package gls.invocation
-import gls.CompilableTestSupport;
+import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class MethodDeclarationTest extends CompilableTestSupport {
+final class MethodDeclarationTest extends CompilableTestSupport {
+
+ @Test
void testDuplicateMethod() {
shouldNotCompile """
class A {
diff --git a/src/test/groovy/gls/invocation/MethodSelectionTest.groovy
b/src/test/groovy/gls/invocation/MethodSelectionTest.groovy
index 9c0f3698fd..eea754d848 100644
--- a/src/test/groovy/gls/invocation/MethodSelectionTest.groovy
+++ b/src/test/groovy/gls/invocation/MethodSelectionTest.groovy
@@ -18,12 +18,16 @@
*/
package gls.invocation
-final class MethodSelectionTest extends gls.CompilableTestSupport {
+import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
+
+final class MethodSelectionTest extends CompilableTestSupport {
/**
* This test ensures Groovy can choose a method based on interfaces.
* Choosing such an interface should not be hidden by subclasses.
*/
+ @Test
void testMostSpecificInterface() {
assertScript '''
interface A{}
@@ -58,6 +62,7 @@ final class MethodSelectionTest extends
gls.CompilableTestSupport {
'''
}
+ @Test
void testMostGeneralForNull() {
// we use the same signatures with different method orders,
// because we want to catch method ordering bugs
@@ -97,6 +102,7 @@ final class MethodSelectionTest extends
gls.CompilableTestSupport {
'''
}
+ @Test
void testMethodSelectionException() {
assertScript '''
import
org.codehaus.groovy.runtime.metaclass.MethodSelectionException as MSE
@@ -116,6 +122,7 @@ final class MethodSelectionTest extends
gls.CompilableTestSupport {
}
// GROOVY-2719
+ @Test
void testMethodSelectionWithInterfaceVargsMethod() {
assertScript '''
public class Thing {}
@@ -129,6 +136,7 @@ final class MethodSelectionTest extends
gls.CompilableTestSupport {
}
// GROOVY-2698
+ @Test
void testComplexInterfaceInheritance() {
assertScript '''
import javax.swing.*
@@ -151,6 +159,7 @@ final class MethodSelectionTest extends
gls.CompilableTestSupport {
'''
}
+ @Test
void testNullUsageForPrimitivesWithExplicitNull() {
[byte,int,short,float,double,boolean,char].each { type ->
assertScript """
@@ -169,6 +178,7 @@ final class MethodSelectionTest extends
gls.CompilableTestSupport {
}
}
+ @Test
void testNullUsageForPrimitivesWithImplicitNull() {
[byte,int,short,float,double,boolean,char].each { type ->
assertScript """
@@ -187,6 +197,7 @@ final class MethodSelectionTest extends
gls.CompilableTestSupport {
}
}
+ @Test
void testNullUsageForPrimitivesAndOverloading() {
[byte,int,short,float,double].each { type ->
assertScript """
@@ -199,7 +210,8 @@ final class MethodSelectionTest extends
gls.CompilableTestSupport {
}
}
- void testPrivateMethodSelectionFromClosure(){
+ @Test
+ void testPrivateMethodSelectionFromClosure() {
assertScript '''
class I1 {
private foo() {1}
@@ -216,7 +228,8 @@ final class MethodSelectionTest extends
gls.CompilableTestSupport {
'''
}
- void testCachingForNullAndPrimitive(){
+ @Test
+ void testCachingForNullAndPrimitive() {
assertScript '''
boolean shaky(boolean defaultValue) {false}
shaky(false)
@@ -269,6 +282,7 @@ final class MethodSelectionTest extends
gls.CompilableTestSupport {
'''
}
+ @Test
void testCallWithExendedBigDecimal() {
assertScript '''
BigDecimal f (BigDecimal x) {
@@ -286,6 +300,7 @@ final class MethodSelectionTest extends
gls.CompilableTestSupport {
}
// GROOVY-6431
+ @Test
void testBigDecAndBigIntSubClass() {
assertScript'''
class MyDecimal extends BigDecimal {
@@ -307,6 +322,7 @@ final class MethodSelectionTest extends
gls.CompilableTestSupport {
'''
}
+ @Test
void testVargsClass() {
assertScript '''
interface Parent {}
@@ -326,6 +342,7 @@ final class MethodSelectionTest extends
gls.CompilableTestSupport {
}
// GROOVY-5812
+ @Test
void testDirectMethodCall() {
assertScript '''
private String[] getStringArrayDirectly() { ["string_00",
"string_01"] }
@@ -343,6 +360,7 @@ final class MethodSelectionTest extends
gls.CompilableTestSupport {
}
// GROOVY-6189, GROOVY-9852
+ @Test
void testSAMs() {
// simple direct case
assertScript '''
diff --git a/src/test/groovy/gls/invocation/StaticMethodInvocationTest.groovy
b/src/test/groovy/gls/invocation/StaticMethodInvocationTest.groovy
index 3b7acbb3f1..7d6e3f50f6 100644
--- a/src/test/groovy/gls/invocation/StaticMethodInvocationTest.groovy
+++ b/src/test/groovy/gls/invocation/StaticMethodInvocationTest.groovy
@@ -19,37 +19,40 @@
package gls.invocation
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class StaticMethodInvocationTest extends CompilableTestSupport {
+final class StaticMethodInvocationTest extends CompilableTestSupport {
+ // GROOVY-2409
+ @Test
void testDifferentCalls() {
- // GROOVY-2409
assertScript """
-class Test {
- // all errors go away if method is declared non-private
- private static foo() {}
+class Test {
+ // all errors go away if method is declared non-private
+ private static foo() {}
- static callFooFromStaticMethod() {
- Test.foo()
- foo()
- this.foo()
- new Test().foo()
- }
+ static callFooFromStaticMethod() {
+ Test.foo()
+ foo()
+ this.foo()
+ new Test().foo()
+ }
- def callFooFromInstanceMethod() {
- Test.foo()
- foo()
- this.foo()
- new Test().foo()
- }
-}
+ def callFooFromInstanceMethod() {
+ Test.foo()
+ foo()
+ this.foo()
+ new Test().foo()
+ }
+}
-Test.callFooFromStaticMethod()
-new Test().callFooFromInstanceMethod()
+Test.callFooFromStaticMethod()
+new Test().callFooFromInstanceMethod()
"""
}
- //GROOVY-6662
+ // GROOVY-6662
+ @Test
void testStaticMethodNotWronglyCached() {
assertScript '''
class A { static bar() {1} }
@@ -61,7 +64,8 @@ new Test().callFooFromInstanceMethod()
'''
}
- //GROOVY-6883
+ // GROOVY-6883
+ @Test
void testStaticMethodCallFromOpenBlock() {
assertScript '''
class SuperClass {
diff --git a/src/test/groovy/gls/property/MetaClassOverridingTest.groovy
b/src/test/groovy/gls/property/MetaClassOverridingTest.groovy
index 27566cfb3c..44f610b91c 100644
--- a/src/test/groovy/gls/property/MetaClassOverridingTest.groovy
+++ b/src/test/groovy/gls/property/MetaClassOverridingTest.groovy
@@ -19,9 +19,11 @@
package gls.property
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class MetaClassOverridingTest extends CompilableTestSupport {
+final class MetaClassOverridingTest extends CompilableTestSupport {
+ @Test
void testOverridingMetaClassProperty() {
shouldCompile """
class A {
@@ -52,7 +54,6 @@ class MetaClassOverridingTest extends CompilableTestSupport {
class A {
private MetaClass metaClass
}
- """
+ """
}
-
-}
\ No newline at end of file
+}
diff --git a/src/test/groovy/gls/scope/BlockScopeVisibilityTest.groovy
b/src/test/groovy/gls/scope/BlockScopeVisibilityTest.groovy
index c70cc1fde0..5b514f755e 100644
--- a/src/test/groovy/gls/scope/BlockScopeVisibilityTest.groovy
+++ b/src/test/groovy/gls/scope/BlockScopeVisibilityTest.groovy
@@ -19,9 +19,13 @@
package gls.scope
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class BlockScopeVisibilityTest extends CompilableTestSupport {
+import static groovy.test.GroovyAssert.shouldFail
+final class BlockScopeVisibilityTest extends CompilableTestSupport {
+
+ @Test
void testForLoopVariableNotVisibleOutside() {
assertScript """
i=1
@@ -30,6 +34,7 @@ class BlockScopeVisibilityTest extends CompilableTestSupport {
"""
}
+ @Test
void testCatchParameterNotVisibleInOtherCatch() {
shouldFail(MissingPropertyException) {
try {
@@ -43,18 +48,19 @@ class BlockScopeVisibilityTest extends
CompilableTestSupport {
}
}
+ @Test
void testInnerClosureCanAccessImplicitItOfOuterClosure() {
- def c = { {-> it}}
+ def c = { {->it} }
assert c(1)() == 1
}
+ @Test
void testForLoopStatement() {
// this example requires not to put the declaration
// into a block !
if (false)
int number = 1
- shouldFail{ number }
+ shouldFail { number }
}
-
}
diff --git a/src/test/groovy/gls/scope/ClassVariableHidingTest.groovy
b/src/test/groovy/gls/scope/ClassVariableHidingTest.groovy
index 3e6789fa19..e87d38a81b 100644
--- a/src/test/groovy/gls/scope/ClassVariableHidingTest.groovy
+++ b/src/test/groovy/gls/scope/ClassVariableHidingTest.groovy
@@ -18,22 +18,24 @@
*/
package gls.scope;
-import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class ClassVariableHidingTest extends CompilableTestSupport {
+final class ClassVariableHidingTest {
def foo = 1;
def bar = 2;
+ @Test
void testFooHiding() {
assert foo == 1
def foo = 5
assert foo == 5
}
+ @Test
void testBarHiding() {
assert bar == 2
def bar = 5
assert bar == 5
}
-}
\ No newline at end of file
+}
diff --git a/src/test/groovy/gls/scope/FinalAccessTest.groovy
b/src/test/groovy/gls/scope/FinalAccessTest.groovy
index 7886990f1e..a56d72ae76 100644
--- a/src/test/groovy/gls/scope/FinalAccessTest.groovy
+++ b/src/test/groovy/gls/scope/FinalAccessTest.groovy
@@ -19,9 +19,11 @@
package gls.scope
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class FinalAccessTest extends CompilableTestSupport {
+final class FinalAccessTest extends CompilableTestSupport {
+ @Test
void testFinalField() {
shouldNotCompile """
class Person {
@@ -33,6 +35,7 @@ class FinalAccessTest extends CompilableTestSupport {
"""
}
+ @Test
void testStaticFinalField1() {
shouldCompile """
class G3911C1 {
@@ -48,6 +51,7 @@ class FinalAccessTest extends CompilableTestSupport {
"""
}
+ @Test
void testStaticFinalField2() {
shouldNotCompile """
class G3911C2 {
@@ -62,4 +66,4 @@ class FinalAccessTest extends CompilableTestSupport {
}
"""
}
-}
\ No newline at end of file
+}
diff --git
a/src/test/groovy/gls/scope/MultipleDefinitionOfSameVariableTest.groovy
b/src/test/groovy/gls/scope/MultipleDefinitionOfSameVariableTest.groovy
index f0ebb42204..fb99201ce0 100644
--- a/src/test/groovy/gls/scope/MultipleDefinitionOfSameVariableTest.groovy
+++ b/src/test/groovy/gls/scope/MultipleDefinitionOfSameVariableTest.groovy
@@ -19,9 +19,11 @@
package gls.scope
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class MultipleDefinitionOfSameVariableTest extends CompilableTestSupport {
+final class MultipleDefinitionOfSameVariableTest extends CompilableTestSupport
{
+ @Test
void testInSameBlock() {
shouldNotCompile '''
def foo = 1
@@ -38,6 +40,7 @@ class MultipleDefinitionOfSameVariableTest extends
CompilableTestSupport {
'''
}
+ @Test
void testInSubBlocks() {
shouldNotCompile '''
def foo = 1
@@ -60,6 +63,7 @@ class MultipleDefinitionOfSameVariableTest extends
CompilableTestSupport {
'''
}
+ @Test
void testInNestedClosure() {
shouldNotCompile '''
def foo = 1
@@ -73,6 +77,7 @@ class MultipleDefinitionOfSameVariableTest extends
CompilableTestSupport {
'''
}
+ @Test
void testBindingHiding() {
assertScript '''
foo = 1
@@ -83,6 +88,7 @@ class MultipleDefinitionOfSameVariableTest extends
CompilableTestSupport {
'''
}
+ @Test
void testBindingAccessInMethod() {
assertScript '''
def methodUsingBinding() {
@@ -98,6 +104,7 @@ class MultipleDefinitionOfSameVariableTest extends
CompilableTestSupport {
'''
}
+ @Test
void testMultipleOfSameName() {
shouldNotCompile '''
class DoubleField {
@@ -107,6 +114,7 @@ class MultipleDefinitionOfSameVariableTest extends
CompilableTestSupport {
'''
}
+ @Test
void testPropertyField() {
shouldCompile '''
class A {
@@ -116,6 +124,7 @@ class MultipleDefinitionOfSameVariableTest extends
CompilableTestSupport {
'''
}
+ @Test
void testPropertyFieldBothInit() {
shouldNotCompile '''
class A {
@@ -125,6 +134,7 @@ class MultipleDefinitionOfSameVariableTest extends
CompilableTestSupport {
'''
}
+ @Test
void testFieldProperty() {
shouldCompile '''
class A {
@@ -134,6 +144,7 @@ class MultipleDefinitionOfSameVariableTest extends
CompilableTestSupport {
'''
}
+ @Test
void testFieldPropertyBothInit() {
shouldNotCompile '''
class A {
@@ -143,6 +154,7 @@ class MultipleDefinitionOfSameVariableTest extends
CompilableTestSupport {
'''
}
+ @Test
void testFieldPropertyProperty() {
shouldNotCompile '''
class A {
@@ -153,6 +165,7 @@ class MultipleDefinitionOfSameVariableTest extends
CompilableTestSupport {
'''
}
+ @Test
void testPropertyFieldField() {
shouldNotCompile '''
class A {
@@ -163,6 +176,7 @@ class MultipleDefinitionOfSameVariableTest extends
CompilableTestSupport {
'''
}
+ @Test
void testFieldAndPropertyWithInit() {
assertScript '''
class X {
@@ -178,6 +192,7 @@ class MultipleDefinitionOfSameVariableTest extends
CompilableTestSupport {
'''
}
+ @Test
void testPropertyAndFieldWithInit() {
assertScript '''
class Y {
@@ -192,5 +207,4 @@ class MultipleDefinitionOfSameVariableTest extends
CompilableTestSupport {
assert result == [5, 6]
'''
}
-
-}
\ No newline at end of file
+}
diff --git a/src/test/groovy/gls/scope/NameResolvingTest.groovy
b/src/test/groovy/gls/scope/NameResolvingTest.groovy
index 6cf0206f15..0e5e8718a6 100644
--- a/src/test/groovy/gls/scope/NameResolvingTest.groovy
+++ b/src/test/groovy/gls/scope/NameResolvingTest.groovy
@@ -19,20 +19,25 @@
package gls.scope
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class NameResolvingTest extends CompilableTestSupport {
+final class NameResolvingTest extends CompilableTestSupport {
+
+ @Test
void testVariableNameEqualsToAClassName() {
Object String = ""
assert String == ""
assert String.class == java.lang.String
}
+ @Test
void testVariableNameEqualsCurrentClassName() {
Object NameResolvingTest = ""
assert NameResolvingTest == ""
assert NameResolvingTest.class == java.lang.String.class
}
+ @Test
void testClassNoVariableInStaticMethod() {
assertScript """
static def foo() {
@@ -42,6 +47,7 @@ class NameResolvingTest extends CompilableTestSupport {
"""
}
+ @Test
void testInAsDefAllowedInPackageNames() {
shouldCompile """
package as.in.def
@@ -49,12 +55,14 @@ class NameResolvingTest extends CompilableTestSupport {
"""
}
+ @Test
void testAssignmentToNonLocalVariableWithSameNameAsClass() {
shouldNotCompile """
String = 1
"""
}
+ @Test
void testClassUsageInSuper() {
shouldCompile """
class A {A(x){}}
@@ -64,6 +72,7 @@ class NameResolvingTest extends CompilableTestSupport {
"""
}
+ @Test
void testSuperClassVariableAccess() {
assertScript """
class U {
@@ -80,4 +89,4 @@ class NameResolvingTest extends CompilableTestSupport {
assert a.foo() == "AB\\n"
"""
}
-}
\ No newline at end of file
+}
diff --git a/src/test/groovy/gls/scope/StaticScopeTest.groovy
b/src/test/groovy/gls/scope/StaticScopeTest.groovy
index 016425de60..1c191ee177 100644
--- a/src/test/groovy/gls/scope/StaticScopeTest.groovy
+++ b/src/test/groovy/gls/scope/StaticScopeTest.groovy
@@ -19,9 +19,13 @@
package gls.scope
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class StaticScopeTest extends CompilableTestSupport {
+import static groovy.test.GroovyAssert.shouldFail
+final class StaticScopeTest extends CompilableTestSupport {
+
+ @Test
void testNormalStaticScopeInScript() {
shouldNotCompile """
static foo() {
@@ -36,6 +40,7 @@ class StaticScopeTest extends CompilableTestSupport {
"""
}
+ @Test
void testStaticImportInclass() {
assertScript """
import static java.lang.Math.*
@@ -45,6 +50,7 @@ class StaticScopeTest extends CompilableTestSupport {
"""
}
+ @Test
void testStaticMethodInConstructor() {
assertScript """
class B {
@@ -59,6 +65,7 @@ class StaticScopeTest extends CompilableTestSupport {
"""
}
+ @Test
void testStaticMethodInSpecialConstructorCall() {
assertScript """
class A {
@@ -84,6 +91,7 @@ class StaticScopeTest extends CompilableTestSupport {
"""
}
+ @Test
void testStaticImportProperty() {
assertScript """
import static A.*
@@ -94,6 +102,7 @@ class StaticScopeTest extends CompilableTestSupport {
"""
}
+ @Test
void testNormalStaticScopeInClass() {
assertScript """
class A {
@@ -116,6 +125,7 @@ class StaticScopeTest extends CompilableTestSupport {
"""
}
+ @Test
void testClosureInStaticScope() {
shouldCompile """
5.times { foo=2 }
@@ -126,6 +136,7 @@ class StaticScopeTest extends CompilableTestSupport {
"""
}
+ @Test
void testScriptMethodCall() {
assertScript """
import static java.util.Calendar.getInstance as now
@@ -145,6 +156,7 @@ class StaticScopeTest extends CompilableTestSupport {
"""
}
+ @Test
void testFullyQualifiedClassName() {
assertScript """
static foo() {java.lang.Integer}
@@ -160,6 +172,7 @@ class StaticScopeTest extends CompilableTestSupport {
"""
}
+ @Test
void testStaticPropertyInit() {
// GROOVY-1910
assertScript """
@@ -182,6 +195,7 @@ class StaticScopeTest extends CompilableTestSupport {
"""
}
+ @Test
void testSpecialConstructorAccess() {
shouldCompile """
class A{ A(x){} }
@@ -221,16 +235,18 @@ class StaticScopeTest extends CompilableTestSupport {
"""
}
+ @Test
void testStaticMethodAccessingDynamicField() {
shouldFail MissingMethodException, """
class A {
def x = { }
static foo() { x() }
- }
+ }
A.foo()
"""
}
+ @Test
void testStaticThisWithClass() {
assertScript """
static foo(){this}
@@ -244,6 +260,7 @@ class StaticScopeTest extends CompilableTestSupport {
"""
}
+ @Test
void testConstructorParameterDefault() {
shouldNotCompile """
class Child {
diff --git a/src/test/groovy/gls/sizelimits/StringSizeTest.groovy
b/src/test/groovy/gls/sizelimits/StringSizeTest.groovy
index 307976d93a..1764e0c508 100644
--- a/src/test/groovy/gls/sizelimits/StringSizeTest.groovy
+++ b/src/test/groovy/gls/sizelimits/StringSizeTest.groovy
@@ -18,8 +18,12 @@
*/
package gls.sizelimits
-class StringSizeTest extends gls.CompilableTestSupport {
+import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
+final class StringSizeTest extends CompilableTestSupport {
+
+ @Test
void testNormalString() {
def string = "x"*65535
@@ -32,8 +36,9 @@ class StringSizeTest extends gls.CompilableTestSupport {
"""
}
+ @Test
void testGString() {
- def string = "x"*65534
+ def string = "x"*65534
// not 65535, because we use one additional space
// in the gstring test script
@@ -46,4 +51,4 @@ class StringSizeTest extends gls.CompilableTestSupport {
def test = "\$x $string"
"""
}
-}
\ No newline at end of file
+}
diff --git a/src/test/groovy/gls/statements/DeclarationTest.groovy
b/src/test/groovy/gls/statements/DeclarationTest.groovy
index db7974e83f..b4d39138d9 100644
--- a/src/test/groovy/gls/statements/DeclarationTest.groovy
+++ b/src/test/groovy/gls/statements/DeclarationTest.groovy
@@ -20,10 +20,13 @@ package gls.statements
import gls.CompilableTestSupport
import org.codehaus.groovy.runtime.typehandling.GroovyCastException
+import org.junit.jupiter.api.Test
-class DeclarationTest extends CompilableTestSupport {
+import static groovy.test.GroovyAssert.shouldFail
+final class DeclarationTest extends CompilableTestSupport {
+ @Test
void testSingleDeclarationInParenthesis() {
shouldNotCompile """
(def a=1).method()
@@ -33,19 +36,21 @@ class DeclarationTest extends CompilableTestSupport {
"""
}
+ @Test
void testNullAssignmentToPrimitive() {
- shouldFail(GroovyCastException, """
+ shouldFail GroovyCastException, """
int x = null
- """)
+ """
assertScript """
Integer x = null
"""
}
+ @Test
void testNullAssignmentToPrimitiveForSharedVariable() {
- shouldFail(GroovyCastException, """
+ shouldFail GroovyCastException, """
int i = null
def c = {i}
- """)
+ """
}
-}
\ No newline at end of file
+}
diff --git a/src/test/groovy/gls/statements/ReturnTest.groovy
b/src/test/groovy/gls/statements/ReturnTest.groovy
index 66effd7b76..1770f550b8 100644
--- a/src/test/groovy/gls/statements/ReturnTest.groovy
+++ b/src/test/groovy/gls/statements/ReturnTest.groovy
@@ -19,17 +19,20 @@
package gls.statements
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class ReturnTest extends CompilableTestSupport {
+final class ReturnTest extends CompilableTestSupport {
+ @Test
void testObjectInitializer() {
shouldNotCompile """
class A {
{return}
- }
+ }
"""
}
+ @Test
void testStaticInitializer() {
assertScript """
class A {
@@ -37,9 +40,10 @@ class ReturnTest extends CompilableTestSupport {
static { return; foo=1 }
}
assert A.foo==2
- """
+ """
}
+ @Test
void testReturnAdditionInFinally() {
//GROOVY-7065
assertScript """
@@ -59,4 +63,4 @@ class ReturnTest extends CompilableTestSupport {
assert finalCountDown().counter == 9
"""
}
-}
\ No newline at end of file
+}
diff --git a/src/test/groovy/gls/syntax/AssertTest.groovy
b/src/test/groovy/gls/syntax/AssertTest.groovy
index 8b9e6ded80..d2a3531ecb 100644
--- a/src/test/groovy/gls/syntax/AssertTest.groovy
+++ b/src/test/groovy/gls/syntax/AssertTest.groovy
@@ -18,13 +18,17 @@
*/
package gls.syntax
-class AssertTest extends gls.CompilableTestSupport {
+import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
- void testAssignment() {
- // don't allow "=" here, it most certainly must be a "=="
- shouldNotCompile """
- def a = 1
- assert a = 2
- """
- }
-}
\ No newline at end of file
+final class AssertTest extends CompilableTestSupport {
+
+ @Test
+ void testAssignment() {
+ // don't allow "=" here, it most certainly must be a "=="
+ shouldNotCompile '''
+ def a = 1
+ assert a = 2
+ '''
+ }
+}
diff --git a/src/test/groovy/gls/syntax/BinaryLiteralTest.groovy
b/src/test/groovy/gls/syntax/BinaryLiteralTest.groovy
index 8cdea3490a..3eb6ae00fd 100644
--- a/src/test/groovy/gls/syntax/BinaryLiteralTest.groovy
+++ b/src/test/groovy/gls/syntax/BinaryLiteralTest.groovy
@@ -19,9 +19,11 @@
package gls.syntax
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class BinaryLiteralTest extends CompilableTestSupport {
+final class BinaryLiteralTest extends CompilableTestSupport {
+ @Test
void testSomeBinaryLiteralNumbers() {
assertScript '''
assert 0b0 == 0
@@ -41,8 +43,6 @@ class BinaryLiteralTest extends CompilableTestSupport {
int anInt = (int)0b1010000101000101
assert anInt == 41285
-
'''
}
-
}
diff --git a/src/test/groovy/gls/syntax/MethodCallValidationTest.groovy
b/src/test/groovy/gls/syntax/MethodCallValidationTest.groovy
index cd46978926..942610bff4 100644
--- a/src/test/groovy/gls/syntax/MethodCallValidationTest.groovy
+++ b/src/test/groovy/gls/syntax/MethodCallValidationTest.groovy
@@ -18,14 +18,18 @@
*/
package gls.syntax
-class MethodCallValidationTest extends gls.CompilableTestSupport {
+import org.junit.jupiter.api.Test
+final class MethodCallValidationTest extends gls.CompilableTestSupport {
+
+ @Test
void testDeclarationInMethodCall() {
shouldNotCompile """
foo(String a)
"""
}
+ @Test
void testDuplicateNamedParameters() {
shouldNotCompile """
def closure = { println it }
@@ -44,4 +48,4 @@ class MethodCallValidationTest extends
gls.CompilableTestSupport {
method debit: 30, credit: 40, debit: 50
"""
}
-}
\ No newline at end of file
+}
diff --git a/src/test/groovy/gls/syntax/NumberLiteralTest.groovy
b/src/test/groovy/gls/syntax/NumberLiteralTest.groovy
index 71591d8084..de53321085 100644
--- a/src/test/groovy/gls/syntax/NumberLiteralTest.groovy
+++ b/src/test/groovy/gls/syntax/NumberLiteralTest.groovy
@@ -19,9 +19,11 @@
package gls.syntax
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class NumberLiteralTest extends CompilableTestSupport {
+final class NumberLiteralTest extends CompilableTestSupport {
+ @Test
void testLargeNumbersOverflowing() {
shouldCompile '''
int a = 0x80000000
@@ -34,6 +36,7 @@ class NumberLiteralTest extends CompilableTestSupport {
'''
}
+ @Test
void testValidIntegerLiterals() {
shouldCompile '''
def a = 2147483647I
@@ -42,6 +45,7 @@ class NumberLiteralTest extends CompilableTestSupport {
'''
}
+ @Test
void testValidLongLiterals() {
shouldCompile '''
def d = 9223372036854775807L
@@ -50,16 +54,17 @@ class NumberLiteralTest extends CompilableTestSupport {
'''
}
+ @Test
void testInvalidIntegerLiteral() {
shouldNotCompile '''
def n = 2147483648I
'''
}
+ @Test
void testInvalidLongLiteral() {
shouldNotCompile '''
def n = 9223372036854775808L
'''
}
-
-}
\ No newline at end of file
+}
diff --git a/src/test/groovy/gls/syntax/OldClosureSyntaxRemovalTest.groovy
b/src/test/groovy/gls/syntax/OldClosureSyntaxRemovalTest.groovy
index 8d9ac26463..65b3b29e52 100644
--- a/src/test/groovy/gls/syntax/OldClosureSyntaxRemovalTest.groovy
+++ b/src/test/groovy/gls/syntax/OldClosureSyntaxRemovalTest.groovy
@@ -19,11 +19,14 @@
package gls.syntax
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
+
+final class OldClosureSyntaxRemovalTest extends CompilableTestSupport {
-class OldClosureSyntaxRemovalTest extends CompilableTestSupport {
def a = 2
def b = 3
+ @Test
void testOneParameter() {
def newClosure = { a -> a }
def oldClosure = { a | b }
@@ -34,6 +37,7 @@ class OldClosureSyntaxRemovalTest extends
CompilableTestSupport {
assert oldClosure(1) == (a | b)
}
+ @Test
void testMultipleParameters() {
shouldNotCompile """
c = {a,b|a+b}
diff --git a/src/test/groovy/gls/syntax/OldPropertySyntaxRemovalTest.groovy
b/src/test/groovy/gls/syntax/OldPropertySyntaxRemovalTest.groovy
index 2558f06fdb..75afbc5bd5 100644
--- a/src/test/groovy/gls/syntax/OldPropertySyntaxRemovalTest.groovy
+++ b/src/test/groovy/gls/syntax/OldPropertySyntaxRemovalTest.groovy
@@ -19,9 +19,11 @@
package gls.syntax
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class OldPropertySyntaxRemovalTest extends CompilableTestSupport {
+final class OldPropertySyntaxRemovalTest extends CompilableTestSupport {
+ @Test
void testMultipleParameters() {
shouldNotCompile """
class C {
@@ -29,4 +31,4 @@ class OldPropertySyntaxRemovalTest extends
CompilableTestSupport {
}
"""
}
-}
\ No newline at end of file
+}
diff --git a/src/test/groovy/gls/syntax/OldSpreadTest.groovy
b/src/test/groovy/gls/syntax/OldSpreadTest.groovy
index 8cf5d1310c..08209035dc 100644
--- a/src/test/groovy/gls/syntax/OldSpreadTest.groovy
+++ b/src/test/groovy/gls/syntax/OldSpreadTest.groovy
@@ -19,13 +19,15 @@
package gls.syntax
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class OldSpreadTest extends CompilableTestSupport {
+final class OldSpreadTest extends CompilableTestSupport {
+ @Test
void testSpreadStatement() {
// don't allow spread outside a method call
shouldNotCompile """
- *x
+ *x
"""
}
-}
\ No newline at end of file
+}
diff --git a/src/test/groovy/gls/syntax/ParsingTest.groovy
b/src/test/groovy/gls/syntax/ParsingTest.groovy
index 6b4f617d0d..7d04bdd36b 100644
--- a/src/test/groovy/gls/syntax/ParsingTest.groovy
+++ b/src/test/groovy/gls/syntax/ParsingTest.groovy
@@ -19,8 +19,12 @@
package gls.syntax
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class ParsingTest extends CompilableTestSupport {
+final class ParsingTest extends CompilableTestSupport {
+
+ // GROOVY-2605
+ @Test
void testExpressionParsingWithCastingInFrontOfAClosure() {
int[] numbers = new int[3]
@@ -55,6 +59,7 @@ class ParsingTest extends CompilableTestSupport {
assert val4.class.componentType == short
}
+ @Test
void testCastPrecedence_Groovy4421_Groovy5185() {
def i = (int)1/(int)2
assert i.class==BigDecimal
@@ -71,6 +76,7 @@ class ParsingTest extends CompilableTestSupport {
assert 4294967294L == (long)someInt + someInt
}
+ @Test
void testExpressionParsingWithCastInFrontOfAMap() {
shouldCompile """
def m = (Map)[a:{ "foo"; println 'bar' }]
diff --git a/src/test/groovy/gls/syntax/UnderscoreInNumbersTest.groovy
b/src/test/groovy/gls/syntax/UnderscoreInNumbersTest.groovy
index cd1f3734a9..38d440409c 100644
--- a/src/test/groovy/gls/syntax/UnderscoreInNumbersTest.groovy
+++ b/src/test/groovy/gls/syntax/UnderscoreInNumbersTest.groovy
@@ -19,13 +19,15 @@
package gls.syntax
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
/**
* Most of the below examples were taken from the Project Coin proposal here:
* http://mail.openjdk.java.net/pipermail/coin-dev/2009-April/001628.html
*/
-class UnderscoreInNumbersTest extends CompilableTestSupport {
+final class UnderscoreInNumbersTest extends CompilableTestSupport {
+ @Test
void testUnderscore() {
assertScript '''
assert 1_2_3_4_5 == 12345
@@ -35,6 +37,7 @@ class UnderscoreInNumbersTest extends CompilableTestSupport {
/**
* http://mail.openjdk.java.net/pipermail/coin-dev/2009-April/001628.html
*/
+ @Test
void testExamplesShouldCompileFromProposal() {
shouldCompile '''
long creditCardNumber = 1234_5678_9012_3456L
@@ -55,6 +58,7 @@ class UnderscoreInNumbersTest extends CompilableTestSupport {
/**
* http://mail.openjdk.java.net/pipermail/coin-dev/2009-April/001628.html
*/
+ @Test
void testExampleFromProposalWithBinaryLiterals() {
shouldCompile '''
byte nybbles = 0b0010_0101
@@ -67,6 +71,7 @@ class UnderscoreInNumbersTest extends CompilableTestSupport {
* Underscore must be placed between digits
* http://mail.openjdk.java.net/pipermail/coin-dev/2009-April/001628.html
*/
+ @Test
void testPositionOfUnderscoresAndWhatsValidOrInvalid() {
shouldCompile '''
int x1 = _52; // This is an identifier, not a numeric literal.
@@ -92,6 +97,7 @@ class UnderscoreInNumbersTest extends CompilableTestSupport {
'''
}
+ @Test
void testInvalidPlacementOfUnderscore() {
shouldNotCompile ''' def i = 10101_ '''
shouldNotCompile ''' def d = 10101_.0 '''
diff --git a/src/test/groovy/gls/types/BooleanExpressionConversionTest.groovy
b/src/test/groovy/gls/types/BooleanExpressionConversionTest.groovy
index f6698625f4..e4cc7b76d8 100644
--- a/src/test/groovy/gls/types/BooleanExpressionConversionTest.groovy
+++ b/src/test/groovy/gls/types/BooleanExpressionConversionTest.groovy
@@ -19,8 +19,11 @@
package gls.types
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class BooleanExpressionConversionTest extends CompilableTestSupport {
+final class BooleanExpressionConversionTest extends CompilableTestSupport {
+
+ @Test
void testInt() {
assertScript """
boolean foo(int i){
@@ -33,6 +36,7 @@ class BooleanExpressionConversionTest extends
CompilableTestSupport {
"""
}
+ @Test
void testLong() {
assertScript """
boolean foo(long i){
@@ -45,6 +49,7 @@ class BooleanExpressionConversionTest extends
CompilableTestSupport {
"""
}
+ @Test
void testFloat() {
assertScript """
boolean foo(float i){
@@ -57,6 +62,7 @@ class BooleanExpressionConversionTest extends
CompilableTestSupport {
"""
}
+ @Test
void testDouble() {
assertScript """
boolean foo(double i){
@@ -69,6 +75,7 @@ class BooleanExpressionConversionTest extends
CompilableTestSupport {
"""
}
+ @Test
void testChar() {
assertScript """
boolean foo(char i){
@@ -81,6 +88,7 @@ class BooleanExpressionConversionTest extends
CompilableTestSupport {
"""
}
+ @Test
void testByte() {
assertScript """
boolean foo(byte i){
@@ -93,6 +101,7 @@ class BooleanExpressionConversionTest extends
CompilableTestSupport {
"""
}
+ @Test
void testShort() {
assertScript """
boolean foo(short i){
@@ -104,5 +113,4 @@ class BooleanExpressionConversionTest extends
CompilableTestSupport {
assert foo((short)256)
"""
}
-
-}
\ No newline at end of file
+}
diff --git a/src/test/groovy/gls/types/GroovyCastTest.groovy
b/src/test/groovy/gls/types/GroovyCastTest.groovy
index c1b76affc1..595573c6e2 100644
--- a/src/test/groovy/gls/types/GroovyCastTest.groovy
+++ b/src/test/groovy/gls/types/GroovyCastTest.groovy
@@ -19,8 +19,11 @@
package gls.types
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class GroovyCastTest extends CompilableTestSupport {
+final class GroovyCastTest extends CompilableTestSupport {
+
+ @Test
void testSAMVariable() {
assertScript """
interface SAM { def foo(); }
@@ -32,6 +35,7 @@ class GroovyCastTest extends CompilableTestSupport {
"""
}
+ @Test
void testSAMProperty() {
assertScript """
interface SAM { def foo(); }
@@ -43,6 +47,7 @@ class GroovyCastTest extends CompilableTestSupport {
"""
}
+ @Test
void testSAMAttribute() {
assertScript """
interface SAM { def foo(); }
@@ -58,6 +63,7 @@ class GroovyCastTest extends CompilableTestSupport {
"""
}
+ @Test
void testSAMType() {
assertScript """
interface Foo {int foo()}
@@ -104,6 +110,7 @@ class GroovyCastTest extends CompilableTestSupport {
"""
}
+ @Test
void testClosureShouldNotBeCoercedToRunnable() {
assertScript '''
Class foo(Runnable r) {
@@ -119,4 +126,4 @@ Class bar(Runnable r) {
assert Closure.isAssignableFrom(foo { 'Hello' })
'''
}
-}
\ No newline at end of file
+}
diff --git a/src/test/groovy/gls/types/OperationsResultTypeTest.groovy
b/src/test/groovy/gls/types/OperationsResultTypeTest.groovy
index 65a7ea4630..845c9fca5b 100644
--- a/src/test/groovy/gls/types/OperationsResultTypeTest.groovy
+++ b/src/test/groovy/gls/types/OperationsResultTypeTest.groovy
@@ -19,9 +19,11 @@
package gls.types
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class OperationsResultTypeTest extends CompilableTestSupport {
+final class OperationsResultTypeTest extends CompilableTestSupport {
+ @Test
void testDeclaredTypeIsKept() {
assertScript """
def list = [10,20,30]
@@ -35,6 +37,7 @@ class OperationsResultTypeTest extends CompilableTestSupport {
"""
}
+ @Test
void testDeclaredTypeIsKeptForSharedVariable() {
assertScript '''
float myFloat = 40f
diff --git a/src/test/groovy/groovy/AbstractClassAndInterfaceTest.groovy
b/src/test/groovy/groovy/AbstractClassAndInterfaceTest.groovy
index 21b15a75e4..a63bc06ed8 100644
--- a/src/test/groovy/groovy/AbstractClassAndInterfaceTest.groovy
+++ b/src/test/groovy/groovy/AbstractClassAndInterfaceTest.groovy
@@ -19,11 +19,12 @@
package groovy
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
final class AbstractClassAndInterfaceTest extends CompilableTestSupport {
+ @Test
void testInterface() {
- def shell = new GroovyShell()
def text = '''
interface A {
void methodOne(Object o)
@@ -42,10 +43,11 @@ final class AbstractClassAndInterfaceTest extends
CompilableTestSupport {
def b = new B()
return b.methodTwo()
'''
- def retVal = shell.evaluate(text)
+ def retVal = assertScript(text)
assert retVal.class == Object
}
+ @Test
void testClassImplementingAnInterfaceButMissesMethod() {
shouldNotCompile '''
interface A {
@@ -78,6 +80,7 @@ final class AbstractClassAndInterfaceTest extends
CompilableTestSupport {
'''
}
+ @Test
void
testClassImplementingNestedInterfaceShouldContainMethodsFromSuperInterfaces() {
shouldNotCompile '''
interface A { def a() }
@@ -89,8 +92,8 @@ final class AbstractClassAndInterfaceTest extends
CompilableTestSupport {
'''
}
+ @Test
void testAbstractClass() {
- def shell = new GroovyShell()
def text = '''
abstract class A {
abstract void methodOne(Object o)
@@ -108,10 +111,11 @@ final class AbstractClassAndInterfaceTest extends
CompilableTestSupport {
def b = new B()
return b.methodTwo()
'''
- def retVal = shell.evaluate(text)
+ def retVal = assertScript(text)
assert retVal.class == Object
}
+ @Test
void testClassExtendingAnAbstractClassButMissesMethod() {
shouldNotCompile '''
abstract class A {
@@ -154,9 +158,9 @@ final class AbstractClassAndInterfaceTest extends
CompilableTestSupport {
'''
}
+ @Test
void testInterfaceAbstractClassCombination() {
- def shell = new GroovyShell()
- def text = '''
+ assertScript '''
interface A {
void methodOne()
}
@@ -174,7 +178,6 @@ final class AbstractClassAndInterfaceTest extends
CompilableTestSupport {
def c = new C()
c.methodTwo()
'''
- shell.evaluate(text)
shouldNotCompile '''
interface A {
@@ -191,9 +194,9 @@ final class AbstractClassAndInterfaceTest extends
CompilableTestSupport {
'''
}
+ @Test
void testDefaultModifiersForInterfaces() {
- def shell = new GroovyShell()
- def text = '''
+ assertScript '''
import java.lang.reflect.Modifier
interface A {
@@ -207,12 +210,11 @@ final class AbstractClassAndInterfaceTest extends
CompilableTestSupport {
assert Modifier.isStatic (fields[0].modifiers)
assert Modifier.isFinal (fields[0].modifiers)
'''
- shell.evaluate(text)
}
+ @Test
void testAccessToInterfaceField() {
- def shell = new GroovyShell()
- def text = '''
+ assertScript '''
interface A {
def foo=1
}
@@ -221,9 +223,9 @@ final class AbstractClassAndInterfaceTest extends
CompilableTestSupport {
}
assert new B().foo()==1
'''
- shell.evaluate(text)
}
+ @Test
void testImplementsDuplicateInterface() {
shouldCompile '''
interface I {}
@@ -235,6 +237,7 @@ final class AbstractClassAndInterfaceTest extends
CompilableTestSupport {
'''
}
+ @Test
void testDefaultMethodParamsNotAllowedInInterface() {
shouldCompile '''
interface Foo {
@@ -248,6 +251,7 @@ final class AbstractClassAndInterfaceTest extends
CompilableTestSupport {
'''
}
+ @Test
void testClassImplementsItselfCreatingACycle() {
shouldNotCompile '''
package p1
@@ -258,6 +262,7 @@ final class AbstractClassAndInterfaceTest extends
CompilableTestSupport {
'''
}
+ @Test
void testAbstractClassWithPrivateAbstractMethod() {
def msg = shouldNotCompile '''
abstract class X {
@@ -267,6 +272,7 @@ final class AbstractClassAndInterfaceTest extends
CompilableTestSupport {
assert msg.contains("The method 'y' must not be private as it is
declared abstract in class 'X'")
}
+ @Test
void testAbstractClassWithPrivateAbstractMethods() {
def msg = shouldNotCompile '''
abstract class X {
@@ -278,6 +284,7 @@ final class AbstractClassAndInterfaceTest extends
CompilableTestSupport {
assert msg.contains("The method 'z' must not be private as it is
declared abstract in class 'X'")
}
+ @Test
void testAbstractNestedClassWithPrivateAbstractMethod() {
def msg = shouldNotCompile '''
class Z {
@@ -289,6 +296,7 @@ final class AbstractClassAndInterfaceTest extends
CompilableTestSupport {
assert msg.contains("The method 'y' must not be private as it is
declared abstract in class 'Z\$X'")
}
+ @Test
void testClassWithPrivateAbstractMethod() {
def msg = shouldNotCompile '''
class X {
@@ -299,6 +307,7 @@ final class AbstractClassAndInterfaceTest extends
CompilableTestSupport {
assert msg.contains("Can't have an abstract method in a non-abstract
class. The class 'X' must be declared abstract or the method 'void y()' must be
implemented.")
}
+ @Test
void testEnumWithPrivateAbstractMethod() {
def msg = shouldNotCompile '''
enum X {
@@ -312,6 +321,7 @@ final class AbstractClassAndInterfaceTest extends
CompilableTestSupport {
assert msg.contains("The method 'y' must not be private as it is
declared abstract in enum 'X'")
}
+ @Test
void testInterfaceWithPrivateAbstractMethod() {
def msg = shouldNotCompile '''
interface X {
diff --git a/src/test/groovy/groovy/MethodInBadPositionTest.groovy
b/src/test/groovy/groovy/MethodInBadPositionTest.groovy
index 453d75c423..17f799d375 100644
--- a/src/test/groovy/groovy/MethodInBadPositionTest.groovy
+++ b/src/test/groovy/groovy/MethodInBadPositionTest.groovy
@@ -19,27 +19,31 @@
package groovy
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class MethodInBadPositionTest extends CompilableTestSupport {
- /** GROOVY-4215 */
+final class MethodInBadPositionTest extends CompilableTestSupport {
+
+ // GROOVY-4215
+ @Test
void testMethodDefinitionInClosure() {
- def msg = shouldNotCompile('''
+ def msg = shouldNotCompile '''
{ ->
def say(String msg) {
println(msg)
}
}()
- ''')
+ '''
assert msg.contains('Method definition not expected here') ||
msg.contains("Unexpected input: '('")
}
- /** GROOVY-4215 */
+ // GROOVY-4215
+ @Test
void testXMethodDefinitionInSwitch() {
- def msg = shouldNotCompile('''
+ def msg = shouldNotCompile '''
switch(1) {
case 1: def say(){}
}
- ''')
+ '''
assert msg.contains('Method definition not expected here') ||
msg.contains("Unexpected input: '('") || msg.contains("Unexpected input:
'switch(1)")
}
-}
\ No newline at end of file
+}
diff --git a/src/test/groovy/groovy/ModifiersTest.groovy
b/src/test/groovy/groovy/ModifiersTest.groovy
index 0d82d4cca8..0714b168aa 100644
--- a/src/test/groovy/groovy/ModifiersTest.groovy
+++ b/src/test/groovy/groovy/ModifiersTest.groovy
@@ -19,17 +19,20 @@
package groovy
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class ModifiersTest extends CompilableTestSupport {
+final class ModifiersTest extends CompilableTestSupport {
- public void testInterface() {
+ @Test
+ void testInterface() {
// control
shouldCompile("interface X {}")
// erroneous
shouldNotCompile("synchronized interface X {}")
}
- public void testClass() {
+ @Test
+ void testClass() {
// control
shouldCompile("public class X {}")
shouldCompile """
@@ -43,28 +46,32 @@ class ModifiersTest extends CompilableTestSupport {
shouldNotCompile("private class X {}")
}
- public void testMethodsShouldOnlyHaveOneVisibility() {
+ @Test
+ void testMethodsShouldOnlyHaveOneVisibility() {
// control
shouldCompile("class X { private method() {} }")
// erroneous
shouldNotCompile("class X { private public method() {} }")
}
- public void testFinalMethodParametersShouldNotBeModified() {
+ @Test
+ void testFinalMethodParametersShouldNotBeModified() {
// control
shouldCompile("class X { private method(x) { x = 1 } }")
// erroneous
shouldNotCompile("class X { private method(final x) { x = 1 } }")
}
- public void testMethodsShouldNotBeVolatile() {
+ @Test
+ void testMethodsShouldNotBeVolatile() {
// control
shouldCompile("class X { def method() {} }")
// erroneous
shouldNotCompile("class X { volatile method() {} }")
}
- public void testInterfaceMethodsShouldNotBeSynchronizedNativeStrictfp() {
+ @Test
+ void testInterfaceMethodsShouldNotBeSynchronizedNativeStrictfp() {
// control
shouldCompile("interface X { def method() }")
// erroneous
@@ -73,14 +80,16 @@ class ModifiersTest extends CompilableTestSupport {
shouldNotCompile("interface X { strictfp method() }")
}
- public void testVariableInClass() {
+ @Test
+ void testVariableInClass() {
// control
shouldCompile("class X { protected name }")
// erroneous
shouldNotCompile("class X { protected private name }")
}
- public void testVariableInScript() {
+ @Test
+ void testVariableInScript() {
// control
shouldCompile("def name")
shouldCompile("String name")
@@ -98,7 +107,8 @@ class ModifiersTest extends CompilableTestSupport {
shouldNotCompile("private protected name")
}
- public void testInvalidModifiersOnConstructor() {
+ @Test
+ void testInvalidModifiersOnConstructor() {
// control
shouldCompile("class Foo { Foo() {}}")
// erroneous
@@ -107,5 +117,4 @@ class ModifiersTest extends CompilableTestSupport {
shouldNotCompile("class Foo { abstract Foo() {}}")
shouldNotCompile("class Foo { native Foo() {}}")
}
-
}
diff --git a/src/test/groovy/groovy/StaticThisTest.groovy
b/src/test/groovy/groovy/StaticThisTest.groovy
index 2ca9dbe50c..039553e051 100644
--- a/src/test/groovy/groovy/StaticThisTest.groovy
+++ b/src/test/groovy/groovy/StaticThisTest.groovy
@@ -19,9 +19,11 @@
package groovy
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class StaticThisTest extends CompilableTestSupport {
+final class StaticThisTest extends CompilableTestSupport {
+ @Test
void testThisFail() {
staticMethod()
}
@@ -36,6 +38,7 @@ class StaticThisTest extends CompilableTestSupport {
assert s.name.endsWith("CompilableTestSupport")
}
+ @Test
void testThisPropertyInStaticMethodShouldNotCompile() {
shouldNotCompile """
class A {
@@ -47,6 +50,7 @@ class StaticThisTest extends CompilableTestSupport {
"""
}
+ @Test
void testSuperPropertyInStaticMethodShouldNotCompile() {
try {
assertScript """
@@ -63,6 +67,7 @@ class StaticThisTest extends CompilableTestSupport {
}
}
+ @Test
void testQualifiedThisShouldBeNested() {
shouldNotCompile """
class A {
@@ -73,6 +78,7 @@ class StaticThisTest extends CompilableTestSupport {
"""
}
+ @Test
void testQualifiedSuperShouldBeNested() {
shouldNotCompile """
class A {
@@ -83,6 +89,7 @@ class StaticThisTest extends CompilableTestSupport {
"""
}
+ @Test
void testQualifiedThisShouldReferenceOuterClass() {
shouldNotCompile """
class A {
@@ -95,6 +102,7 @@ class StaticThisTest extends CompilableTestSupport {
"""
}
+ @Test
void testQualifiedSuperShouldReferenceOuterClass() {
shouldNotCompile """
class A {
@@ -107,6 +115,7 @@ class StaticThisTest extends CompilableTestSupport {
"""
}
+ @Test
void testQualifiedThisForNestedClassShouldNotBeStaticContext() {
shouldNotCompile """
class A {
@@ -119,6 +128,7 @@ class StaticThisTest extends CompilableTestSupport {
"""
}
+ @Test
void testQualifiedSuperForNestedClassShouldNotBeStaticContext() {
shouldNotCompile """
class A {
@@ -134,6 +144,7 @@ class StaticThisTest extends CompilableTestSupport {
/**
* GROOVY-7047: Static inner class crashes compiler when it references
parent's this
*/
+ @Test
void testParentThisShouldNotBeReferredInsideStaticClass() {
shouldNotCompile """
class Foo {
@@ -143,5 +154,4 @@ class StaticThisTest extends CompilableTestSupport {
}
"""
}
-
}
diff --git a/src/test/groovy/groovy/TryCatchTest.groovy
b/src/test/groovy/groovy/TryCatchTest.groovy
index e3bcd7f238..89fff440da 100644
--- a/src/test/groovy/groovy/TryCatchTest.groovy
+++ b/src/test/groovy/groovy/TryCatchTest.groovy
@@ -19,12 +19,15 @@
package groovy
import gls.CompilableTestSupport
+import org.junit.jupiter.api.BeforeEach
+import org.junit.jupiter.api.Test
-class TryCatchTest extends CompilableTestSupport {
+final class TryCatchTest extends CompilableTestSupport {
def exceptionCalled
def finallyCalled
+ @Test
void testTryCatch() {
try {
failingMethod()
@@ -40,6 +43,7 @@ class TryCatchTest extends CompilableTestSupport {
assert finallyCalled, "should have invoked the finally clause"
}
+ @Test
void testStandaloneTryBlockShouldNotCompile() {
shouldNotCompile """
try {
@@ -48,6 +52,7 @@ class TryCatchTest extends CompilableTestSupport {
"""
}
+ @Test
void testTryFinally() {
Boolean touched = false;
@@ -60,6 +65,7 @@ class TryCatchTest extends CompilableTestSupport {
assert touched, "finally not called with empty try"
}
+ @Test
void testWorkingMethod() {
try {
workingMethod()
@@ -96,11 +102,13 @@ class TryCatchTest extends CompilableTestSupport {
assert finallyCalled, "should have invoked the finally clause"
}
- protected void setUp() {
+ @BeforeEach
+ void setUp() {
exceptionCalled = false
finallyCalled = false
}
+ @Test
void testTryWithReturnWithPrimitiveTypes() {
assert intTry() == 1
assert longTry() == 2
@@ -153,6 +161,7 @@ class TryCatchTest extends CompilableTestSupport {
} finally {}
}
+ @Test
void testTryCatchWithUntyped() {
try {
throw new Exception();
@@ -163,6 +172,7 @@ class TryCatchTest extends CompilableTestSupport {
assert false
}
+ @Test
void testTryCatchInConstructor() {
// the super() call construction left an
// element on the stack, causing an inconsistent
diff --git a/src/test/groovy/groovy/transform/stc/Groovy7880Bug.groovy
b/src/test/groovy/groovy/transform/stc/Groovy7880Bug.groovy
index 033a55097b..711eddc7af 100644
--- a/src/test/groovy/groovy/transform/stc/Groovy7880Bug.groovy
+++ b/src/test/groovy/groovy/transform/stc/Groovy7880Bug.groovy
@@ -20,8 +20,11 @@
package groovy.transform.stc
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class Groovy7880Bug extends CompilableTestSupport {
+final class Groovy7880Bug extends CompilableTestSupport {
+
+ @Test
void testDiamondUseShouldNotCauseNPE() {
shouldCompile '''
@groovy.transform.CompileStatic
diff --git a/src/test/groovy/groovy/util/MiscScriptTest.groovy
b/src/test/groovy/groovy/util/MiscScriptTest.groovy
index f3b6ff9127..3a4e413378 100644
--- a/src/test/groovy/groovy/util/MiscScriptTest.groovy
+++ b/src/test/groovy/groovy/util/MiscScriptTest.groovy
@@ -19,17 +19,20 @@
package groovy.util
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
/**
* Miscellaneous tests for {@link groovy.lang.Script}.
*/
-public class MiscScriptTest extends CompilableTestSupport {
+final class MiscScriptTest extends CompilableTestSupport {
- public void testEmptyScript() throws Exception {
- assertScript("");
+ @Test
+ void testEmptyScript() {
+ assertScript("")
}
// GROOVY-6589
+ @Test
void testShouldFailCompilation() {
shouldNotCompile '''
def run() {}
diff --git
a/src/test/groovy/org/codehaus/groovy/transform/AutoFinalTransformBlackBoxTest.groovy
b/src/test/groovy/org/codehaus/groovy/transform/AutoFinalTransformBlackBoxTest.groovy
index 5eefbf68bb..0c1484a7c3 100644
---
a/src/test/groovy/org/codehaus/groovy/transform/AutoFinalTransformBlackBoxTest.groovy
+++
b/src/test/groovy/org/codehaus/groovy/transform/AutoFinalTransformBlackBoxTest.groovy
@@ -21,12 +21,10 @@ package org.codehaus.groovy.transform
import gls.CompilableTestSupport
import org.junit.jupiter.api.Test
-import java.util.Map.Entry
-
/**
* Tests for the {@code @AutoFinal} AST transform.
*/
-class AutoFinalTransformBlackBoxTest extends CompilableTestSupport {
+final class AutoFinalTransformBlackBoxTest extends CompilableTestSupport {
@Test
void testAutoFinal_Closure() {
@@ -113,13 +111,12 @@ class AutoFinalTransformBlackBoxTest extends
CompilableTestSupport {
shouldCompile(script)
}
-
String autoFinalTestScript(
final boolean hasAnnotation,
final Map<String, Object> annotationParameters,
final String classPart, final String scriptPart = '') {
assert !hasAnnotation || (annotationParameters != null); assert
classPart
- final String annotationParametersTerm = annotationParameters ?
"(${annotationParameters.collect { final Entry<String, Object> e ->
"$e.key=$e.value" }.join(', ')})" : ''
+ final String annotationParametersTerm = annotationParameters ?
"(${annotationParameters.collect { Map.Entry<String, Object> e ->
"$e.key=$e.value" }.join(', ')})" : ''
final String script = """
import groovy.transform.AutoFinal
import groovy.transform.ASTTest
@@ -153,15 +150,4 @@ class AutoFinalTransformBlackBoxTest extends
CompilableTestSupport {
printStackTrace(inner)
}
}
-
- Throwable shouldThrow(final String script) {
- try {
- final GroovyClassLoader gcl = new GroovyClassLoader()
- gcl.parseClass(script, getTestClassName())
- }
- catch (Throwable throwable) {
- return throwable
- }
- throw new Exception("Script was expected to throw here!")
- }
}
diff --git
a/src/test/groovy/org/codehaus/groovy/transform/SortableTransformTest.groovy
b/src/test/groovy/org/codehaus/groovy/transform/SortableTransformTest.groovy
index c16e5322f6..edf2f7f907 100644
--- a/src/test/groovy/org/codehaus/groovy/transform/SortableTransformTest.groovy
+++ b/src/test/groovy/org/codehaus/groovy/transform/SortableTransformTest.groovy
@@ -20,8 +20,11 @@ package org.codehaus.groovy.transform
import gls.CompilableTestSupport
import groovy.transform.Sortable
+import org.junit.jupiter.api.Test
-class SortableTransformTest extends CompilableTestSupport {
+final class SortableTransformTest extends CompilableTestSupport {
+
+ @Test
void testSortableWithCustomOrdering() {
assertScript '''
import groovy.transform.Sortable
@@ -40,6 +43,7 @@ class SortableTransformTest extends CompilableTestSupport {
'''
}
+ @Test
void testSortableWithCompileStatic() {
assertScript '''
import groovy.transform.*
@@ -63,6 +67,7 @@ class SortableTransformTest extends CompilableTestSupport {
'''
}
+ @Test
void testDuckTypingWithComparators() {
assertScript '''
import groovy.transform.*
@@ -95,6 +100,7 @@ class SortableTransformTest extends CompilableTestSupport {
'''
}
+ @Test
void testSortableWithSortableProperty() {
assertScript '''
import groovy.transform.*
@@ -117,6 +123,7 @@ class SortableTransformTest extends CompilableTestSupport {
'''
}
+ @Test
void testBadIncludesAndExcludes() {
def message = shouldFail '''
@groovy.transform.Sortable(includes='first', excludes='last')
class Person {
@@ -128,6 +135,7 @@ class SortableTransformTest extends CompilableTestSupport {
assert message.contains("Error during @Sortable processing: Only one
of 'includes' and 'excludes' should be supplied not both")
}
+ @Test
void testBadInclude() {
def message = shouldFail '''
@groovy.transform.Sortable(includes='first,middle') class Person {
@@ -139,6 +147,7 @@ class SortableTransformTest extends CompilableTestSupport {
assert message.contains("Error during @Sortable processing: 'includes'
property 'middle' does not exist.")
}
+ @Test
void testBadExclude() {
def message = shouldFail '''
@groovy.transform.Sortable(excludes='first,middle') class Person {
@@ -150,6 +159,7 @@ class SortableTransformTest extends CompilableTestSupport {
assert message.contains("Error during @Sortable processing: 'excludes'
property 'middle' does not exist.")
}
+ @Test
void testBadPropertyType() {
def message = shouldFail '''
@groovy.transform.Sortable class Person {
@@ -161,6 +171,7 @@ class SortableTransformTest extends CompilableTestSupport {
assert message.contains("Error during @Sortable processing: property
'appearances' must be Comparable")
}
+ @Test
void testBadInterfaceUsage() {
def message = shouldFail '''
@groovy.transform.Sortable interface Foo { }
@@ -168,6 +179,7 @@ class SortableTransformTest extends CompilableTestSupport {
assert message.contains("@Sortable cannot be applied to interface Foo")
}
+ @Test
void testReverseSorting() {
assertScript '''
import groovy.transform.*
diff --git
a/src/test/groovy/org/codehaus/groovy/transform/SourceURITransformTest.groovy
b/src/test/groovy/org/codehaus/groovy/transform/SourceURITransformTest.groovy
index 257943dae7..a669a87a2c 100644
---
a/src/test/groovy/org/codehaus/groovy/transform/SourceURITransformTest.groovy
+++
b/src/test/groovy/org/codehaus/groovy/transform/SourceURITransformTest.groovy
@@ -19,8 +19,11 @@
package org.codehaus.groovy.transform
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class SourceURITransformTest extends CompilableTestSupport {
+final class SourceURITransformTest extends CompilableTestSupport {
+
+ @Test
void testWorksInClass() {
def groovy = new GroovyClassLoader()
def compiledClass = groovy.parseClass '''class CompanionThingy {
@@ -40,6 +43,7 @@ class SourceURITransformTest extends CompilableTestSupport {
assert
compiledClass.newInstance().toString().matches(".*data:.*,class%20CompanionThingy%20%7B.*")
}
+ @Test
void testWorksInScript() {
assertScript '''// This is script for testWorksInScript
@groovy.transform.SourceURI def myURI
diff --git a/src/testFixtures/groovy/gls/CompilableTestSupport.groovy
b/src/testFixtures/groovy/gls/CompilableTestSupport.groovy
index 1c8a770b8a..0db79a01af 100644
--- a/src/testFixtures/groovy/gls/CompilableTestSupport.groovy
+++ b/src/testFixtures/groovy/gls/CompilableTestSupport.groovy
@@ -18,26 +18,55 @@
*/
package gls
-import groovy.test.GroovyTestCase
+import groovy.test.GroovyAssert
import groovy.transform.AutoFinal
import groovy.transform.CompileStatic
import org.codehaus.groovy.control.CompilationFailedException
+import org.junit.jupiter.api.BeforeEach
+import org.junit.jupiter.api.TestInfo
+
+import java.util.concurrent.atomic.AtomicInteger
+
+import static org.junit.jupiter.api.Assertions.fail
@AutoFinal @CompileStatic
-abstract class CompilableTestSupport extends GroovyTestCase {
+abstract class CompilableTestSupport {
+
+ String methodName
+
+ @BeforeEach
+ final void setUpTestCase(TestInfo testInfo) {
+ methodName = testInfo.getTestMethod().orElseThrow().getName()
+ }
- protected String shouldNotCompile(String script) {
+ private static final AtomicInteger scriptFileNameCounter = new
AtomicInteger(0)
+
+ private String getTestClassName() {
+
"TestScript${getMethodName()}${scriptFileNameCounter.getAndIncrement()}.groovy"
+ }
+
+
//--------------------------------------------------------------------------
+
+ protected final Object assertScript(String script) {
+ new GroovyShell().evaluate(script, testClassName)
+ }
+
+ protected final String shouldFail(String script) {
+ GroovyAssert.shouldFail(script).getMessage()
+ }
+
+ protected final void shouldCompile(String script) {
try (def gcl = new GroovyClassLoader()) {
gcl.parseClass(script, testClassName)
- } catch (CompilationFailedException ex) {
- return ex.message
}
- fail('the compilation succeeded but should have failed')
}
- protected void shouldCompile(final String script) {
+ protected final String shouldNotCompile(String script) {
try (def gcl = new GroovyClassLoader()) {
gcl.parseClass(script, testClassName)
+ } catch (CompilationFailedException ex) {
+ return ex.message
}
+ fail('the compilation succeeded but should have failed')
}
}
diff --git a/subprojects/groovy-jmx/src/spec/test/JmxTest.groovy
b/subprojects/groovy-jmx/src/spec/test/JmxTest.groovy
index d314722caf..390e75f332 100644
--- a/subprojects/groovy-jmx/src/spec/test/JmxTest.groovy
+++ b/subprojects/groovy-jmx/src/spec/test/JmxTest.groovy
@@ -17,9 +17,11 @@
* under the License.
*/
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class JmxTest extends CompilableTestSupport {
+final class JmxTest extends CompilableTestSupport {
+ @Test
void testIntroduction() {
shouldCompile '''
import groovy.jmx.GroovyMBean
@@ -46,6 +48,7 @@ class JmxTest extends CompilableTestSupport {
'''
}
+ @Test
void testTheJvm() {
shouldCompile '''
// tag::the_jvm[]
@@ -129,6 +132,7 @@ class JmxTest extends CompilableTestSupport {
'''
}
+ @Test
void testTomcat() {
shouldCompile '''
@Grab('org.jfree:jfreechart:1.5.0')
@@ -180,6 +184,7 @@ class JmxTest extends CompilableTestSupport {
'''
}
+ @Test
void testWebLogic() {
shouldCompile '''
// tag::weblogic[]
@@ -210,6 +215,7 @@ class JmxTest extends CompilableTestSupport {
'''
}
+ @Test
void testSpringClasses() {
shouldCompile '''
@Grab('org.springframework:spring-context:5.2.8.RELEASE')
@@ -261,6 +267,7 @@ class JmxTest extends CompilableTestSupport {
'''
}
+ @Test
void testSpringUsage() {
shouldCompile '''
@Grab('org.springframework:spring-context:5.2.8.RELEASE')
@@ -298,6 +305,7 @@ class JmxTest extends CompilableTestSupport {
'''
}
+ @Test
void testTroubleshooting() {
shouldCompile '''
import javax.management.remote.*
@@ -315,6 +323,7 @@ class JmxTest extends CompilableTestSupport {
'''
}
+ @Test
void testJmxBuilder() {
shouldCompile '''
@Grab('org.codehaus.groovy:groovy-jmx:2.1.6')
diff --git
a/subprojects/groovy-servlet/src/spec/test/servlet/GroovyServletTest.groovy
b/subprojects/groovy-servlet/src/spec/test/servlet/GroovyServletTest.groovy
index 01c56ec0db..764bc07284 100644
--- a/subprojects/groovy-servlet/src/spec/test/servlet/GroovyServletTest.groovy
+++ b/subprojects/groovy-servlet/src/spec/test/servlet/GroovyServletTest.groovy
@@ -19,9 +19,11 @@
package servlet
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class GroovyServletTest extends CompilableTestSupport {
+final class GroovyServletTest extends CompilableTestSupport {
+ @Test
void testExample() {
shouldCompile '''
// tag::example[]
@@ -50,6 +52,7 @@ class GroovyServletTest extends CompilableTestSupport {
'''
}
+ @Test
void testExampleMarkupBuilder() {
shouldCompile '''
// tag::example_markup_builder[]
diff --git a/subprojects/groovy-swing/src/spec/test/SwingBuilderTest.groovy
b/subprojects/groovy-swing/src/spec/test/SwingBuilderTest.groovy
index 17e74ce82f..9904afddad 100644
--- a/subprojects/groovy-swing/src/spec/test/SwingBuilderTest.groovy
+++ b/subprojects/groovy-swing/src/spec/test/SwingBuilderTest.groovy
@@ -17,9 +17,11 @@
* under the License.
*/
import gls.CompilableTestSupport
+import org.junit.jupiter.api.Test
-class DesignPatternsTest extends CompilableTestSupport {
+final class DesignPatternsTest extends CompilableTestSupport {
+ @Test
void testSimpleExample() {
shouldCompile '''
// tag::simple_example[]
@@ -39,6 +41,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testMoreInvolvedExample() {
shouldCompile '''
// tag::more_involved_example[]
@@ -76,6 +79,7 @@ class DesignPatternsTest extends CompilableTestSupport {
'''
}
+ @Test
void testObservableBindingExample() {
shouldCompile '''
// tag::observable_binding_example[]
diff --git
a/subprojects/groovy-templates/src/spec/test/TemplateEnginesTest.groovy
b/subprojects/groovy-templates/src/spec/test/TemplateEnginesTest.groovy
index 3999d8bce3..df91364ea1 100644
--- a/subprojects/groovy-templates/src/spec/test/TemplateEnginesTest.groovy
+++ b/subprojects/groovy-templates/src/spec/test/TemplateEnginesTest.groovy
@@ -20,9 +20,11 @@ import gls.CompilableTestSupport
import groovy.text.StreamingTemplateEngine
import groovy.text.Template
import groovy.text.TemplateEngine
+import org.junit.jupiter.api.Test
-class TemplateEnginesTest extends CompilableTestSupport {
+final class TemplateEnginesTest extends CompilableTestSupport {
+ @Test
void testSimpleTemplateEngine1() {
// tag::simple_template_engine1[]
def text = 'Dear "$firstname $lastname",\nSo nice to meet you in <%
print city %>.\nSee you in ${month},\n${signed}'
@@ -38,6 +40,7 @@ class TemplateEnginesTest extends CompilableTestSupport {
// end::simple_template_engine1[]
}
+ @Test
void testSimpleTemplateEngineOther() {
def binding = [firstname: 'andrey']
def engine = new groovy.text.SimpleTemplateEngine()
@@ -107,7 +110,8 @@ class TemplateEnginesTest extends CompilableTestSupport {
assert result.readLines()[1].trim() == '\\'
}
- void testStreamingTemplateEngine() {
+ @Test
+ void testStreamingTemplateEngine() {
// tag::streaming_template_engine[]
def text = '''\
Dear <% out.print firstname %> ${lastname},
@@ -138,6 +142,7 @@ The conference committee.'''
// end::streaming_template_engine[]
}
+ @Test
void testGStringTemplateEngine() {
def binding = [firstname: 'Sam', lastname: 'Pullara', city: 'New
York', month: 'December', signed: 'Groovy-Dev']
def engine = new groovy.text.GStringTemplateEngine()
@@ -169,6 +174,7 @@ The conference committee.'''
'''
}
+ @Test
void testXmlTemplateEngine() {
// tag::xml_template_engine[]
def binding = [firstname: 'Jochen', lastname: 'Theodorou', nickname:
'blackdrag', salutation: 'Dear']
@@ -196,6 +202,7 @@ The conference committee.'''
'''
}
+ @Test
void testStreamingTemplateEngine_GROOVY9507() {
TemplateEngine engine = new StreamingTemplateEngine()
Template template = engine.createTemplate('''