This is an automated email from the ASF dual-hosted git repository. paulk pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 5e263d87c0871143117c7d2ab8579d02456ae029 Author: Paul King <pa...@asert.com.au> AuthorDate: Wed Jan 2 08:35:36 2019 +1000 whitespace/formatting plus cleanup/remove @author tags as per Apache recommended practices cont'd --- gradle/pomconfigurer.gradle | 3 + .../groovy/groovy/transform/CompileDynamic.groovy | 3 +- .../groovy/transform/ConditionalInterrupt.groovy | 74 ++++--- .../groovy/groovy/transform/TailRecursive.groovy | 3 +- .../groovy/groovy/transform/ThreadInterrupt.groovy | 127 +++++------- .../groovy/groovy/transform/TimedInterrupt.groovy | 8 +- src/test/groovy/io/LineColumnReaderTest.groovy | 3 - .../groovy/lang/BenchmarkInterceptorTest.groovy | 29 +-- src/test/groovy/lang/ClosureResolvingTest.groovy | 3 +- .../groovy/lang/DelegatingMetaClassTest.groovy | 8 +- .../lang/ExpandoMetaClassCreationHandleTest.groovy | 41 ++-- src/test/groovy/lang/ExpandoMetaClassTest.groovy | 126 ++++++------ src/test/groovy/lang/GetMethodsTest.groovy | 13 +- src/test/groovy/lang/GroovyCodeSourceTest.groovy | 7 +- src/test/groovy/lang/GroovySystemTest.groovy | 10 +- src/test/groovy/lang/InterceptorTest.groovy | 4 +- src/test/groovy/lang/MapOfClosureTest.groovy | 229 +++++++++++---------- src/test/groovy/lang/MetaClassRegistryTest.groovy | 9 +- src/test/groovy/lang/PropertyMissingTest.groovy | 22 +- .../groovy/lang/ReferenceSerializationTest.groovy | 2 - src/test/groovy/lang/RespondsToTest.groovy | 12 +- .../lang/ScriptSourcePositionInAstTest.groovy | 4 +- src/test/groovy/mock/interceptor/Caller.groovy | 15 +- .../groovy/mock/interceptor/Collaborator.groovy | 11 +- .../mock/interceptor/MockSingleCallTest.groovy | 38 ++-- .../mock/interceptor/StubCallSequenceTest.groovy | 2 - .../mock/interceptor/StubSingleCallTest.groovy | 6 +- .../groovy/operator/BitwiseOperatorsTest.groovy | 32 ++- src/test/groovy/operator/NegateListsTest.groovy | 6 +- src/test/groovy/operator/PowerOperatorsTest.groovy | 21 +- .../groovy/operator/SpreadListOperatorTest.groovy | 8 +- .../groovy/operator/SpreadMapOperatorTest.groovy | 64 +++--- src/test/groovy/time/TimeCategoryTest.groovy | 10 +- src/test/groovy/transform/LazyTest.groovy | 18 +- .../groovy/transform/ThreadInterruptTest.groovy | 2 - 35 files changed, 444 insertions(+), 529 deletions(-) diff --git a/gradle/pomconfigurer.gradle b/gradle/pomconfigurer.gradle index 61aa7bb..e9bd98b 100644 --- a/gradle/pomconfigurer.gradle +++ b/gradle/pomconfigurer.gradle @@ -755,6 +755,9 @@ project.ext.pomConfigureClosureWithoutTweaks = { contributor { name 'Peter Gromov' } + contributor { + name 'Johannes Link' + } } mailingLists { mailingList { diff --git a/src/main/groovy/groovy/transform/CompileDynamic.groovy b/src/main/groovy/groovy/transform/CompileDynamic.groovy index c5247d4..11cd23b 100644 --- a/src/main/groovy/groovy/transform/CompileDynamic.groovy +++ b/src/main/groovy/groovy/transform/CompileDynamic.groovy @@ -25,10 +25,9 @@ import java.lang.annotation.Documented * This can be used for example if you statically compile a full class but you want to skip * some methods without having to use the full annotation. * - * @author Cedric Champeau * @since 2.1.0 */ @Documented @AnnotationCollector(processor = "org.codehaus.groovy.transform.CompileDynamicProcessor") -public @interface CompileDynamic { +@interface CompileDynamic { } \ No newline at end of file diff --git a/src/main/groovy/groovy/transform/ConditionalInterrupt.groovy b/src/main/groovy/groovy/transform/ConditionalInterrupt.groovy index 66aa64c..0877775 100644 --- a/src/main/groovy/groovy/transform/ConditionalInterrupt.groovy +++ b/src/main/groovy/groovy/transform/ConditionalInterrupt.groovy @@ -102,9 +102,6 @@ import java.lang.annotation.Target * * @see TimedInterrupt * @see ThreadInterrupt - * @author Cedric Champeau - * @author Hamlet D'Arcy - * @author Paul King * @since 1.8.0 */ @java.lang.annotation.Documented @@ -112,44 +109,43 @@ import java.lang.annotation.Target @Target([ElementType.PACKAGE, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.LOCAL_VARIABLE]) @GroovyASTTransformationClass(["org.codehaus.groovy.transform.ConditionalInterruptibleASTTransformation"]) @interface ConditionalInterrupt { - /** - * Set this to false if you have multiple classes within one source file and only - * want a conditional check on some of the classes. Place annotations on the classes - * you want enhanced. Set to true (the default) for blanket coverage of conditional - * checks on all methods, loops and closures within all classes/script code. - * - * For even finer-grained control see {@code applyToAllMembers}. - * - * @see #applyToAllMembers() - */ - boolean applyToAllClasses() default true + /** + * Set this to false if you have multiple classes within one source file and only + * want a conditional check on some of the classes. Place annotations on the classes + * you want enhanced. Set to true (the default) for blanket coverage of conditional + * checks on all methods, loops and closures within all classes/script code. + * + * For even finer-grained control see {@code applyToAllMembers}. + * + * @see #applyToAllMembers() + */ + boolean applyToAllClasses() default true - /** - * Set this to false if you have multiple methods/closures within a class or script and only - * want conditional checks on some of them. Place annotations on the methods/closures that - * you want enhanced. When false, {@code applyToAllClasses} is automatically set to false. - * - * Set to true (the default) for blanket coverage of conditional checks on all methods, loops - * and closures within the class/script. - * - * @since 2.2.0 - * @see #applyToAllClasses() - */ - boolean applyToAllMembers() default true + /** + * Set this to false if you have multiple methods/closures within a class or script and only + * want conditional checks on some of them. Place annotations on the methods/closures that + * you want enhanced. When false, {@code applyToAllClasses} is automatically set to false. + * + * Set to true (the default) for blanket coverage of conditional checks on all methods, loops + * and closures within the class/script. + * + * @since 2.2.0* @see #applyToAllClasses() + */ + boolean applyToAllMembers() default true - /** - * By default a conditional check is added to the start of all user-defined methods. To turn this off simply - * set this parameter to false. - */ - boolean checkOnMethodStart() default true + /** + * By default a conditional check is added to the start of all user-defined methods. To turn this off simply + * set this parameter to false. + */ + boolean checkOnMethodStart() default true - /** - * Sets the type of exception which is thrown. - */ - Class thrown() default InterruptedException + /** + * Sets the type of exception which is thrown. + */ + Class thrown() default InterruptedException - /** - * Conditional check - set as a closure expression. - */ - Class value() + /** + * Conditional check - set as a closure expression. + */ + Class value() } diff --git a/src/main/groovy/groovy/transform/TailRecursive.groovy b/src/main/groovy/groovy/transform/TailRecursive.groovy index afbee50..e4e9936 100644 --- a/src/main/groovy/groovy/transform/TailRecursive.groovy +++ b/src/main/groovy/groovy/transform/TailRecursive.groovy @@ -77,11 +77,10 @@ import java.lang.annotation.Target * assert sizeOfList(1..10000) == 10000 * </pre> * - * @author Johannes Link * @since 2.3 */ @Retention(RetentionPolicy.SOURCE) @Target([ElementType.METHOD]) @GroovyASTTransformationClass(["org.codehaus.groovy.transform.tailrec.TailRecursiveASTTransformation"]) -public @interface TailRecursive { +@interface TailRecursive { } diff --git a/src/main/groovy/groovy/transform/ThreadInterrupt.groovy b/src/main/groovy/groovy/transform/ThreadInterrupt.groovy index 817507a..8c779d4 100644 --- a/src/main/groovy/groovy/transform/ThreadInterrupt.groovy +++ b/src/main/groovy/groovy/transform/ThreadInterrupt.groovy @@ -43,20 +43,10 @@ import java.lang.annotation.Target * * <pre> * <code>@groovy.transform.ThreadInterrupt</code> - * def scriptMethod() { - * 4.times { - * println 'executing script method...' - * } - * } - * - * class MyClass { - * def myMethod() { - * for (i in (1..10)) { - * println 'executing method...' - * } - * } - * } - * + * def scriptMethod() {* 4.times {* println 'executing script method...' + *}*}* + * class MyClass {* def myMethod() {* for (i in (1..10)) {* println 'executing method...' + *}*}*}* * scriptMethod() * new MyClass().myMethod() * </pre> @@ -64,85 +54,60 @@ import java.lang.annotation.Target * Which results in the following code being generated. Notice the checks and exceptions: * * <pre> - * public class script1290627909406 extends groovy.lang.Script { - * - * public java.lang.Object scriptMethod() { - * if (java.lang.Thread.currentThread().isInterrupted()) { - * throw new java.lang.InterruptedException('Execution Interrupted') - * } - * 4.times({ - * if (java.lang.Thread.currentThread().isInterrupted()) { - * throw new java.lang.InterruptedException('Execution Interrupted') - * } - * this.println('executing script method...') - * }) - * } - * } - * public class MyClass extends java.lang.Object { - * - * public java.lang.Object myMethod() { - * if (java.lang.Thread.currentThread().isInterrupted()) { - * throw new java.lang.InterruptedException('Execution Interrupted') - * } - * for (java.lang.Object i : (1..10)) { - * if (java.lang.Thread.currentThread().isInterrupted()) { - * throw new java.lang.InterruptedException('Execution Interrupted') - * } - * this.println('executing method...') - * } - * } - * } - * + * public class script1290627909406 extends groovy.lang.Script {* + * public java.lang.Object scriptMethod() {* if (java.lang.Thread.currentThread().isInterrupted()) {* throw new java.lang.InterruptedException('Execution Interrupted') + *}* 4.times({* if (java.lang.Thread.currentThread().isInterrupted()) {* throw new java.lang.InterruptedException('Execution Interrupted') + *}* this.println('executing script method...') + *}) + *}*}* public class MyClass extends java.lang.Object {* + * public java.lang.Object myMethod() {* if (java.lang.Thread.currentThread().isInterrupted()) {* throw new java.lang.InterruptedException('Execution Interrupted') + *}* for (java.lang.Object i : (1..10)) {* if (java.lang.Thread.currentThread().isInterrupted()) {* throw new java.lang.InterruptedException('Execution Interrupted') + *}* this.println('executing method...') + *}*}*}* * this.scriptMethod() * new MyClass().myMethod() * </pre> * Additional usage examples can be found in the unit test for this class. * - * @see TimedInterrupt - * @see ConditionalInterrupt - * @author Cedric Champeau - * @author Hamlet D'Arcy - * @author Paul King - * @since 1.8.0 + * @see TimedInterrupt* @see ConditionalInterrupt* @since 1.8.0 */ @Documented @Retention(RetentionPolicy.SOURCE) @Target([ElementType.PACKAGE, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.LOCAL_VARIABLE]) @GroovyASTTransformationClass(["org.codehaus.groovy.transform.ThreadInterruptibleASTTransformation"]) @interface ThreadInterrupt { - /** - * Set this to false if you have multiple classes within one source file and only - * want isInterrupted checks on some of the classes. Place annotations on the classes - * you want enhanced. Set to true (the default) for blanket coverage of isInterrupted - * checks on all methods, loops and closures within all classes/script code. - * - * For even finer-grained control see {@code applyToAllMembers}. - * - * @see #applyToAllMembers() - */ - boolean applyToAllClasses() default true + /** + * Set this to false if you have multiple classes within one source file and only + * want isInterrupted checks on some of the classes. Place annotations on the classes + * you want enhanced. Set to true (the default) for blanket coverage of isInterrupted + * checks on all methods, loops and closures within all classes/script code. + * + * For even finer-grained control see {@code applyToAllMembers}. + * + * @see #applyToAllMembers() + */ + boolean applyToAllClasses() default true - /** - * Set this to false if you have multiple methods/closures within a class or script and only - * want isInterrupted checks on some of them. Place annotations on the methods/closures that - * you want enhanced. When false, {@code applyToAllClasses} is automatically set to false. - * - * Set to true (the default) for blanket coverage of isInterrupted checks on all methods, loops - * and closures within the class/script. - * - * @since 2.2.0 - * @see #applyToAllClasses() - */ - boolean applyToAllMembers() default true + /** + * Set this to false if you have multiple methods/closures within a class or script and only + * want isInterrupted checks on some of them. Place annotations on the methods/closures that + * you want enhanced. When false, {@code applyToAllClasses} is automatically set to false. + * + * Set to true (the default) for blanket coverage of isInterrupted checks on all methods, loops + * and closures within the class/script. + * + * @since 2.2.0* @see #applyToAllClasses() + */ + boolean applyToAllMembers() default true - /** - * By default an isInterrupted check is added to the start of all user-defined methods. To turn this off simply - * set this parameter to false. - */ - boolean checkOnMethodStart() default true + /** + * By default an isInterrupted check is added to the start of all user-defined methods. To turn this off simply + * set this parameter to false. + */ + boolean checkOnMethodStart() default true - /** - * Sets the type of exception which is thrown. - */ - Class thrown() default InterruptedException + /** + * Sets the type of exception which is thrown. + */ + Class thrown() default InterruptedException } diff --git a/src/main/groovy/groovy/transform/TimedInterrupt.groovy b/src/main/groovy/groovy/transform/TimedInterrupt.groovy index 0a0c193..03fe784 100644 --- a/src/main/groovy/groovy/transform/TimedInterrupt.groovy +++ b/src/main/groovy/groovy/transform/TimedInterrupt.groovy @@ -79,16 +79,13 @@ import java.util.concurrent.TimeoutException * </pre> * See the unit test for this class for additional examples. * - * @author Hamlet D'Arcy - * @author Cedric Champeau - * @author Paul King * @see ThreadInterrupt * @see ConditionalInterrupt * @since 1.8.0 */ @Documented @Retention(RetentionPolicy.SOURCE) -@Target([ ElementType.PACKAGE, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.LOCAL_VARIABLE]) +@Target([ElementType.PACKAGE, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.LOCAL_VARIABLE]) @GroovyASTTransformationClass(["org.codehaus.groovy.transform.TimedInterruptibleASTTransformation"]) @interface TimedInterrupt { /** @@ -113,8 +110,7 @@ import java.util.concurrent.TimeoutException * Set to true (the default) for blanket coverage of timeout checks on all methods, loops * and closures within the class/script. * - * @since 2.2.0 - * @see #applyToAllClasses() + * @since 2.2.0* @see #applyToAllClasses() */ boolean applyToAllMembers() default true diff --git a/src/test/groovy/io/LineColumnReaderTest.groovy b/src/test/groovy/io/LineColumnReaderTest.groovy index 56c0793..b7ff52d 100644 --- a/src/test/groovy/io/LineColumnReaderTest.groovy +++ b/src/test/groovy/io/LineColumnReaderTest.groovy @@ -20,9 +20,6 @@ package groovy.io import java.nio.CharBuffer -/** - * @author Guillaume Laforge - */ class LineColumnReaderTest extends GroovyTestCase { String text = '''L'invitation au voyage diff --git a/src/test/groovy/lang/BenchmarkInterceptorTest.groovy b/src/test/groovy/lang/BenchmarkInterceptorTest.groovy index 58a0c97..ceeece7 100644 --- a/src/test/groovy/lang/BenchmarkInterceptorTest.groovy +++ b/src/test/groovy/lang/BenchmarkInterceptorTest.groovy @@ -19,38 +19,29 @@ package groovy.lang /** -* Test for the BenchmarkInterceptor -* @author Dierk Koenig -**/ -class BenchmarkInterceptorTest extends GroovyTestCase{ + * Test for the BenchmarkInterceptor + */ +class BenchmarkInterceptorTest extends GroovyTestCase { Interceptor benchmarkInterceptor def proxy void setUp() { benchmarkInterceptor = new BenchmarkInterceptor() - proxy = ProxyMetaClass.getInstance(Date.class) + proxy = ProxyMetaClass.getInstance(Date) proxy.setInterceptor(benchmarkInterceptor) } - // this test is not valid any more as we don't log calls void testSimpleInterception() { -/* proxy.use { - def x = new Date(0) - x++ + def x = new Date(0) + x++ } def stats = benchmarkInterceptor.statistic() assertEquals 2, stats.size() - assert stats.find{it[0] == 'ctor'} - assert stats.find{it[0] == 'next'} - assert stats.every{it[1] == 1} - assert stats.every{it[2] < 200} -*/ + assert stats.find { it[0] == 'ctor' } + assert stats.find { it[0] == 'next' } + assert stats.every { it[1] == 1 } + assert stats.every { it[2] < 200 } } - - } - - - diff --git a/src/test/groovy/lang/ClosureResolvingTest.groovy b/src/test/groovy/lang/ClosureResolvingTest.groovy index e4dddf0..64e3ea2 100644 --- a/src/test/groovy/lang/ClosureResolvingTest.groovy +++ b/src/test/groovy/lang/ClosureResolvingTest.groovy @@ -20,8 +20,7 @@ package groovy.lang /** * Tests how closures resolve to either a delegate or an owner for a given resolveStrategy - - * @author Graeme Rocher + * * @since 1.5 */ diff --git a/src/test/groovy/lang/DelegatingMetaClassTest.groovy b/src/test/groovy/lang/DelegatingMetaClassTest.groovy index 54556c7..4607069 100644 --- a/src/test/groovy/lang/DelegatingMetaClassTest.groovy +++ b/src/test/groovy/lang/DelegatingMetaClassTest.groovy @@ -18,13 +18,9 @@ */ package groovy.lang - /** * Tests for the DelegatingMetaClass - * - * @author Graeme Rocher - **/ - + */ class DelegatingMetaClassTest extends GroovyTestCase { void testIsGroovyObject() { @@ -34,4 +30,4 @@ class DelegatingMetaClassTest extends GroovyTestCase { assertEquals DelegatingMetaClassTest, metaClass.getTheClass() } -} \ No newline at end of file +} diff --git a/src/test/groovy/lang/ExpandoMetaClassCreationHandleTest.groovy b/src/test/groovy/lang/ExpandoMetaClassCreationHandleTest.groovy index 35c71fd..172f7a7 100644 --- a/src/test/groovy/lang/ExpandoMetaClassCreationHandleTest.groovy +++ b/src/test/groovy/lang/ExpandoMetaClassCreationHandleTest.groovy @@ -18,9 +18,6 @@ */ package groovy.lang; -/** - * @author Graeme Rocher - */ class ExpandoMetaClassCreationHandleTest extends GroovyTestCase { def registry = GroovySystem.metaClassRegistry MetaClass savedStringMeta @@ -45,7 +42,7 @@ class ExpandoMetaClassCreationHandleTest extends GroovyTestCase { String foo = "hello" assertEquals "HELLO", foo.toUpperCase() - Object.metaClass.doStuff = {-> delegate.toString().toUpperCase() } + Object.metaClass.doStuff = { -> delegate.toString().toUpperCase() } assertEquals "HELLO", foo.doStuff() } @@ -58,7 +55,7 @@ class ExpandoMetaClassCreationHandleTest extends GroovyTestCase { def metaClass = registry.getMetaClass(IBar) assertTrue(metaClass instanceof ExpandoMetaClass) - metaClass.helloWorld = {-> "goodbye!" } + metaClass.helloWorld = { -> "goodbye!" } def t = new Test1() assertEquals "goodbye!", t.helloWorld() @@ -72,8 +69,8 @@ class ExpandoMetaClassCreationHandleTest extends GroovyTestCase { assertTrue(metaClass instanceof ExpandoMetaClass) def map = [:] - metaClass.getAt = {Integer i -> map[i] } - metaClass.putAt = {Integer i, val -> map[i] = val } + metaClass.getAt = { Integer i -> map[i] } + metaClass.putAt = { Integer i, val -> map[i] = val } def t = new Test1() //assertEquals 2, t.metaClass.getExpandoMethods().size() @@ -93,9 +90,13 @@ class ExpandoMetaClassCreationHandleTest extends GroovyTestCase { def metaClass = registry.getMetaClass(Foo) def testValue = null - metaClass.setProperty = {String name, value -> + metaClass.setProperty = { String name, value -> def mp = delegate.metaClass.getMetaProperty(name) - if (mp) { mp.setProperty(delegate, value) } else { testValue = value } + if (mp) { + mp.setProperty(delegate, value) + } else { + testValue = value + } } def t = new Test1() @@ -113,7 +114,7 @@ class ExpandoMetaClassCreationHandleTest extends GroovyTestCase { def metaClass = registry.getMetaClass(Foo) - metaClass.getProperty = {String name -> + metaClass.getProperty = { String name -> def mp = delegate.metaClass.getMetaProperty(name) mp ? mp.getProperty(delegate) : "foo $name" } @@ -134,7 +135,7 @@ class ExpandoMetaClassCreationHandleTest extends GroovyTestCase { def metaClass = registry.getMetaClass(Foo) - metaClass.invokeMethod = {String name, args -> + metaClass.invokeMethod = { String name, args -> def mm = delegate.metaClass.getMetaMethod(name, args) mm ? mm.invoke(delegate, args) : "bar!!" } @@ -152,8 +153,8 @@ class ExpandoMetaClassCreationHandleTest extends GroovyTestCase { def metaClass = registry.getMetaClass(List) assertTrue(metaClass instanceof ExpandoMetaClass) - metaClass.sizeDoubled = {-> delegate.size() * 2 } - metaClass.isFull = {-> false } + metaClass.sizeDoubled = { -> delegate.size() * 2 } + metaClass.isFull = { -> false } def list = new ArrayList() @@ -178,7 +179,7 @@ class ExpandoMetaClassCreationHandleTest extends GroovyTestCase { metaClass = registry.getMetaClass(url.getClass()) assertTrue(metaClass instanceof ExpandoMetaClass) - metaClass.toUpperString = {-> + metaClass.toUpperString = { -> delegate.toString().toUpperCase() } @@ -195,7 +196,7 @@ class ExpandoMetaClassCreationHandleTest extends GroovyTestCase { metaClass = registry.getMetaClass(Object) } - metaClass.toFoo = {-> "foo" } + metaClass.toFoo = { -> "foo" } def uri = new URI("http://bar.com") def s = "bar" @@ -203,7 +204,7 @@ class ExpandoMetaClassCreationHandleTest extends GroovyTestCase { assertEquals "foo", uri.toFoo() assertEquals "foo", s.toFoo() - metaClass.toBar = {-> "bar" } + metaClass.toBar = { -> "bar" } assertEquals "bar", uri.toBar() assertEquals "bar", s.toBar() @@ -213,13 +214,13 @@ class ExpandoMetaClassCreationHandleTest extends GroovyTestCase { registry.removeMetaClass(Test1) registry.removeMetaClass(EMCInheritTest) - EMCInheritTest.metaClass.foo = {-> "hello!" } + EMCInheritTest.metaClass.foo = { -> "hello!" } def emc = new EMCInheritTest() assertEquals "hello!", emc.foo() - Test1.metaClass.foo = {-> "uck" } + Test1.metaClass.foo = { -> "uck" } emc = new EMCInheritTest() // make sure original foo wasn't overridden assertEquals "hello!", emc.foo() @@ -232,13 +233,13 @@ class ExpandoMetaClassCreationHandleTest extends GroovyTestCase { registry.removeMetaClass(IBar) registry.removeMetaClass(Object) - EMCInheritTest.metaClass.methodMissing = {String name, args -> "hello!" } + EMCInheritTest.metaClass.methodMissing = { String name, args -> "hello!" } def emc = new EMCInheritTest() assertEquals "hello!", emc.foo() - Test1.metaClass.methodMissing = {String name, args -> "uck" } + Test1.metaClass.methodMissing = { String name, args -> "uck" } emc = new EMCInheritTest() // make sure original foo wasn't overridden assertEquals "hello!", emc.bar() diff --git a/src/test/groovy/lang/ExpandoMetaClassTest.groovy b/src/test/groovy/lang/ExpandoMetaClassTest.groovy index 7451127..f285ad4 100644 --- a/src/test/groovy/lang/ExpandoMetaClassTest.groovy +++ b/src/test/groovy/lang/ExpandoMetaClassTest.groovy @@ -18,9 +18,6 @@ */ package groovy.lang -/** - * @author Graeme Rocher - */ class ExpandoMetaClassTest extends GroovyTestCase { @Override @@ -42,7 +39,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { void testClosureCallDoCall() { ExpandoMetaClass.enableGlobally() - def cl = {assert it.class == Object[]} + def cl = { assert it.class == Object[] } Object[] item = [1] try { cl(item) @@ -50,7 +47,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { ExpandoMetaClass.disableGlobally() def reg = GroovySystem.metaClassRegistry reg.removeMetaClass(cl.class) - } + } } void testFindAll() { @@ -69,33 +66,33 @@ class ExpandoMetaClassTest extends GroovyTestCase { """ } finally { ExpandoMetaClass.disableGlobally() - } + } } void testMethodsAfterAddingNewMethod() { - EMCT_Class.metaClass.newMethod = {-> "foo" } + EMCT_Class.metaClass.newMethod = { -> "foo" } - def methods = EMCT_Class.metaClass.methods.findAll {it.name == "newMethod"} + def methods = EMCT_Class.metaClass.methods.findAll { it.name == "newMethod" } assert methods assertEquals 1, methods.size() - EMCT_Class.metaClass.newMethod = {-> "foo" } + EMCT_Class.metaClass.newMethod = { -> "foo" } - methods = EMCT_Class.metaClass.methods.findAll {it.name == "newMethod"} + methods = EMCT_Class.metaClass.methods.findAll { it.name == "newMethod" } assert methods assertEquals 1, methods.size() } void testPropertiesAfterAddingProperty() { - EMCT_Class.metaClass.getNewProp = {-> "foo" } + EMCT_Class.metaClass.getNewProp = { -> "foo" } - def props = EMCT_Class.metaClass.properties.findAll {it.name == "newProp"} + def props = EMCT_Class.metaClass.properties.findAll { it.name == "newProp" } assert props assertEquals 1, props.size() - EMCT_Class.metaClass.setNewProp = {String txt -> } + EMCT_Class.metaClass.setNewProp = { String txt -> } - props = EMCT_Class.metaClass.properties.findAll {it.name == "newProp"} + props = EMCT_Class.metaClass.properties.findAll { it.name == "newProp" } assert props assertEquals 1, props.size() } @@ -123,7 +120,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { mc.initialize() GroovySystem.metaClassRegistry.setMetaClass(EMCT_InvokeMethod.class, mc) - mc.'static'.getHello = {-> "bar!"} + mc.'static'.getHello = { -> "bar!" } assertEquals "bar!", EMCT_InvokeMethod.hello } @@ -133,7 +130,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { mc.initialize() GroovySystem.metaClassRegistry.setMetaClass(EMCT_InvokeMethod.class, mc) - mc.'static'.invokeMethod = {String methodName, args -> + mc.'static'.invokeMethod = { String methodName, args -> def metaMethod = mc.getStaticMetaMethod(methodName, args) def result = null if (metaMethod) result = metaMethod.invoke(delegate, args) @@ -153,7 +150,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { assert mc.hasMetaMethod("invokeMe", [String] as Class[]) - mc.invokeMethod = {String name, args -> + mc.invokeMethod = { String name, args -> def mm = delegate.metaClass.getMetaMethod(name, args) mm ? mm.invoke(delegate, args) : "bar!!" } @@ -172,10 +169,14 @@ class ExpandoMetaClassTest extends GroovyTestCase { assert mc.hasMetaProperty("name") def testValue = null - mc.setProperty = {String name, value -> + mc.setProperty = { String name, value -> def mp = delegate.metaClass.getMetaProperty(name) - if (mp) {mp.setProperty(delegate, value)} else {testValue = value} + if (mp) { + mp.setProperty(delegate, value) + } else { + testValue = value + } } def t = new EMCT_GetProperty() @@ -194,7 +195,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { assert mc.hasMetaProperty("name") - mc.getProperty = {String name -> + mc.getProperty = { String name -> def mp = delegate.metaClass.getMetaProperty(name) mp ? mp.getProperty(delegate) : "foo $name" @@ -212,7 +213,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { void testBooleanGetterWithClosure() { def metaClass = new ExpandoMetaClass(EMCT_Class.class, false, true) metaClass.initialize() - metaClass.isValid = {-> true} + metaClass.isValid = { -> true } def t = new EMCT_Class() t.metaClass = metaClass @@ -224,12 +225,12 @@ class ExpandoMetaClassTest extends GroovyTestCase { void testAllowAdditionOfProperties() { def metaClass = new ExpandoMetaClass(EMCT_Class.class, false, true) - metaClass.getOne << {-> + metaClass.getOne << { -> "testme" } metaClass.initialize() try { - metaClass.getTwo << {-> + metaClass.getTwo << { -> "testagain" } } @@ -247,12 +248,12 @@ class ExpandoMetaClassTest extends GroovyTestCase { void testAllowAdditionOfMethods() { def metaClass = new ExpandoMetaClass(EMCT_Class.class, false, true) - metaClass.myMethod << {-> + metaClass.myMethod << { -> "testme" } metaClass.initialize() try { - metaClass.mySecondMethod << {-> + metaClass.mySecondMethod << { -> "testagain" } } @@ -291,7 +292,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { void testPropertyGetterWithClosure() { def metaClass = new ExpandoMetaClass(EMCT_Class.class) - metaClass.getSomething = {-> "testme"} + metaClass.getSomething = { -> "testme" } metaClass.initialize() @@ -306,7 +307,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { def metaClass = new ExpandoMetaClass(EMCT_Class.class) def testSet = null - metaClass.setSomething = {String txt -> testSet = txt} + metaClass.setSomething = { String txt -> testSet = txt } metaClass.initialize() @@ -323,7 +324,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { void testNewMethodOverloading() { def metaClass = new ExpandoMetaClass(EMCT_Class.class) - metaClass.overloadMe << {String txt -> txt} << {Integer i -> i} + metaClass.overloadMe << { String txt -> txt } << { Integer i -> i } metaClass.initialize() @@ -342,7 +343,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { def metaClass = new ExpandoMetaClass(EMCT_Class.class, false, true) metaClass.initialize() - metaClass.doSomething = {Integer i -> i + 1} + metaClass.doSomething = { Integer i -> i + 1 } t.metaClass = metaClass @@ -358,7 +359,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { def metaClass = new ExpandoMetaClass(EMCT_Class.class, false, true) - metaClass.doSomething = {Integer i -> i + 1} + metaClass.doSomething = { Integer i -> i + 1 } metaClass.initialize() @@ -399,7 +400,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { void testCheckFailOnExisting() { def metaClass = new ExpandoMetaClass(EMCT_Class.class) try { - metaClass.existing << {-> + metaClass.existing << { -> "should fail. already exists!" } fail("Should have thrown exception when method already exists") @@ -412,7 +413,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { void testCheckFailOnExistingConstructor() { def metaClass = new ExpandoMetaClass(EMCT_Class.class) try { - metaClass.constructor << {-> + metaClass.constructor << { -> "should fail. already exists!" } fail("Should have thrown exception when method already exists") @@ -425,7 +426,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { void testCheckFailOnExistingStaticMethod() { def metaClass = new ExpandoMetaClass(EMCT_Class.class) try { - metaClass.'static'.existingStatic << {-> + metaClass.'static'.existingStatic << { -> "should fail. already exists!" } fail("Should have thrown exception when method already exists") @@ -438,7 +439,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { void testNewStaticMethod() { def metaClass = new ExpandoMetaClass(EMCT_Class.class, true) - metaClass.'static'.myStaticMethod << {String txt -> + metaClass.'static'.myStaticMethod << { String txt -> "testme" } metaClass.initialize() @@ -449,7 +450,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { void testReplaceStaticMethod() { def metaClass = new ExpandoMetaClass(EMCT_Class.class, true) - metaClass.'static'.existingStatic = {-> + metaClass.'static'.existingStatic = { -> "testme" } metaClass.initialize() @@ -461,7 +462,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { void testNewZeroArgumentStaticMethod() { def metaClass = new ExpandoMetaClass(EMCT_Class.class, true) - metaClass.'static'.myStaticMethod = {-> + metaClass.'static'.myStaticMethod = { -> "testme" } metaClass.initialize() @@ -487,7 +488,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { void testNewConstructor() { def metaClass = new ExpandoMetaClass(EMCT_Class.class, true) - metaClass.constructor << {String txt -> + metaClass.constructor << { String txt -> def t = EMCT_Class.class.newInstance() t.name = txt return t @@ -505,7 +506,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { void testReplaceConstructor() { def metaClass = new ExpandoMetaClass(EMCT_Class.class, true) - metaClass.constructor = {-> + metaClass.constructor = { -> "testme" } @@ -521,7 +522,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { void testReplaceInstanceMethod() { def metaClass = new ExpandoMetaClass(EMCT_Class.class) - metaClass.existing2 = {Object i -> + metaClass.existing2 = { Object i -> "testme" } metaClass.initialize() @@ -555,7 +556,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { metaClass.withOptional { String first, String second = "no param" -> - "$first + $second" + "$first + $second" } def t = new EMCT_Class() @@ -699,11 +700,11 @@ class ExpandoMetaClassTest extends GroovyTestCase { def doMethods(clazz) { def metaClass = clazz.metaClass - metaClass.setErrors = {errors -> + metaClass.setErrors = { errors -> thingo = errors } - metaClass.getErrors = {-> + metaClass.getErrors = { -> return thingo } } @@ -711,19 +712,17 @@ class ExpandoMetaClassTest extends GroovyTestCase { void testGetProperty() { def x = new EMCT_SuperClass() def mc = x.metaClass - mc.getProperty = {String name -> + mc.getProperty = { String name -> MetaProperty mp = mc.getMetaProperty(name) if (mp) mp.getProperty(delegate) else { if (thingo) { thingo."$name" - } - else { + } else { if (application) { "non-null application" - } - else { + } else { String methodName = "get${name[0].toUpperCase()}${name.substring(1)}" mc."$methodName" = { -> "$name" @@ -762,7 +761,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { } } - mc.render = {String txt -> + mc.render = { String txt -> txt } @@ -771,7 +770,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { } void testInterfaceWithGetProperty() { - EMCT_Implemented.metaClass.getProperty = {String name -> + EMCT_Implemented.metaClass.getProperty = { String name -> return "META " + delegate.class.metaClass.getMetaProperty(name).getProperty(delegate) } EMCT_InterfaceWithFormat.metaClass.getFormat = { @@ -782,15 +781,15 @@ class ExpandoMetaClassTest extends GroovyTestCase { } void testPickMethodForVarg() { - // as of 1.6 a metaClass is often the HandleMetaclass, which delegates - // methods to an underlaying meta class. hasMethod is a Method on EMC - // that takes a Class[] vargs argument as last part. If that part is not - // given, then hasMetaMethod will still work, but the code actually - // invoking the method in EMC.invokeMehod(String,Object) has to correct the - // arguments. - assert "".metaClass.pickMethod("trim") - } - + // as of 1.6 a metaClass is often the HandleMetaclass, which delegates + // methods to an underlaying meta class. hasMethod is a Method on EMC + // that takes a Class[] vargs argument as last part. If that part is not + // given, then hasMetaMethod will still work, but the code actually + // invoking the method in EMC.invokeMehod(String,Object) has to correct the + // arguments. + assert "".metaClass.pickMethod("trim") + } + void testEMCMetaClassProperty() { // GROOVY-2516 try { @@ -799,7 +798,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { GroovySystem.metaClassRegistry.removeMetaClass(ExpandoMetaClass.class) } } - + void testDynamicAddedMethodWithGStringCall() { // GROOVY-4691 assertScript """ @@ -822,7 +821,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { } static class X { - def foo() {2} + def foo() { 2 } } void testPOJOMetaClassInterception() { @@ -837,6 +836,7 @@ class ExpandoMetaClassTest extends GroovyTestCase { invoking.metaClass = null } } + void testPOGOMetaClassInterception() { X entity = new X() try { @@ -868,9 +868,9 @@ class EMCT_ChildClass extends EMCT_SuperClass { } class EMCT_InvokeMethod { - def invokeMe(String boo) {"Foo!! $boo"} + def invokeMe(String boo) { "Foo!! $boo" } - static myStaticMethod() {"bar!"} + static myStaticMethod() { "bar!" } } class EMCT_GetProperty { @@ -888,7 +888,7 @@ class EMCT_Class { "hello!" } - def doSomething(Object txt) {txt} + def doSomething(Object txt) { txt } static existingStatic() { "I exist" diff --git a/src/test/groovy/lang/GetMethodsTest.groovy b/src/test/groovy/lang/GetMethodsTest.groovy index 99c96d5..da079d6 100644 --- a/src/test/groovy/lang/GetMethodsTest.groovy +++ b/src/test/groovy/lang/GetMethodsTest.groovy @@ -20,17 +20,16 @@ package groovy.lang /** * Tests the behaviour of the runtime evaluating methods of Groovy's MetaClass system - - * @author Graeme Rocher + * * @since 1.5 */ class GetMethodsTest extends GroovyTestCase { void testGetMethods() { - GMTest2.metaClass.doStuff = {-> "foo" } - GMTest2.metaClass.getFoo = {-> "foo" } + GMTest2.metaClass.doStuff = { -> "foo" } + GMTest2.metaClass.getFoo = { -> "foo" } GMTest2.metaClass.bar = "bar" - GMTest2.metaClass.'static'.doMoreStuff = {-> "more" } + GMTest2.metaClass.'static'.doMoreStuff = { -> "more" } def t = new GMTest2() assert t.metaClass.methods.find { it.name == 'one' } @@ -50,7 +49,7 @@ class GetMethodsTest extends GroovyTestCase { } void testGetProperties() { - GMTest2.metaClass.getFoo = {-> "foo" } + GMTest2.metaClass.getFoo = { -> "foo" } GMTest2.metaClass.bar = "bar" def t = new GMTest2() @@ -68,7 +67,7 @@ class GMTest1 { String five def two = { "three" } - def one() { "two"} + def one() { "two" } def one(String one) { "two: $one" } diff --git a/src/test/groovy/lang/GroovyCodeSourceTest.groovy b/src/test/groovy/lang/GroovyCodeSourceTest.groovy index 7308ce4..9f8422f 100644 --- a/src/test/groovy/lang/GroovyCodeSourceTest.groovy +++ b/src/test/groovy/lang/GroovyCodeSourceTest.groovy @@ -18,9 +18,6 @@ */ package groovy.lang -/** - * @author Merlyn Albery-Speyer - */ class GroovyCodeSourceTest extends GroovyTestCase { void testValidEncoding() { new GroovyCodeSource(createTemporaryGroovyClassFile(), "UTF-8") @@ -37,7 +34,7 @@ class GroovyCodeSourceTest extends GroovyTestCase { void testInvalidFile() { try { - new GroovyCodeSource(new File("SomeFileThatDoesNotExist"+System.currentTimeMillis()), "UTF-8") + new GroovyCodeSource(new File("SomeFileThatDoesNotExist" + System.currentTimeMillis()), "UTF-8") fail("expected IOException") } catch (IOException) { assert true @@ -54,7 +51,7 @@ class GroovyCodeSourceTest extends GroovyTestCase { } File createTemporaryGroovyClassFile() { - String testName = "GroovyCodeSourceTest"+System.currentTimeMillis() + String testName = "GroovyCodeSourceTest" + System.currentTimeMillis() File groovyCode = new File(System.getProperty("java.io.tmpdir"), testName) groovyCode.write("class SomeClass { }") groovyCode.deleteOnExit() diff --git a/src/test/groovy/lang/GroovySystemTest.groovy b/src/test/groovy/lang/GroovySystemTest.groovy index 7bb716e..448247d 100644 --- a/src/test/groovy/lang/GroovySystemTest.groovy +++ b/src/test/groovy/lang/GroovySystemTest.groovy @@ -18,15 +18,9 @@ */ package groovy.lang -import java.util.logging.* - /** * Tests for the GroovySystem class - * - * @author Graeme Rocher - * @author Roshan Dawrani - **/ - + */ class GroovySystemTest extends GroovyTestCase { void testGetMetaClassRegistry() { @@ -37,4 +31,4 @@ class GroovySystemTest extends GroovyTestCase { void testGroovyVersion() { assert GroovySystem.getVersion() } -} \ No newline at end of file +} diff --git a/src/test/groovy/lang/InterceptorTest.groovy b/src/test/groovy/lang/InterceptorTest.groovy index 2e15539..3d74369 100644 --- a/src/test/groovy/lang/InterceptorTest.groovy +++ b/src/test/groovy/lang/InterceptorTest.groovy @@ -25,9 +25,7 @@ import org.codehaus.groovy.runtime.StringBufferWriter * TracingInterceptor. Makes also use of the ProxyMetaClass and * shows the collaboration. * As a side Effect, the ProxyMetaClass is also partly tested. - * - * @author Dierk Koenig - * */ + */ class InterceptorTest extends GroovyTestCase { def Interceptor logInterceptor diff --git a/src/test/groovy/lang/MapOfClosureTest.groovy b/src/test/groovy/lang/MapOfClosureTest.groovy index 0919bb5..653bfcb 100644 --- a/src/test/groovy/lang/MapOfClosureTest.groovy +++ b/src/test/groovy/lang/MapOfClosureTest.groovy @@ -1,115 +1,116 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package groovy.lang - -/** - * Tests maps of closures coerced to classes by asType() - * - * @author Jochen Theodorou - * @author Guillaume Laforge - */ -class MapOfClosureTest extends GroovyTestCase { - - void testInterfaceProxy() { - def outer = 1 - def x = [run: { outer++ }] as Runnable - x.run() - - assert x instanceof Runnable - assert outer == 2 - } - - void testInterfaceProxyWithoutAllMethods() { - def proxy = [ methodOne: { 'some string' } ] as MultiMethodInterface - - assert proxy instanceof MultiMethodInterface - - assertEquals 'some string', proxy.methodOne() - - shouldFail(UnsupportedOperationException) { - proxy.methodTwo() - } - } - - void testObject() { - def m = [bar: { "foo" }] - def x = m as Object - - assert x.is(m) - assert "foo" == x.bar() - } - - void testAbstractClassSubclassing() { - def outer = 1 - def x = [run: { outer++ }] as TimerTask - x.run() - assert x instanceof TimerTask - assert outer == 2 - } - - /** - * Checks public and protected methods from parents can also be overridden by the Map coercion to classes. - */ - void testOverrideProtectedMethods() { - def b = [pub: { "map pub" }, prot: { "map prot" }, child: { "map child" }] as B - - assert "map pub" == b.pub() - assert "map prot" == b.prot() - assert "map child" == b.child() - assert "abstract" == b.abstractMethod() - } - - /** - * Checks that abstract methods can also be overridden. - */ - void testAbstractMethodIsOverrided() { - def a = [abstractMethod: { "map abstract" }] as A - - assert "map abstract" == a.abstractMethod() - } - - /** - * Verify that complex method signatures, even with primitive types and arrays, can be overridden. - */ - void testComplexMethodSignature() { - def c = [foo: { int a, List b, Double[] c -> ["map foo"] as String[] }] as C - - assert ["map foo"] as String[] == c.foo(1, ['a', 'b'], [0.2, 0.3] as Double[]) - } -} - -abstract class A { - protected prot() { "prot" } - def pub() { "pub" } - abstract abstractMethod() -} - -class B extends A { - protected child() { "child" } - def abstractMethod() { "abstract" } -} - -class C { - String[] foo(int a, List b, Double[] c) { ["foo"] as String[] } -} - -interface MultiMethodInterface { - String methodOne() - String methodTwo() +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package groovy.lang + +/** + * Tests maps of closures coerced to classes by asType() + */ +class MapOfClosureTest extends GroovyTestCase { + + void testInterfaceProxy() { + def outer = 1 + def x = [run: { outer++ }] as Runnable + x.run() + + assert x instanceof Runnable + assert outer == 2 + } + + void testInterfaceProxyWithoutAllMethods() { + def proxy = [methodOne: { 'some string' }] as MultiMethodInterface + + assert proxy instanceof MultiMethodInterface + + assertEquals 'some string', proxy.methodOne() + + shouldFail(UnsupportedOperationException) { + proxy.methodTwo() + } + } + + void testObject() { + def m = [bar: { "foo" }] + def x = m as Object + + assert x.is(m) + assert "foo" == x.bar() + } + + void testAbstractClassSubclassing() { + def outer = 1 + def x = [run: { outer++ }] as TimerTask + x.run() + assert x instanceof TimerTask + assert outer == 2 + } + + /** + * Checks public and protected methods from parents can also be overridden by the Map coercion to classes. + */ + void testOverrideProtectedMethods() { + def b = [pub: { "map pub" }, prot: { "map prot" }, child: { "map child" }] as B + + assert "map pub" == b.pub() + assert "map prot" == b.prot() + assert "map child" == b.child() + assert "abstract" == b.abstractMethod() + } + + /** + * Checks that abstract methods can also be overridden. + */ + void testAbstractMethodIsOverrided() { + def a = [abstractMethod: { "map abstract" }] as A + + assert "map abstract" == a.abstractMethod() + } + + /** + * Verify that complex method signatures, even with primitive types and arrays, can be overridden. + */ + void testComplexMethodSignature() { + def c = [foo: { int a, List b, Double[] c -> ["map foo"] as String[] }] as C + + assert ["map foo"] as String[] == c.foo(1, ['a', 'b'], [0.2, 0.3] as Double[]) + } +} + +abstract class A { + protected prot() { "prot" } + + def pub() { "pub" } + + abstract abstractMethod() +} + +class B extends A { + protected child() { "child" } + + def abstractMethod() { "abstract" } +} + +class C { + String[] foo(int a, List b, Double[] c) { ["foo"] as String[] } +} + +interface MultiMethodInterface { + String methodOne() + + String methodTwo() } \ No newline at end of file diff --git a/src/test/groovy/lang/MetaClassRegistryTest.groovy b/src/test/groovy/lang/MetaClassRegistryTest.groovy index 120bb4c..83d4f13 100644 --- a/src/test/groovy/lang/MetaClassRegistryTest.groovy +++ b/src/test/groovy/lang/MetaClassRegistryTest.groovy @@ -21,9 +21,6 @@ package groovy.lang /** * GROOVY-2875: MetaClassRegistryImpl constantMetaClasses map is leaking resources * GROOVY-4481: the listener and iterator mechanism over the MetaClassRegistry wasn't working. - * - * @author Jochen Theodorou - * @author Guillaume Laforge */ class MetaClassRegistryTest extends GroovyTestCase { @@ -32,7 +29,7 @@ class MetaClassRegistryTest extends GroovyTestCase { static { try { Class.forName("org.codehaus.groovy.vmplugin.v7.IndyInterface", true, MetaClassRegistryTest.classLoader) - } catch(e){ + } catch (e) { } initSize = GroovySystem.metaClassRegistry.metaClassRegistryChangeEventListeners.size() } @@ -42,7 +39,7 @@ class MetaClassRegistryTest extends GroovyTestCase { def listener = { event -> called = event } as MetaClassRegistryChangeEventListener registry.addMetaClassRegistryChangeEventListener listener - Integer.metaClass.foo = {->} + Integer.metaClass.foo = { -> } assert 1.foo() == null assert called != null @@ -94,7 +91,7 @@ class MetaClassRegistryTest extends GroovyTestCase { } void testIteratorRemove() { - Integer.metaClass.foo {-> 1 } + Integer.metaClass.foo { -> 1 } assert 1.foo() == 1 for (def it = registry.iterator(); it.hasNext();) { it.remove() diff --git a/src/test/groovy/lang/PropertyMissingTest.groovy b/src/test/groovy/lang/PropertyMissingTest.groovy index 9ef4ae8..7016464 100644 --- a/src/test/groovy/lang/PropertyMissingTest.groovy +++ b/src/test/groovy/lang/PropertyMissingTest.groovy @@ -21,14 +21,13 @@ package groovy.lang /** * Tests the behaviour of the propertyMissing functionality of Groovy * - * @author Graeme Rocher * @since 1.5 */ class PropertyMissingTest extends GroovyTestCase { void testPropertyMissingWithMethods() { - def t = new PMTest1() + def t = new PMTest1() assertEquals "bar", t.foo t.foo = "changed" @@ -43,21 +42,21 @@ class PropertyMissingTest extends GroovyTestCase { void testPropertyMissingViaMetaClass() { def store = [:] PMTest2.metaClass.propertyMissing = { String name -> - store.name + store.name } PMTest2.metaClass.propertyMissing = { String name, value -> - store.name = value + store.name = value } def t = new PMTest2() - assertEquals "bar", t.foo - t.foo = "changed" - assertEquals "changed", t.foo - assertNull t.bar - t.bar = "keepme" + assertEquals "bar", t.foo + t.foo = "changed" + assertEquals "changed", t.foo + assertNull t.bar + t.bar = "keepme" - assertEquals "keepme", t.bar + assertEquals "keepme", t.bar } @@ -102,9 +101,11 @@ class PropertyMissingTest extends GroovyTestCase { class PMTest1 { def store = [:] String foo = "bar" + String propertyMissing(String name) { store.name } + void propertyMissing(String name, value) { store.name = value } @@ -116,6 +117,7 @@ class PMTest2 { class PMTest3 { String foo = 'bar' + void propertyMissing(String name, value) { foo = "${name}-${value}" } diff --git a/src/test/groovy/lang/ReferenceSerializationTest.groovy b/src/test/groovy/lang/ReferenceSerializationTest.groovy index c6bb043..603cf12 100644 --- a/src/test/groovy/lang/ReferenceSerializationTest.groovy +++ b/src/test/groovy/lang/ReferenceSerializationTest.groovy @@ -20,8 +20,6 @@ package groovy.lang /** * GROOVY-4305: Make groovy.lang.Reference implement Serializable - * - * @author Guillaume Laforge */ class ReferenceSerializationTest extends GroovyTestCase implements Serializable { diff --git a/src/test/groovy/lang/RespondsToTest.groovy b/src/test/groovy/lang/RespondsToTest.groovy index 7ca2a8d..890ed44 100644 --- a/src/test/groovy/lang/RespondsToTest.groovy +++ b/src/test/groovy/lang/RespondsToTest.groovy @@ -21,13 +21,12 @@ package groovy.lang /** * Tests the respondsTo functionality of Groovy * - * @author Graeme Rocher * @since 1.6.0 */ class RespondsToTest extends GroovyTestCase { void testRespondsToForMethodEvaluation() { - RespondsToTestClass.metaClass.invokeMethod = {String name, args -> + RespondsToTestClass.metaClass.invokeMethod = { String name, args -> def methods = RespondsToTestClass.metaClass.respondsTo(delegate, name, args*.getClass() as Class[]) def result if (methods) { @@ -36,8 +35,7 @@ class RespondsToTest extends GroovyTestCase { result = methods[0].invoke(delegate, [args] as Object[]) else result = methods[0].invoke(delegate, args) - } - else { + } else { result = "foo" } result @@ -58,7 +56,7 @@ class RespondsToTest extends GroovyTestCase { } void testRespondsTo() { - RTTest2.metaClass.newM = {-> "foo" } + RTTest2.metaClass.newM = { -> "foo" } def t = new RTTest2() assert t.metaClass.respondsTo(t, "one") assert t.metaClass.respondsTo(t, "three") @@ -90,7 +88,7 @@ class RespondsToTest extends GroovyTestCase { } void testHasProperty() { - RTTest2.metaClass.getNewProp = {-> "new" } + RTTest2.metaClass.getNewProp = { -> "new" } def t = new RTTest2() assert t.metaClass.hasProperty(t, "two") assert t.metaClass.hasProperty(t, "newtwo") @@ -128,7 +126,7 @@ class RTTest1 { String five def two = { "three" } - def one() { "two"} + def one() { "two" } def one(String one) { "two: $one" } diff --git a/src/test/groovy/lang/ScriptSourcePositionInAstTest.groovy b/src/test/groovy/lang/ScriptSourcePositionInAstTest.groovy index 55e7a84..d550ddb 100644 --- a/src/test/groovy/lang/ScriptSourcePositionInAstTest.groovy +++ b/src/test/groovy/lang/ScriptSourcePositionInAstTest.groovy @@ -23,8 +23,6 @@ import org.codehaus.groovy.control.Phases /** * Check that scripts have proper source position in the AST - * - * @author Guillaume Laforge */ class ScriptSourcePositionInAstTest extends GroovyTestCase { @@ -32,7 +30,7 @@ class ScriptSourcePositionInAstTest extends GroovyTestCase { CompilationUnit cu = new CompilationUnit() cu.addSource("scriptSourcePosition.groovy", text) cu.compile(Phases.SEMANTIC_ANALYSIS) - + def node = cu.getAST().getClass("scriptSourcePosition") [[node.getLineNumber(), node.getColumnNumber()], [node.getLastLineNumber(), node.getLastColumnNumber()]] diff --git a/src/test/groovy/mock/interceptor/Caller.groovy b/src/test/groovy/mock/interceptor/Caller.groovy index c3a93cf..386f695 100644 --- a/src/test/groovy/mock/interceptor/Caller.groovy +++ b/src/test/groovy/mock/interceptor/Caller.groovy @@ -19,23 +19,25 @@ package groovy.mock.interceptor /** - Helper class for testing. - @author Dierk Koenig -*/ - + * Helper class for testing. + */ class Caller { int collaborateOne() { return new Collaborator().one() } + int collaborateOne(int arg) { - return new Collaborator().one( arg ) + return new Collaborator().one(arg) } + int collaborateOne(int one, two) { - return new Collaborator().one( one, two ) + return new Collaborator().one(one, two) } + int collaborateTwo() { return new Collaborator().two() } + String collaborateJava() { return 'whatever'.toString() } @@ -43,6 +45,7 @@ class Caller { String callFoo1() { return new Collaborator().foo } + String callFoo2() { return new Collaborator().foo } diff --git a/src/test/groovy/mock/interceptor/Collaborator.groovy b/src/test/groovy/mock/interceptor/Collaborator.groovy index df3895d..7c1b503 100644 --- a/src/test/groovy/mock/interceptor/Collaborator.groovy +++ b/src/test/groovy/mock/interceptor/Collaborator.groovy @@ -19,24 +19,25 @@ package groovy.mock.interceptor /** - Helper class for testing. - @author Dierk Koenig -*/ - + * Helper class for testing. + */ class Collaborator { String foo = "bar" String bar = "foo" - + def one() { throw new RuntimeException('Never reach here. Should have been mocked.') } + def one(int arg) { throw new RuntimeException('Never reach here. Should have been mocked.') } + def one(int one, int two) { throw new RuntimeException('Never reach here. Should have been mocked.') } + def two() { throw new RuntimeException('Never reach here. Should have been mocked.') } diff --git a/src/test/groovy/mock/interceptor/MockSingleCallTest.groovy b/src/test/groovy/mock/interceptor/MockSingleCallTest.groovy index 04ddb04..36f8605 100644 --- a/src/test/groovy/mock/interceptor/MockSingleCallTest.groovy +++ b/src/test/groovy/mock/interceptor/MockSingleCallTest.groovy @@ -21,11 +21,9 @@ package groovy.mock.interceptor import junit.framework.AssertionFailedError /** - Testing Groovy Mock support for single calls to the Collaborator with - no, one, multiple, or arbitrary arguments, exceptions and failures. - @author Dierk Koenig -*/ - + * Testing Groovy Mock support for single calls to the Collaborator with + * no, one, multiple, or arbitrary arguments, exceptions and failures. + */ class MockSingleCallTest extends GroovyTestCase { MockFor mocker @@ -35,18 +33,18 @@ class MockSingleCallTest extends GroovyTestCase { } void testMockGetter() { - mocker.demand.getFoo { "foo" } - mocker.demand.getFoo { "foobar" } - mocker.use { - assertEquals "foo", new Caller().callFoo1() - assertEquals "foobar", new Caller().callFoo2() - } + mocker.demand.getFoo { "foo" } + mocker.demand.getFoo { "foobar" } + mocker.use { + assertEquals "foo", new Caller().callFoo1() + assertEquals "foobar", new Caller().callFoo2() + } } void testMockSetter() { def result = null - + mocker.demand.setBar { result = it } mocker.demand.setBar { result = it } @@ -58,25 +56,28 @@ class MockSingleCallTest extends GroovyTestCase { } } - + void testSingleCallNoArgs() { mocker.demand.one { 1 } mocker.use { assertEquals 1, new Caller().collaborateOne() } } + void testSingleCallOneArg() { mocker.demand.one { arg -> return arg } mocker.use { assertEquals 2, new Caller().collaborateOne(2) } } + void testSingleCallTwoArgs() { mocker.demand.one { one, two -> return one + two } mocker.use { assertEquals 2, new Caller().collaborateOne(1, 1) } } + void testNoSingleCallTwoArgsWhenNoArgDemanded() { mocker.demand.one { 2 } mocker.use { @@ -85,18 +86,21 @@ class MockSingleCallTest extends GroovyTestCase { } } } + void testSingleCallTwoArgsWhenArbitraryArgsDemanded() { - mocker.demand.one { Object[] arg -> 2 } + mocker.demand.one { Object[] arg -> 2 } mocker.use { assertEquals 2, new Caller().collaborateOne(1, 1) } } + void testSingleCallTwoArgsWhenDefaultArgsDemanded() { - mocker.demand.one { one=null, two=null -> 2 } + mocker.demand.one { one = null, two = null -> 2 } mocker.use { assertEquals 2, new Caller().collaborateOne(1, 1) } } + void testVerifyFailsIfOneDemandedButNoneExcecuted() { mocker.demand.one { 1 } def msg = shouldFail(AssertionFailedError.class) { @@ -110,6 +114,7 @@ class MockSingleCallTest extends GroovyTestCase { exception. */ // assert msg =~ /0.*1..1.*never called/ } + void testFirstOptionalOmitted() { mocker.demand.one(0..1) { 1 } mocker.use { @@ -117,6 +122,7 @@ class MockSingleCallTest extends GroovyTestCase { } // Getting here means no exception, which is what we want to test. (Fix for GROOVY-2309) } + void testSingleCallExceptionDemanded() { mocker.demand.one { throw new IllegalArgumentException() } mocker.use { @@ -126,12 +132,14 @@ class MockSingleCallTest extends GroovyTestCase { } } } + void testSingleCallFailDemanded() { mocker.demand.one { fail 'just kidding' } mocker.use { shouldFail() { new Caller().collaborateOne() } } } + void testJavaCall() { mocker = new MockFor(String.class) mocker.demand.toString { 'groovy' } diff --git a/src/test/groovy/mock/interceptor/StubCallSequenceTest.groovy b/src/test/groovy/mock/interceptor/StubCallSequenceTest.groovy index d0e51bd..1011743 100644 --- a/src/test/groovy/mock/interceptor/StubCallSequenceTest.groovy +++ b/src/test/groovy/mock/interceptor/StubCallSequenceTest.groovy @@ -23,8 +23,6 @@ import junit.framework.AssertionFailedError /** * Testing Groovy Stub support for multiple calls to the Collaborator with * demanding one or two methods multiple and and various ranges. - * - * @author Dierk Koenig */ class StubCallSequenceTest extends GroovyTestCase { diff --git a/src/test/groovy/mock/interceptor/StubSingleCallTest.groovy b/src/test/groovy/mock/interceptor/StubSingleCallTest.groovy index 48c21f3..3785175 100644 --- a/src/test/groovy/mock/interceptor/StubSingleCallTest.groovy +++ b/src/test/groovy/mock/interceptor/StubSingleCallTest.groovy @@ -19,10 +19,8 @@ package groovy.mock.interceptor /** - Testing Groovy Stub support for single calls to the Collaborator - @author Dierk Koenig -*/ - + * Testing Groovy Stub support for single calls to the Collaborator + */ class StubSingleCallTest extends GroovyTestCase { StubFor stub diff --git a/src/test/groovy/operator/BitwiseOperatorsTest.groovy b/src/test/groovy/operator/BitwiseOperatorsTest.groovy index 5e29e37..fc5c719 100644 --- a/src/test/groovy/operator/BitwiseOperatorsTest.groovy +++ b/src/test/groovy/operator/BitwiseOperatorsTest.groovy @@ -18,10 +18,8 @@ */ package groovy.operator -/** +/** * Test Bitwise Operations - * - * @author Pilho Kim */ class BitwiseOperatorsTest extends GroovyTestCase { @@ -166,38 +164,38 @@ class BitwiseOperatorsTest extends GroovyTestCase { } void testBitwiseOrInClosure() { - def c1 = {x, y -> return x | y} + def c1 = { x, y -> return x | y } assert c1(14, 5) == 15 // 0x0000000E | 0x00000005 = 0x0000000F assert c1(0x0D, 0xFE) == 255 // 0x0000000D | 0x000000FE = 0x000000FF - def c2 = {x, y -> return x | y} + def c2 = { x, y -> return x | y } assert c2(14, 5) == 15 // 0x0000000E | 0x00000005 = 0x0000000F assert c2(0x0D, 0xFE) == 255 // 0x0000000D | 0x000000FE = 0x000000FF } void testAmbiguityOfBitwiseOr() { - def c1 = {x, y -> return x | y} + def c1 = { x, y -> return x | y } assert c1(14, 5) == 15 // 0x0000000E | 0x00000005 = 0x0000000F assert c1(0x0D, 0xFE) == 255 // 0x0000000D | 0x000000FE = 0x000000FF - def c2 = {x, y -> return x | y} + def c2 = { x, y -> return x | y } assert c2(14, 5) == 15 // 0x0000000E | 0x00000005 = 0x0000000F assert c2(0x0D, 0xFE) == 255 // 0x0000000D | 0x000000FE = 0x000000FF def x = 3 def y = 5 - c1 = {xx -> return y} // -> is a closure delimiter - c2 = {return x & y} // & is a bitAnd - def c3 = {return x ^ y} // & is a bitXor + c1 = { xx -> return y } // -> is a closure delimiter + c2 = { return x & y } // & is a bitAnd + def c3 = { return x ^ y } // & is a bitXor def c11 = { xx -> return y // -> is a closure delimiter } def c12 = { return (x | y) // | is a bitOr } - def c13 = {xx -> return y // -> is a closure delimiter + def c13 = { xx -> return y // -> is a closure delimiter } - def c14 = {-> return x | y // last | is a bitOr + def c14 = { -> return x | y // last | is a bitOr } assert c1(null) == 5 @@ -210,18 +208,18 @@ class BitwiseOperatorsTest extends GroovyTestCase { x = 0x03 - def d1 = {xx -> return xx} // -> is a closure delimiter - def d2 = {return x & x} // & is a bitAnd - def d3 = {return x ^ x} // & is a bitXor + def d1 = { xx -> return xx } // -> is a closure delimiter + def d2 = { return x & x } // & is a bitAnd + def d3 = { return x ^ x } // & is a bitXor def d11 = { xx -> return xx // -> is a closure delimiter } def d12 = { return (x | x) // | is a bitOr } - def d13 = {xx -> return xx // -> is a closure delimiter + def d13 = { xx -> return xx // -> is a closure delimiter } - def d14 = {-> return x | x // last | is a bitOr + def d14 = { -> return x | x // last | is a bitOr } assert d1(0xF0) == 0xF0 assert d2(0xF0) == 0x03 diff --git a/src/test/groovy/operator/NegateListsTest.groovy b/src/test/groovy/operator/NegateListsTest.groovy index 13c768c..2132971 100644 --- a/src/test/groovy/operator/NegateListsTest.groovy +++ b/src/test/groovy/operator/NegateListsTest.groovy @@ -18,11 +18,9 @@ */ package groovy.operator -/** +/** * Test to negate lists in Classic Groovy. * Test to check whether a given function is even/odd on a given domain. - * - * @author Pilho Kim */ class NegateListsTest extends GroovyTestCase { @@ -64,7 +62,7 @@ class NegateListsTest extends GroovyTestCase { def n = 1000 // the number of partitions for the interval 0..2/PI def x = [] for (i in 0..n) { - x << i*PI/n + x << i * PI / n } def cos = { Math.cos(it) } diff --git a/src/test/groovy/operator/PowerOperatorsTest.groovy b/src/test/groovy/operator/PowerOperatorsTest.groovy index 85e81e7..9c6a378 100644 --- a/src/test/groovy/operator/PowerOperatorsTest.groovy +++ b/src/test/groovy/operator/PowerOperatorsTest.groovy @@ -18,11 +18,8 @@ */ package groovy.operator -/** +/** * Test Math Power Operation in Classic/New Groovy - * - * @author Pilho Kim - * @version $Revision: 4996 $ */ class PowerOperatorsTest extends GroovyTestCase { @@ -33,10 +30,10 @@ class PowerOperatorsTest extends GroovyTestCase { assert -3**4 == -81 assert 3**-4 == 3.power(-4) assert -3**-4 == -3.power(-4) - assert 7**2 - 7*3 + 2 == 30 // 49 - 21 + 2 = 30 - assert -7**2 - 7*3 + 2 == -68 // -49 - 21 + 2 = -68 - assert -(7**2) - 7*3 + 2 == -68 // -49 - 21 + 2 = -68 - assert (-7)**2 - 7*3 + 2 == 30 // 49 - 21 + 2 = 30 + assert 7**2 - 7 * 3 + 2 == 30 // 49 - 21 + 2 = 30 + assert -7**2 - 7 * 3 + 2 == -68 // -49 - 21 + 2 = -68 + assert -(7**2) - 7 * 3 + 2 == -68 // -49 - 21 + 2 = -68 + assert (-7)**2 - 7 * 3 + 2 == 30 // 49 - 21 + 2 = 30 } void testPowerOperation() { @@ -64,9 +61,9 @@ class PowerOperatorsTest extends GroovyTestCase { assert x == 7 println("${(--x)**2}") assert x == 6 - assert (--x)**2 + x*2 - 1 == 34 // 5**2 + 5*2 - 1 = 34 + assert (--x)**2 + x * 2 - 1 == 34 // 5**2 + 5*2 - 1 = 34 assert x == 5 - assert (x--)**2 + x*2 - 1 == 32 // 5**2 + 4*2 - 1 = 32 + assert (x--)**2 + x * 2 - 1 == 32 // 5**2 + 4*2 - 1 = 32 assert x == 4 } @@ -85,8 +82,8 @@ class PowerOperatorsTest extends GroovyTestCase { x **= y assert x == 25 assert x**y == 625 - assert x**-1 == 1/25 - assert x**-y == 1/625 + assert x**-1 == 1 / 25 + assert x**-y == 1 / 625 assert x**-y == x**(-y) } diff --git a/src/test/groovy/operator/SpreadListOperatorTest.groovy b/src/test/groovy/operator/SpreadListOperatorTest.groovy index 62a1097..eaffe2e 100644 --- a/src/test/groovy/operator/SpreadListOperatorTest.groovy +++ b/src/test/groovy/operator/SpreadListOperatorTest.groovy @@ -24,11 +24,7 @@ package groovy.operator * For an example, <pre> * assert [1, *[2, 3], 4] == [1, 2, 3, 4] * </pre> - * - * @author Pilho Kim - * @author Jochen Theodorou */ - class SpreadListOperatorTest extends GroovyTestCase { void testSpreadingInList() { @@ -36,7 +32,7 @@ class SpreadListOperatorTest extends GroovyTestCase { assert [1, *[222, 333], 456] == [1, 222, 333, 456] - def y = [1,2,3] + def y = [1, 2, 3] assert [*y] == y } @@ -112,7 +108,7 @@ class SpreadListOperatorTest extends GroovyTestCase { } void testSpreadingInClosureParameters() { - def twice = {it*2} + def twice = { it * 2 } assert twice(3) == 6 assert twice("abcd") == 'abcdabcd' diff --git a/src/test/groovy/operator/SpreadMapOperatorTest.groovy b/src/test/groovy/operator/SpreadMapOperatorTest.groovy index f455879..3241161 100644 --- a/src/test/groovy/operator/SpreadMapOperatorTest.groovy +++ b/src/test/groovy/operator/SpreadMapOperatorTest.groovy @@ -27,14 +27,11 @@ package groovy.operator * * m = ['a':11, 'aa':22, 'aaa':33] * w = ['c':100] - * m.each {w[it.key] = it.value } - * + * m.each {w[it.key] = it.value }* * assert z == w * - * @author Pilho Kim */ - -public class SpreadMapOperatorTest extends GroovyTestCase { +class SpreadMapOperatorTest extends GroovyTestCase { def f(m) { println m.c } @@ -48,30 +45,30 @@ public class SpreadMapOperatorTest extends GroovyTestCase { } def fn() { - return [ 1:'ein', 2:'zwei', 3:'drei' ] + return [1: 'ein', 2: 'zwei', 3: 'drei'] } void testSpreadMap() { try { - def m = ["a":100, "b":200] - def x = ['tt':55, *:m] + def m = ["a": 100, "b": 200] + def x = ['tt': 55, *: m] println x.size() println x - x = ['tt':55, 'yy':77] + x = ['tt': 55, 'yy': 77] println x - x = [*:m, *:m] + x = [*: m, *: m] println x assert x == m - x = [*:x, *:fn(), 100:'hundred'] + x = [*: x, *: fn(), 100: 'hundred'] println x println(x.getClass()) assert x instanceof Map - def y = [1:1, 2:2, *:[3:3, 4:4, *:[5:5], 6:6], 7:7] + def y = [1: 1, 2: 2, *: [3: 3, 4: 4, *: [5: 5], 6: 6], 7: 7] println y println(y.getClass()) - assert y == [1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7] + assert y == [1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7] } catch (Exception e) { e.printStackTrace() @@ -79,21 +76,21 @@ public class SpreadMapOperatorTest extends GroovyTestCase { } void testSpreadMapVsWithClosure() { - def m = ['a':11, 'aa':22, 'aaa':33] - def z = ['c':100, *:m] - - def w = ['c':100] + def m = ['a': 11, 'aa': 22, 'aaa': 33] + def z = ['c': 100, *: m] + + def w = ['c': 100] m.each { w[it.key] = it.value } - println z - println w + println z + println w assert z == w - def z2 = [*:m, 'c':100] + def z2 = [*: m, 'c': 100] def w2 = m w2['c'] = 100 - println z2 - println w2 + println z2 + println w2 assert z2 == w2 assert z == z2 assert w == w2 @@ -117,16 +114,19 @@ public class SpreadMapOperatorTest extends GroovyTestCase { } void testSpreadMapFunctionCall() { - def m = ['a':10, 'b':20, 'c':30] - f(*:m) // Call with only one spread map argument - f(*:m, 'e':50) // Call with one spread map argument and one named argument - f('e':100, *:m) // Call with one named argument and one spread map argument - - func('e':100, 1, 2, 3, *:m) // Call with one named argument, three usual arguments, and one spread map argument - - def l = [4, 5] - func('e':100, *l, *:m, 6) // Call with one named argument, one spread list argument, one spread map argument, and one usual argument - func(7, 'e':100, *l, *:m) // Call with one usual argument, one named argument, one spread list argument, and one spread map argument + def m = ['a': 10, 'b': 20, 'c': 30] + f(*: m) // Call with only one spread map argument + f(*: m, 'e': 50) // Call with one spread map argument and one named argument + f('e': 100, *: m) // Call with one named argument and one spread map argument + + func('e': 100, 1, 2, 3, *: m) + // Call with one named argument, three usual arguments, and one spread map argument + + def l = [4, 5] + func('e': 100, *l, *: m, 6) + // Call with one named argument, one spread list argument, one spread map argument, and one usual argument + func(7, 'e': 100, *l, *: m) + // Call with one usual argument, one named argument, one spread list argument, and one spread map argument } } diff --git a/src/test/groovy/time/TimeCategoryTest.groovy b/src/test/groovy/time/TimeCategoryTest.groovy index dd23fdc..0ad5e96 100644 --- a/src/test/groovy/time/TimeCategoryTest.groovy +++ b/src/test/groovy/time/TimeCategoryTest.groovy @@ -18,12 +18,10 @@ */ package groovy.time -/** +/** * Tests the groovy.time.TimeCategory class. * Most of these tests use January 1 as a start time to avoid * leap years and daylight savings time issues. - * - * @author Hamlet D'Arcy */ class TimeCategoryTest extends GroovyTestCase { @@ -210,8 +208,8 @@ class TimeCategoryTest extends GroovyTestCase { def t3 = t1 + 4.seconds + 2.milliseconds def t4 = t1 - 4.seconds - 2.milliseconds def t5 = t1 + 4.seconds - 2.milliseconds - def t6 = t1 - 2.milliseconds - def t7 = t1 + 2.milliseconds + def t6 = t1 - 2.milliseconds + def t7 = t1 + 2.milliseconds assert (t1 - t2).toString() == '3.998 seconds' assert (t1 - t3).toString() == '-4.002 seconds' assert (t1 - t4).toString() == '4.002 seconds' @@ -229,7 +227,7 @@ class TimeCategoryTest extends GroovyTestCase { } void testDateEquality() { - use (TimeCategory) { + use(TimeCategory) { Date dt1 = 0.days.from.now Date dt2 = new Date(0.days.from.now.time) diff --git a/src/test/groovy/transform/LazyTest.groovy b/src/test/groovy/transform/LazyTest.groovy index 91296f7..dd41ed8 100644 --- a/src/test/groovy/transform/LazyTest.groovy +++ b/src/test/groovy/transform/LazyTest.groovy @@ -23,12 +23,10 @@ import java.lang.reflect.Modifier /** * Unit tests for the Lazy annotation - * - * @author Tim Yates */ class LazyTest extends GroovyTestCase { - public void testLazyPrimitiveWrapping() { - def tester = new GroovyClassLoader().parseClass( + void testLazyPrimitiveWrapping() { + def tester = new GroovyClassLoader().parseClass( '''class MyClass { | @Lazy int index = { -> | 1 @@ -42,8 +40,8 @@ class LazyTest extends GroovyTestCase { assert field.type == Integer } - public void testLazyVolatilePrimitiveWrapping() { - def tester = new GroovyClassLoader().parseClass( + void testLazyVolatilePrimitiveWrapping() { + def tester = new GroovyClassLoader().parseClass( '''class MyClass { | @Lazy volatile int index = { -> | 1 @@ -57,8 +55,8 @@ class LazyTest extends GroovyTestCase { assert field.type == Integer } - public void testLazySoftPrimitiveWrapping() { - def tester = new GroovyClassLoader().parseClass( + void testLazySoftPrimitiveWrapping() { + def tester = new GroovyClassLoader().parseClass( '''class MyClass { | @Lazy(soft=true) int index = { -> | 1 @@ -72,8 +70,8 @@ class LazyTest extends GroovyTestCase { assert field.type == SoftReference } - public void testLazyVolatileSoftPrimitiveWrapping() { - def tester = new GroovyClassLoader().parseClass( + void testLazyVolatileSoftPrimitiveWrapping() { + def tester = new GroovyClassLoader().parseClass( '''class MyClass { | @Lazy(soft=true) volatile int index = { -> | 1 diff --git a/src/test/groovy/transform/ThreadInterruptTest.groovy b/src/test/groovy/transform/ThreadInterruptTest.groovy index c742de1..46400c1 100644 --- a/src/test/groovy/transform/ThreadInterruptTest.groovy +++ b/src/test/groovy/transform/ThreadInterruptTest.groovy @@ -26,8 +26,6 @@ import java.lang.reflect.Modifier /** * Test for @ThreadInterrupt. - * - * @author Hamlet D'Arcy */ class ThreadInterruptTest extends GroovyTestCase { private Map<String,MethodNode> oldValues = [:]