This is an automated email from the ASF dual-hosted git repository. paulk pushed a commit to branch GROOVY_2_5_X in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 0b00c8ad62469c547466d863d3f60f35c29c0adc Author: Paul King <pa...@asert.com.au> AuthorDate: Tue Jan 1 19:42:01 2019 +1000 cleanup/remove @author tags as per Apache recommended practices cont'd --- gradle/pomconfigurer.gradle | 6 +- src/test/groovy/FileTest.groovy | 3 - src/test/groovy/FilterLineTest.groovy | 2 - src/test/groovy/Foo.groovy | 2 - src/test/groovy/GroovyClosureMethodsTest.groovy | 2 - src/test/groovy/HexTest.groovy | 2 - src/test/groovy/IdentityClosureTest.groovy | 3 - .../groovy/InvokeNormalMethodsFirstTest.groovy | 2 - src/test/groovy/LiteralTypesTest.groovy | 190 +++--- src/test/groovy/MapConstructionTest.groovy | 2 - src/test/groovy/MapPropertyTest.groovy | 19 +- .../MethodParameterAccessWithinClosureTest.groovy | 51 +- src/test/groovy/MinMaxTest.groovy | 38 +- src/test/groovy/MultiCatchTest.groovy | 4 +- src/test/groovy/MultiDimArraysTest.groovy | 6 +- src/test/groovy/NullPropertyTest.groovy | 11 +- src/test/groovy/OverridePropertyGetterTest.groovy | 23 +- ...ateVariableAccessFromAnotherInstanceTest.groovy | 14 +- src/test/groovy/ProcessTest.groovy | 48 +- src/test/groovy/Property2Test.groovy | 3 - src/test/groovy/PropertyTest.groovy | 55 +- src/test/groovy/ReadLineTest.groovy | 43 +- src/test/groovy/RegularExpressionsTest.groovy | 130 ++-- src/test/groovy/ReturnTest.groovy | 26 +- src/test/groovy/SocketTest.groovy | 4 +- src/test/groovy/SortTest.groovy | 38 +- src/test/groovy/SpreadDotTest.groovy | 99 +-- .../groovy/SwitchWithDifferentTypesTest.groovy | 48 +- src/test/groovy/TextPropertyTest.groovy | 14 +- .../UniqueOnCollectionWithClosureTest.groovy | 15 +- .../UniqueOnCollectionWithComparatorTest.groovy | 153 ++--- src/test/groovy/VarargsMethodTest.groovy | 73 +- src/test/groovy/annotations/MyIntegerAnno.groovy | 69 +- src/test/groovy/beans/BindableTest.groovy | 745 ++++++++++----------- 34 files changed, 947 insertions(+), 996 deletions(-) diff --git a/gradle/pomconfigurer.gradle b/gradle/pomconfigurer.gradle index 6a5ce05..61aa7bb 100644 --- a/gradle/pomconfigurer.gradle +++ b/gradle/pomconfigurer.gradle @@ -588,9 +588,6 @@ project.ext.pomConfigureClosureWithoutTweaks = { name 'Chris K Wensel' } contributor { - name 'Joachim Baumann' - } - contributor { name 'David Sutherland' } contributor { @@ -684,6 +681,9 @@ project.ext.pomConfigureClosureWithoutTweaks = { name 'Thomas Heller' } contributor { + name 'John Stump' + } + contributor { name 'Ivan Ganza' } contributor { diff --git a/src/test/groovy/FileTest.groovy b/src/test/groovy/FileTest.groovy index 613a05d..9e9fe11 100644 --- a/src/test/groovy/FileTest.groovy +++ b/src/test/groovy/FileTest.groovy @@ -23,9 +23,6 @@ import static groovy.io.FileVisitResult.* /** * Unit test for File GDK methods - * - * @author Marc Guillemot - * @author Paul King */ class FileTest extends GroovyTestCase { diff --git a/src/test/groovy/FilterLineTest.groovy b/src/test/groovy/FilterLineTest.groovy index a091ad9..1611e40 100644 --- a/src/test/groovy/FilterLineTest.groovy +++ b/src/test/groovy/FilterLineTest.groovy @@ -22,8 +22,6 @@ package groovy * check that the new filterLine() method on InputStream is ok * (and indirectly test newReader() method on InputStream) * as specified in GROOVY-624 and GROOVY-625 - * - * @author <a href="mailto:jeremy.ray...@bigfoot.com">Jeremy Rayner</a> */ class FilterLineTest extends GroovyTestCase { diff --git a/src/test/groovy/Foo.groovy b/src/test/groovy/Foo.groovy index ce183e2..889dd53 100644 --- a/src/test/groovy/Foo.groovy +++ b/src/test/groovy/Foo.groovy @@ -20,8 +20,6 @@ package groovy /** * A dummy bean for testing the use of properties in Groovy - * - * @author <a href="mailto:ja...@coredevelopers.net">James Strachan</a> */ class Foo implements Serializable { diff --git a/src/test/groovy/GroovyClosureMethodsTest.groovy b/src/test/groovy/GroovyClosureMethodsTest.groovy index 256d1f6..f43a7b5 100644 --- a/src/test/groovy/GroovyClosureMethodsTest.groovy +++ b/src/test/groovy/GroovyClosureMethodsTest.groovy @@ -25,8 +25,6 @@ import java.util.concurrent.TimeUnit * Test case for the eachObject method on a file containing * zero, one or more objects (object stream). Also test cases * for eachDir, eachFileMatch and runAfter methods. - * - * @author Hein Meling */ class GroovyClosureMethodsTest extends GroovyTestCase { diff --git a/src/test/groovy/HexTest.groovy b/src/test/groovy/HexTest.groovy index a28acff..aa76b5d 100644 --- a/src/test/groovy/HexTest.groovy +++ b/src/test/groovy/HexTest.groovy @@ -20,8 +20,6 @@ package groovy /** * Test cases for encodeHex methods in DefaultGroovyMethods - * - * @author Brian Alexander (balex...@gmail.com) */ class HexTest extends GroovyTestCase { diff --git a/src/test/groovy/IdentityClosureTest.groovy b/src/test/groovy/IdentityClosureTest.groovy index 53fdbdb..65599b8 100644 --- a/src/test/groovy/IdentityClosureTest.groovy +++ b/src/test/groovy/IdentityClosureTest.groovy @@ -20,9 +20,6 @@ package groovy /** * Check that Object.identity(Closure) method works as expected - * - * @author Jeremy Rayner - * @author Guillaume Laforge */ class IdentityClosureTest extends GroovyTestCase { diff --git a/src/test/groovy/InvokeNormalMethodsFirstTest.groovy b/src/test/groovy/InvokeNormalMethodsFirstTest.groovy index aae4535..c3a179a 100644 --- a/src/test/groovy/InvokeNormalMethodsFirstTest.groovy +++ b/src/test/groovy/InvokeNormalMethodsFirstTest.groovy @@ -20,8 +20,6 @@ package groovy /** * Invoke normal methods first: if no statically typed method exist, use invokeMethod(). - * - * @author Guillaume Laforge */ class InvokeNormalMethodsFirstTest extends GroovyTestCase { diff --git a/src/test/groovy/LiteralTypesTest.groovy b/src/test/groovy/LiteralTypesTest.groovy index bbc4ae4..4a792cd 100644 --- a/src/test/groovy/LiteralTypesTest.groovy +++ b/src/test/groovy/LiteralTypesTest.groovy @@ -22,142 +22,140 @@ package groovy * Test numeric literal types (with and without suffixes) * @see org.codehaus.groovy.syntax.parser/ASTBuilder#createIntegralNumber() * @see org.codehaus.groovy.syntax.parser/ASTBuilder#createDecimalNumber() - * - * @author Brian Larson */ class LiteralTypesTest extends GroovyTestCase { void testIntegral() { - def x = 42; - assert x instanceof Integer; + def x = 42 + assert x instanceof Integer - x = 42I; - assert x instanceof Integer; + x = 42I + assert x instanceof Integer - x = 42i; - assert x instanceof Integer; + x = 42i + assert x instanceof Integer - x = 42L; - assert x instanceof Long; + x = 42L + assert x instanceof Long - x = 42G; - assert x instanceof BigInteger; + x = 42G + assert x instanceof BigInteger - x = 0xFF; //Hex - assert x instanceof Integer; - assert x == new Integer("255"); + x = 0xFF //Hex + assert x instanceof Integer + assert x == new Integer("255") - x = 0xFFL; //Hex - assert x instanceof Long; - assert x == new Long("255"); + x = 0xFFL //Hex + assert x instanceof Long + assert x == new Long("255") - x = 0xFFG; //Hex - assert x instanceof BigInteger; - assert x == new BigInteger("FF",16); + x = 0xFFG //Hex + assert x instanceof BigInteger + assert x == new BigInteger("FF",16) - x = 0x9000000000000000; - assert x instanceof BigInteger; - assert x == new BigInteger("9000000000000000",16); + x = 0x9000000000000000 + assert x instanceof BigInteger + assert x == new BigInteger("9000000000000000",16) - x = 077; //octal - assert x instanceof Integer; - assert x == new Integer("63"); + x = 077 //octal + assert x instanceof Integer + assert x == new Integer("63") - x = 077l; //octal - assert x instanceof Long; - assert x == new Long("63"); + x = 077l //octal + assert x instanceof Long + assert x == new Long("63") - x = 077g; //octal - assert x instanceof BigInteger; - assert x == new BigInteger("77",8); + x = 077g //octal + assert x instanceof BigInteger + assert x == new BigInteger("77",8) - x = 2147483647; // max integer value - assert x instanceof Integer; - assert x == new Integer("2147483647"); + x = 2147483647 // max integer value + assert x instanceof Integer + assert x == new Integer("2147483647") - x = -2147483648; // min integer constant + x = -2147483648 // min integer constant assert x < 0 - assert x == new Integer("-2147483648"); - assert x instanceof Integer, x.class; + assert x == new Integer("-2147483648") + assert x instanceof Integer, x.class - x = -2147483649; // min integer value - 1 - assert x == new Long("-2147483649"); - assert x instanceof Long; + x = -2147483649 // min integer value - 1 + assert x == new Long("-2147483649") + assert x instanceof Long - x = 2147483648; // 1 + max integer value - assert x == new Long("2147483648"); - assert x instanceof Long; + x = 2147483648 // 1 + max integer value + assert x == new Long("2147483648") + assert x instanceof Long - x = 9223372036854775807; // max long value - assert x == new Long("9223372036854775807"); - assert x instanceof Long; + x = 9223372036854775807 // max long value + assert x == new Long("9223372036854775807") + assert x instanceof Long - x = -9223372036854775808; // min long value - assert x == new Long("-9223372036854775808"); - assert x instanceof Long; + x = -9223372036854775808 // min long value + assert x == new Long("-9223372036854775808") + assert x instanceof Long - x = -9223372036854775809; // min long value - 1 - assert x == new BigInteger("-9223372036854775809"); - assert x instanceof BigInteger; + x = -9223372036854775809 // min long value - 1 + assert x == new BigInteger("-9223372036854775809") + assert x instanceof BigInteger - x = 9223372036854775808; // 1 + max long value - assert x == new BigInteger("9223372036854775808"); - assert x instanceof BigInteger; + x = 9223372036854775808 // 1 + max long value + assert x == new BigInteger("9223372036854775808") + assert x instanceof BigInteger } void testDecimal() { - def x = 3.2; - assert x instanceof BigDecimal; - assert x == new BigDecimal("3.2"); + def x = 3.2 + assert x instanceof BigDecimal + assert x == new BigDecimal("3.2") - x = 3.2G; - assert x instanceof BigDecimal; - assert x == new BigDecimal("3.2"); + x = 3.2G + assert x instanceof BigDecimal + assert x == new BigDecimal("3.2") - x = 3.2g; - assert x instanceof BigDecimal; - assert x == new BigDecimal("3.2"); + x = 3.2g + assert x instanceof BigDecimal + assert x == new BigDecimal("3.2") - x = -3.2; - assert x instanceof BigDecimal; - assert x == new BigDecimal("-3.2"); + x = -3.2 + assert x instanceof BigDecimal + assert x == new BigDecimal("-3.2") - x = 3.2D; - assert x instanceof Double; - assert x == new Double("3.2"); + x = 3.2D + assert x instanceof Double + assert x == new Double("3.2") - x = -3.2d; - assert x instanceof Double; - assert x == new Double("-3.2"); + x = -3.2d + assert x instanceof Double + assert x == new Double("-3.2") - x = 3.2F; - assert x instanceof Float; - assert x == new Float("3.2"); + x = 3.2F + assert x instanceof Float + assert x == new Float("3.2") - x = -3.2f; - assert x instanceof Float; - assert x == new Float("-3.2"); + x = -3.2f + assert x instanceof Float + assert x == new Float("-3.2") } void testExponential() { - def x = 3.1415926535e42; - assert x instanceof BigDecimal; - assert x == new BigDecimal("3.1415926535e42"); + def x = 3.1415926535e42 + assert x instanceof BigDecimal + assert x == new BigDecimal("3.1415926535e42") - x = 3.2e+2; - assert x instanceof BigDecimal; - assert x == new BigDecimal("3.2e+2"); + x = 3.2e+2 + assert x instanceof BigDecimal + assert x == new BigDecimal("3.2e+2") - x = 3.2e-2; - assert x instanceof BigDecimal; - assert x == new BigDecimal("3.2e-2"); + x = 3.2e-2 + assert x instanceof BigDecimal + assert x == new BigDecimal("3.2e-2") - x = 3.2e2d; - assert x instanceof Double; - assert x == new Double("3.2e2"); + x = 3.2e2d + assert x instanceof Double + assert x == new Double("3.2e2") - x = 3.2e2f; - assert x instanceof Float; - assert x == new Float("3.2e2"); + x = 3.2e2f + assert x instanceof Float + assert x == new Float("3.2e2") } } diff --git a/src/test/groovy/MapConstructionTest.groovy b/src/test/groovy/MapConstructionTest.groovy index 23e3033..07ba975 100644 --- a/src/test/groovy/MapConstructionTest.groovy +++ b/src/test/groovy/MapConstructionTest.groovy @@ -20,8 +20,6 @@ package groovy /** * Tests creating Maps in Groovy - * - * @author <a href="mailto:ja...@coredevelopers.net">James Strachan</a> */ class MapConstructionTest extends GroovyTestCase { diff --git a/src/test/groovy/MapPropertyTest.groovy b/src/test/groovy/MapPropertyTest.groovy index 3176145..2762721 100644 --- a/src/test/groovy/MapPropertyTest.groovy +++ b/src/test/groovy/MapPropertyTest.groovy @@ -18,22 +18,19 @@ */ package groovy -/** - * @author <a href="mailto:ja...@coredevelopers.net">James Strachan</a> - */ class MapPropertyTest extends GroovyTestCase { void testGetAndSetProperties() { - def m = [ 'name' : 'James', 'location' : 'London', 'id':1 ] - + def m = ['name': 'James', 'location': 'London', 'id': 1] + assert m.name == 'James' assert m.location == 'London' assert m.id == 1 - + m.name = 'Bob' m.location = 'Atlanta' m.id = 2 - + assert m.name == 'Bob' assert m.location == 'Atlanta' assert m.id == 2 @@ -41,16 +38,16 @@ class MapPropertyTest extends GroovyTestCase { void testSetupAndEmptyMap() { def m = [:] - + m.name = 'Bob' m.location = 'Atlanta' m.id = 2 - + assert m.name == 'Bob' assert m.location == 'Atlanta' assert m.id == 2 } - + void testMapSubclassing() { def c = new MyClass() @@ -64,7 +61,7 @@ class MapPropertyTest extends GroovyTestCase { // GROOVY-5985 void testMapPutAtWithKeyMatchingReadOnlyProperty() { - def map = [serialVersionUID:123] + def map = [serialVersionUID: 123] assert map["serialVersionUID"] == 123 assert map.serialVersionUID == 123 diff --git a/src/test/groovy/MethodParameterAccessWithinClosureTest.groovy b/src/test/groovy/MethodParameterAccessWithinClosureTest.groovy index c530b94..60d125f 100644 --- a/src/test/groovy/MethodParameterAccessWithinClosureTest.groovy +++ b/src/test/groovy/MethodParameterAccessWithinClosureTest.groovy @@ -20,41 +20,40 @@ package groovy /** * To test access to method scoped variable within closure - * - * @author <a href="mailto:jeremy.ray...@bigfoot.com">Jeremy Rayner</a> */ - - -class MethodParameterAccessWithinClosureTest extends GroovyTestCase { +class MethodParameterAccessWithinClosureTest extends GroovyTestCase { def cheese def shop - + void setUp() { cheese = null shop = ["wensleydale"] - } - void testSimpleMethodParameterAccess() { - assert "wensleydale" == vendor1("wensleydale") } + + void testSimpleMethodParameterAccess() { + assert "wensleydale" == vendor1("wensleydale") + } + void testMethodParameterWithDifferentNameToPropertyUsingClosure() { assert "wensleydale" == vendor2("wensleydale") } + void testMethodParameterWithSameNameAsPropertyUsingClosure() { assert "wensleydale" == vendor3("wensleydale") } - + void testOptionalMethodParameterUsedInClosure() { assert "wensleydale" == vendor4("wensleydale") assert null == vendor4() } - + void testDoubleParameterAndsingleParameterUsedInClosure() { - assert vendor5(5.0d,2) == 7.0d + assert vendor5(5.0d, 2) == 7.0d } - + void testAccessToMethodParameterInOverwrittenMethodCalledBySuper() { - // GROOVY-2107 - assertScript """ + // GROOVY-2107 + assertScript """ class A { // the closure is accessing the parameter def foo(x){ return {x}} @@ -66,28 +65,28 @@ class MethodParameterAccessWithinClosureTest extends GroovyTestCase { } def b = new B() assert b.foo(1).call() == 2 - """ + """ } - + private String vendor1(cheese) { cheese } - + private String vendor2(aCheese) { - shop.find() {it == aCheese} + shop.find() { it == aCheese } } - + private String vendor3(cheese) { - shop.find() {it == cheese} + shop.find() { it == cheese } } - + /** note: cheese is a field, that is intended **/ - private vendor4(aCheese=cheese) { - shop.find() {it == aCheese} + private vendor4(aCheese = cheese) { + shop.find() { it == aCheese } } - + private vendor5(double a, int b) { - b.times {a++} + b.times { a++ } return a } } \ No newline at end of file diff --git a/src/test/groovy/MinMaxTest.groovy b/src/test/groovy/MinMaxTest.groovy index 131ab39..a11a87a 100644 --- a/src/test/groovy/MinMaxTest.groovy +++ b/src/test/groovy/MinMaxTest.groovy @@ -18,48 +18,46 @@ */ package groovy -/** +/** * Tests the min() and max() functions - * - * @author <a href="mailto:ja...@coredevelopers.net">James Strachan</a> */ class MinMaxTest extends GroovyTestCase { void testSimpleMinMax() { def list = [5, 2, 6, 1, 9, 8] - + def n = list.min() assert n == 1 - + n = list.max() assert n == 9 } - + void testMinMaxWithComparator() { def people = getPeople() // let's find the maximum by name - def order = new OrderBy( { it.get('@cheese') } ) + def order = new OrderBy({ it.get('@cheese') }) def p = people.min(order) - assert p.get("@name") == "Joe" , "found person ${p}" + assert p.get("@name") == "Joe", "found person ${p}" p = people.max(order) - assert p.get("@name") == "Chris" , "found person ${p}" + assert p.get("@name") == "Chris", "found person ${p}" } - + void testMinMaxOnArraysWithComparator() { Person[] people = [ - new Person(name:'James', cheese:'Edam', location:'London'), - new Person(name:'Bob', cheese:'Cheddar', location:'Atlanta'), - new Person(name:'Chris', cheese:'Red Leicester', location:'London'), - new Person(name:'Joe', cheese:'Brie', location:'London') + new Person(name: 'James', cheese: 'Edam', location: 'London'), + new Person(name: 'Bob', cheese: 'Cheddar', location: 'Atlanta'), + new Person(name: 'Chris', cheese: 'Red Leicester', location: 'London'), + new Person(name: 'Joe', cheese: 'Brie', location: 'London') ] // let's find the maximum by name - def order = new OrderBy( { it.cheese } ) + def order = new OrderBy({ it.cheese }) def p = people.min(order) assert p.name == "Joe", "Expected to find Joe but found person ${p}" @@ -71,12 +69,12 @@ class MinMaxTest extends GroovyTestCase { def getPeople() { def builder = new NodeBuilder() def tree = builder.people { - person(name:'James', cheese:'Edam', location:'London') - person(name:'Bob', cheese:'Cheddar', location:'Atlanta') - person(name:'Chris', cheese:'Red Leicester', location:'London') - person(name:'Joe', cheese:'Brie', location:'London') + person(name: 'James', cheese: 'Edam', location: 'London') + person(name: 'Bob', cheese: 'Cheddar', location: 'Atlanta') + person(name: 'Chris', cheese: 'Red Leicester', location: 'London') + person(name: 'Joe', cheese: 'Brie', location: 'London') } - + return tree.children() } diff --git a/src/test/groovy/MultiCatchTest.groovy b/src/test/groovy/MultiCatchTest.groovy index 06647d6..d23829f 100644 --- a/src/test/groovy/MultiCatchTest.groovy +++ b/src/test/groovy/MultiCatchTest.groovy @@ -20,10 +20,8 @@ package groovy /** * Test for the multi-catch exception from JDK 7 (Project Coin) - * - * @author Cedric Champeau */ -class MultiCatchTest extends GroovyTestCase{ +class MultiCatchTest extends GroovyTestCase { void testDynamicCatch() { def catched = false diff --git a/src/test/groovy/MultiDimArraysTest.groovy b/src/test/groovy/MultiDimArraysTest.groovy index ee32286..4327432 100644 --- a/src/test/groovy/MultiDimArraysTest.groovy +++ b/src/test/groovy/MultiDimArraysTest.groovy @@ -20,8 +20,6 @@ package groovy /** * Expose how to deal with multi-dimensional Arrays until this is supported at the language level. - * @author Dierk Koenig - * @author Jochen Theodorou */ class MultiDimArraysTest extends GroovyTestCase { @@ -44,13 +42,13 @@ class MultiDimArraysTest extends GroovyTestCase { def someArrayOfStringArrays = new SomeClass().anArrayOfStringArraysWorkaround() assert 1 == someArrayOfStringArrays.size() assert "whatever" == someArrayOfStringArrays[0][0] - someArrayOfStringArrays.each() { assert it} + someArrayOfStringArrays.each() { assert it } } void testInsideGroovyMultiDimReplacement() { Object[] someArrayOfStringArrays = [["a", "a", "a"], ["b", "b", "b", null]] assert "a" == someArrayOfStringArrays[0][0] - someArrayOfStringArrays.each() { assert it} + someArrayOfStringArrays.each() { assert it } } void testMultiDimCreationWithSizes() { diff --git a/src/test/groovy/NullPropertyTest.groovy b/src/test/groovy/NullPropertyTest.groovy index 0e75162..7e59c80 100644 --- a/src/test/groovy/NullPropertyTest.groovy +++ b/src/test/groovy/NullPropertyTest.groovy @@ -18,15 +18,12 @@ */ package groovy -/** - * @author Jeremy Rayner - */ -class NullPropertyTest extends GroovyTestCase { +class NullPropertyTest extends GroovyTestCase { def wensleydale = null - void testNullProperty() { - assert wensleydale == null - } + void testNullProperty() { + assert wensleydale == null + } } diff --git a/src/test/groovy/OverridePropertyGetterTest.groovy b/src/test/groovy/OverridePropertyGetterTest.groovy index ca6fb2d..70c1c3d 100644 --- a/src/test/groovy/OverridePropertyGetterTest.groovy +++ b/src/test/groovy/OverridePropertyGetterTest.groovy @@ -20,25 +20,22 @@ package groovy /** * test to ensure that overriding getter doesn't throw a NPE on access - * - * @author <a href="mailto:jeremy.ray...@bigfoot.com">Jeremy Rayner</a> */ - -class OverridePropertyGetterTest extends GroovyTestCase { +class OverridePropertyGetterTest extends GroovyTestCase { def cheese - - void testSimpleMethodParameterAccess() { - def o = new OverridePropertyGetterTest() - def p = new OverridePropertyGetterTest() - try { - //@todo - //p.cheese = o.cheese + + void testSimpleMethodParameterAccess() { + def o = new OverridePropertyGetterTest(cheese: 'Edam') + def p = new OverridePropertyGetterTest(cheese: 'Cheddar') + try { + p.cheese = o.cheese } catch (Exception e) { fail(e.getMessage()) } + assert p.cheese == 'Edam' } - - public String getCheese() { + + String getCheese() { return cheese } } diff --git a/src/test/groovy/PrivateVariableAccessFromAnotherInstanceTest.groovy b/src/test/groovy/PrivateVariableAccessFromAnotherInstanceTest.groovy index 196baab..a78c054 100644 --- a/src/test/groovy/PrivateVariableAccessFromAnotherInstanceTest.groovy +++ b/src/test/groovy/PrivateVariableAccessFromAnotherInstanceTest.groovy @@ -21,27 +21,25 @@ package groovy /** * test to ensure that private instance variables are visible to * other instance variables of the same class - * - * @author <a href="mailto:jeremy.ray...@bigfoot.com">Jeremy Rayner</a> */ -class PrivateVariableAccessFromAnotherInstanceTest extends GroovyTestCase implements Cloneable { +class PrivateVariableAccessFromAnotherInstanceTest extends GroovyTestCase implements Cloneable { def foo private def bar - - public PrivateVariableAccessFromAnotherInstanceTest() { + + PrivateVariableAccessFromAnotherInstanceTest() { super() foo = "foo" bar = "bar" } - - public Object clone() { + + Object clone() { def result = new PrivateVariableAccessFromAnotherInstanceTest() result.foo = foo result.bar = bar return result } - + void testClone() { def fred = new PrivateVariableAccessFromAnotherInstanceTest() diff --git a/src/test/groovy/ProcessTest.groovy b/src/test/groovy/ProcessTest.groovy index fc0670e..0f75a99 100644 --- a/src/test/groovy/ProcessTest.groovy +++ b/src/test/groovy/ProcessTest.groovy @@ -20,63 +20,61 @@ package groovy /** * check that groovy Process methods do their job. - * - * @author <a href="mailto:jeremy.ray...@bigfoot.com">Jeremy Rayner</a> */ - class ProcessTest extends GroovyTestCase { def myProcess - + void setUp() { myProcess = new MockProcess() } - + void testProcessAppendBytes() { def myBytes = "mooky".getBytes() - + myProcess << myBytes - + def result = myProcess.outputStream.toByteArray() assert result != null - assert Arrays.equals(myBytes,result) + assert Arrays.equals(myBytes, result) } + void testProcessAppendTwoByteArrays() { def myBytes1 = "foo".getBytes() def myBytes2 = "bar".getBytes() - + myProcess << myBytes1 << myBytes2 - + def result = myProcess.outputStream.toByteArray() assert result != null - assert result.size() == myBytes1.size() + myBytes2.size() + assert result.size() == myBytes1.size() + myBytes2.size() } - + void testProcessAppend() { myProcess << "mooky" assert "mooky" == myProcess.outputStream.toString() } - + void testProcessInputStream() { assert myProcess.in instanceof InputStream assert myProcess.in != null } - + void testProcessText() { assert "" == myProcess.text } - + void testProcessErrorStream() { assert myProcess.err instanceof InputStream assert myProcess.err != null } - + void testProcessOutputStream() { assert myProcess.out instanceof OutputStream assert myProcess.out != null } - + // @todo - ps.waitForOrKill(secs) creates it's own thread, leave this out of test suite for now... - + void tearDown() { myProcess.destroy() } @@ -89,17 +87,23 @@ class MockProcess extends Process { private def e private def i private def o - - public MockProcess() { + + MockProcess() { e = new AnotherMockInputStream() i = new AnotherMockInputStream() o = new ByteArrayOutputStream() } + void destroy() {} + int exitValue() { return 0 } + InputStream getErrorStream() { return e } - public InputStream getInputStream() { return i } - public OutputStream getOutputStream() { return o } + + InputStream getInputStream() { return i } + + OutputStream getOutputStream() { return o } + int waitFor() { return 0 } } diff --git a/src/test/groovy/Property2Test.groovy b/src/test/groovy/Property2Test.groovy index e098f81..130fb32 100644 --- a/src/test/groovy/Property2Test.groovy +++ b/src/test/groovy/Property2Test.groovy @@ -20,9 +20,6 @@ package groovy /** * Tests the use of getMetaPropertyValues() and getProperties() for Beans and Expandos. - * - * @author john stump - * @author dierk koenig */ class Property2Test extends GroovyTestCase { diff --git a/src/test/groovy/PropertyTest.groovy b/src/test/groovy/PropertyTest.groovy index 59b41e9..2cf74f1 100644 --- a/src/test/groovy/PropertyTest.groovy +++ b/src/test/groovy/PropertyTest.groovy @@ -20,8 +20,6 @@ package groovy /** * Tests the use of properties in Groovy - * - * @author <a href="mailto:ja...@coredevelopers.net">James Strachan</a> */ class PropertyTest extends GroovyTestCase { @@ -66,7 +64,7 @@ class PropertyTest extends GroovyTestCase { // methods should fail on non-existent method calls //shouldFail { foo.blah = 4 } - shouldFail {foo.setBlah(4)} + shouldFail { foo.setBlah(4) } } void testCannotSeePrivateProperties() { @@ -76,7 +74,7 @@ class PropertyTest extends GroovyTestCase { //shouldFail { def x = foo.invisible } //todo: correct handling of access rules // methods should fail on non-existent method calls - shouldFail {foo.getQ()} + shouldFail { foo.getQ() } } void testConstructorWithNamedProperties() { @@ -105,10 +103,10 @@ class PropertyTest extends GroovyTestCase { assert s.length == 10 // this def does not mean there is a getLength() method - shouldFail {i.getLength()} + shouldFail { i.getLength() } // verify we can't set this def, it's read-only - shouldFail {i.length = 6} + shouldFail { i.length = 6 } } void testGstringAssignment() { @@ -184,21 +182,21 @@ class PropertyTest extends GroovyTestCase { c.superThing = 'bar thing' assert c.superthing() == 'bar1bar thing' } - + void testOverwritingNormalProperty() { - def c = new Child(); + def c = new Child() assert c.normalProperty == 2 } //GROOVY-2244 - public void testWriteOnlyBeanProperty() { + void testWriteOnlyBeanProperty() { def bean = new Child() // assert the property exists - assert bean.metaClass.properties.findAll{it.name == 'superThing'} + assert bean.metaClass.properties.findAll { it.name == 'superThing' } // attempt to write to it - bean.superThing= 'x' + bean.superThing = 'x' // attempt to read it shouldFail(MissingPropertyException) { @@ -219,7 +217,7 @@ class PropertyTest extends GroovyTestCase { ''' } - public void testPropertyWithMultipleSetters() { + void testPropertyWithMultipleSetters() { assertScript ''' class A { private field @@ -256,45 +254,56 @@ class Base { protected String field = 'bar' protected thing = 'foo thing' - def getXprop() {'foo x prop'} - def x() {'foo x'} - void setThing(value) {thing = value} - + + def getXprop() { 'foo x prop' } + + def x() { 'foo x' } + + void setThing(value) { thing = value } + //testing final property getter - final getFinalProperty() {1} - + final getFinalProperty() { 1 } + // testing normal property def normalProperty = 1 } class Child extends Base { protected String field = 'foo' + super.field - public getField() {field} - void setSuperField(value) {super.field = value} - public getSuperField() {super.field} + + def getField() { field } + + void setSuperField(value) { super.field = value } + + def getSuperField() { super.field } def thing = 'bar thing' + def superthing() { 'bar1' + super.thing } + def x() { 'bar2' + super.x() } + def getXprop() { 'bar3' + super.xprop } + def getXpropViaMethod() { 'bar4' + super.getXprop() } + def setSuperThing(value) { super.thing = value } - + // testing final property getter // the following property should not add a new getter // method, this would result in a verify error def finalProperty = 32 - + // testing overwriting normal property def normalProperty = 2 } diff --git a/src/test/groovy/ReadLineTest.groovy b/src/test/groovy/ReadLineTest.groovy index dbdca06..4d56367 100644 --- a/src/test/groovy/ReadLineTest.groovy +++ b/src/test/groovy/ReadLineTest.groovy @@ -21,26 +21,24 @@ package groovy /** * Test to ensure that readLine() method works on Reader/InputStream - * - * @author <a href="mailto:jeremy.ray...@bigfoot.com">Jeremy Rayner</a> - * @author Joachim Baumann */ - class ReadLineTest extends GroovyTestCase { def file + void setUp() { file = new File("src/test/groovy/ReadLineTest.groovy") } + void testReadOneLineFromReader() { def line - file.withReader() {line = it.readLine()} + file.withReader() { line = it.readLine() } assert line == "// Do not remove this line: it is used in test below" } - + static testString = " �\n �\n\n �\r\n 5\r\r 7\n\r 9" - static expectedLines = [ " �", " �", "", " �", " 5", "", " 7", "", " 9" ] - static String[] expectedLinesSlow = [ " �", " �", " �", " 5", " 7" ] - static int[] expectedChars = [' ', '9', -1]; + static expectedLines = [" �", " �", "", " �", " 5", "", " 7", "", " 9"] + static String[] expectedLinesSlow = [" �", " �", " �", " 5", " 7"] + static int[] expectedChars = [' ', '9', -1] void readFromReader(Reader reader) throws IOException { expectedLines.each { expected -> @@ -50,12 +48,12 @@ class ReadLineTest extends GroovyTestCase { assertNull("Readline should return null", reader.readLine()) } - public void testBufferedReader() throws IOException { + void testBufferedReader() throws IOException { Reader reader = new BufferedReader(new StringReader(testString)) readFromReader(reader) } - public void testReaderSupportingMark() throws IOException { + void testReaderSupportingMark() throws IOException { Reader reader = new StringReader(testString) readFromReader(reader) } @@ -64,24 +62,27 @@ class ReadLineTest extends GroovyTestCase { * In this case we cannot read more than one line separator * Thus empty lines can be returned if line separation is \r\n. */ - public void testReaderSlow() throws IOException { - Reader reader = new SlowStringReader(testString); + + void testReaderSlow() throws IOException { + Reader reader = new SlowStringReader(testString) expectedLinesSlow.each { expected -> String line = reader.readLine() - while(line != null && line.length() == 0) { + while (line != null && line.length() == 0) { line = reader.readLine() - } - assertEquals("Readline should return correct line", expected, line); + } + assertEquals("Readline should return correct line", expected, line) } - assertEquals("Readline should return empty string", "", reader.readLine()); + assertEquals("Readline should return empty string", "", reader.readLine()) expectedChars.each { expected -> - assertEquals("Remaining characters incorrect", expected, reader.read()) + assertEquals("Remaining characters incorrect", expected, reader.read()) } - assertNull(reader.readLine()); + assertNull(reader.readLine()) } } + class SlowStringReader extends StringReader { - public SlowStringReader(String s) { super(s); } - public boolean markSupported() { return false } + SlowStringReader(String s) { super(s) } + + boolean markSupported() { return false } } diff --git a/src/test/groovy/RegularExpressionsTest.groovy b/src/test/groovy/RegularExpressionsTest.groovy index 817188b..7d5d08a 100644 --- a/src/test/groovy/RegularExpressionsTest.groovy +++ b/src/test/groovy/RegularExpressionsTest.groovy @@ -18,20 +18,12 @@ */ package groovy -/** - * Tests Groovy's regular expression syntax and DGM methods. - * - * @author Sam Pullara - * @author <a href="mailto:ja...@coredevelopers.net">James Strachan</a> - * @author Pilho Kim - * @author Graham Miller - * @author Paul King - * @author Ted Naleid - */ - import java.util.regex.Matcher import java.util.regex.Pattern +/** + * Tests Groovy's regular expression syntax and DGM methods. + */ class RegularExpressionsTest extends GroovyTestCase { void testMatchOperator() { @@ -52,12 +44,16 @@ class RegularExpressionsTest extends GroovyTestCase { assert m instanceof Matcher - while (m) { i = i + 1 } + while (m) { + i = i + 1 + } assert i == 2 i = 0 m = "cheesecheese" =~ "e+" - while (m) { i = i + 1 } + while (m) { + i = i + 1 + } assert i == 4 m.reset() @@ -66,17 +62,17 @@ class RegularExpressionsTest extends GroovyTestCase { m.find() assert m.group() == "ee" } - + // From the javadoc of the getAt() method void testMatcherWithIntIndex() { def p = /ab[d|f]/ def m = "abcabdabeabf" =~ p assert 2 == m.count assert 2 == m.size() // synonym for m.getCount() - assert ! m.hasGroup() + assert !m.hasGroup() assert 0 == m.groupCount() def matches = ["abd", "abf"] - for (i in 0 ..< m.count) { + for (i in 0..<m.count) { assert m[i] == matches[i] } @@ -86,7 +82,7 @@ class RegularExpressionsTest extends GroovyTestCase { assert m.hasGroup() assert 1 == m.groupCount() matches = [["abc", "c"], ["abd", "d"], ["abe", "e"], ["abf", "f"]] - for (i in 0 ..< m.count) { + for (i in 0..<m.count) { assert m[i] == matches[i] } @@ -95,7 +91,7 @@ class RegularExpressionsTest extends GroovyTestCase { assert m.hasGroup() assert 1 == m.groupCount() matches = [["abd", "d"], ["abxyz", "xyz"], ["abx", "x"]] - for (i in 0 ..< m.count) { + for (i in 0..<m.count) { assert m[i] == matches[i] } } @@ -105,20 +101,20 @@ class RegularExpressionsTest extends GroovyTestCase { def matcher = string =~ "e+" assert "ee" == matcher[2] - assert ["ee", "e"] == matcher[2..3] + assert ["ee", "e"] == matcher[2..3] assert ["ee", "ee"] == matcher[0, 2] assert ["ee", "e", "ee"] == matcher[0, 1..2] - + matcher = "cheese please" =~ /([^e]+)e+/ assert ["se", "s"] == matcher[1] assert [["se", "s"], [" ple", " pl"]] == matcher[1, 2] - assert [["se", "s"], [" ple", " pl"]] == matcher[1 .. 2] + assert [["se", "s"], [" ple", " pl"]] == matcher[1..2] assert [["chee", "ch"], [" ple", " pl"], ["ase", "as"]] == matcher[0, 2..3] - + matcher = "cheese please" =~ /([^e]+)e+/ shouldFail { matcher[0, [1, 2]] } } - + void testMatcherIterator() { def matcher = "cheesecheese" =~ "e+" def iter = matcher.iterator() @@ -131,7 +127,7 @@ class RegularExpressionsTest extends GroovyTestCase { assert "ee" == iter.next() assert iter.hasNext() assert "e" == iter.next() - assert ! iter.hasNext() + assert !iter.hasNext() shouldFail(NoSuchElementException.class, { iter.next() }) matcher = "cheese please" =~ /([^e]+)e+/ @@ -145,9 +141,9 @@ class RegularExpressionsTest extends GroovyTestCase { assert [" ple", " pl"] == iter.next() assert iter.hasNext() assert ["ase", "as"] == iter.next() - assert ! iter.hasNext() + assert !iter.hasNext() shouldFail(NoSuchElementException.class, { iter.next() }) - + // collect() uses iterator matcher = "cheesecheese" =~ "e+" assert ["ee", "e", "ee", "e"] == matcher.collect { it } @@ -159,13 +155,13 @@ class RegularExpressionsTest extends GroovyTestCase { void testMatcherEach() { def count = 0 def result = [] - ("cheesecheese" =~ "cheese").each {value -> result += value; count = count + 1} + ("cheesecheese" =~ "cheese").each { value -> result += value; count = count + 1 } assert count == 2 assert result == ['cheese', 'cheese'] count = 0 result = [] - ("cheesecheese" =~ "ee+").each { result += it; count = count + 1} + ("cheesecheese" =~ "ee+").each { result += it; count = count + 1 } assert count == 2 assert result == ['ee', 'ee'] @@ -178,13 +174,13 @@ class RegularExpressionsTest extends GroovyTestCase { } assert ["chee", "se", " ple", "ase"] == resultAll assert ["ch", "s", " pl", "as"] == resultGroup - + matcher = "cheese please" =~ /([^e]+)e+/ result = [] matcher.each { result << it } assert [["chee", "ch"], ["se", "s"], [" ple", " pl"], ["ase", "as"]] == result } - + // Check consistency between each and collect void testMatcherEachVsCollect() { def matcher = "cheese cheese" =~ "e+" @@ -266,13 +262,13 @@ class RegularExpressionsTest extends GroovyTestCase { def BOUNDS = /\b/ def rhyme = /$BOUNDS\w*ain$BOUNDS/ def found = '' - myFairStringy.eachMatch(rhyme) {match -> + myFairStringy.eachMatch(rhyme) { match -> found += match + ' ' } assert found == 'rain Spain plain ' // a second way that is equivalent found = '' - (myFairStringy =~ rhyme).each {match -> + (myFairStringy =~ rhyme).each { match -> found += match + ' ' } assert found == 'rain Spain plain ' @@ -318,7 +314,7 @@ class RegularExpressionsTest extends GroovyTestCase { def result = [] def letters = '' def numbers = '' - string.eachMatch(/([a-z]):(\d)/) {full, group1, group2 -> + string.eachMatch(/([a-z]):(\d)/) { full, group1, group2 -> result += full letters += group1 numbers += group2 @@ -331,7 +327,7 @@ class RegularExpressionsTest extends GroovyTestCase { letters = '' numbers = '' def matcher = string =~ /([a-z]):(\d)/ - matcher.each {match -> + matcher.each { match -> result += match[0] letters += match[1] numbers += match[2] @@ -386,8 +382,12 @@ class RegularExpressionsTest extends GroovyTestCase { } void testReplaceWithClosure() { - assert '1-FISH, two fish' == "one fish, two fish".replaceFirst(~/([a-z]{3})\s([a-z]{4})/) { [one:1, two:2][it[1]] + '-' + it[2].toUpperCase() } - assert '1-FISH, 2-FISH' == "one fish, two fish".replaceAll(~/([a-z]{3})\s([a-z]{4})/) { [one:1, two:2][it[1]] + '-' + it[2].toUpperCase() } + assert '1-FISH, two fish' == "one fish, two fish".replaceFirst(~/([a-z]{3})\s([a-z]{4})/) { + [one: 1, two: 2][it[1]] + '-' + it[2].toUpperCase() + } + assert '1-FISH, 2-FISH' == "one fish, two fish".replaceAll(~/([a-z]{3})\s([a-z]{4})/) { + [one: 1, two: 2][it[1]] + '-' + it[2].toUpperCase() + } } void testNoGroupMatcherAndGet() { @@ -424,7 +424,7 @@ class RegularExpressionsTest extends GroovyTestCase { } assert result == ['0:[abd, d]', '1:[abxyz, xyz]', '2:[abx, x]'] } - + void replaceAllHelper(p, c) { assert 'x12345' == 'x123z45'.replaceAll(p, c) assert '12345' == '12345z'.replaceAll(p, c) @@ -442,7 +442,7 @@ class RegularExpressionsTest extends GroovyTestCase { assert '\\23\\\\45\\' == '\\23\\\\45\\'.replaceAll(p, c) assert '$\\23\\$\\45\\' == '$\\23\\$\\45\\'.replaceAll(p, c) } - + void testReplaceAllClosure() { def p = /([^z]*)(z)/ def c = { all, m, d -> m } @@ -466,7 +466,7 @@ class RegularExpressionsTest extends GroovyTestCase { assert null == 'foo foo baz'.find(p) assert 'bar' == 'foo bar baz'.find(p) assert 'car' == 'car'.find(p) - + def patternWithGroups = /(.)ar/ assert null == ''.find(patternWithGroups) assert 'bar' == 'foo bar baz'.find(patternWithGroups) @@ -481,50 +481,50 @@ class RegularExpressionsTest extends GroovyTestCase { def c = { match -> return "-$match-" } assert null == 'foo foo baz'.find(p, c) assert '-bar-' == 'foo bar baz'.find(p, c) - assert '-car-' == 'car'.find(p, c) + assert '-car-' == 'car'.find(p, c) def compiledPattern = ~p assert null == 'foo foo baz'.find(compiledPattern, c) assert '-bar-' == 'foo bar baz'.find(compiledPattern, c) assert '-car-' == 'car'.find(compiledPattern, c) } - + void testFindClosureWithGroups() { def AREA_CODE = /\d{3}/ def EXCHANGE = /\d{3}/ def STATION_NUMBER = /\d{4}/ def phone = /($AREA_CODE)-($EXCHANGE)-($STATION_NUMBER)/ - def c = { match, areaCode, exchange, stationNumber -> - return "($areaCode) $exchange-$stationNumber" - } - - assert null == 'foo'.find(phone) { match, areaCode, exchange, stationNumber -> return match } - assert "612-555-1212" == 'foo 612-555-1212 bar'.find(phone) { match, areaCode, exchange, stationNumber -> return match } - assert "(612) 555-1212" == 'foo 612-555-1212 bar'.find(phone, c) + def c = { match, areaCode, exchange, stationNumber -> + return "($areaCode) $exchange-$stationNumber" + } + + assert null == 'foo'.find(phone) { match, areaCode, exchange, stationNumber -> return match } + assert "612-555-1212" == 'foo 612-555-1212 bar'.find(phone) { match, areaCode, exchange, stationNumber -> return match } + assert "(612) 555-1212" == 'foo 612-555-1212 bar'.find(phone, c) def compiledPhonePattern = ~phone - assert "(888) 555-1212" == "bar 888-555-1212 foo".find (compiledPhonePattern, c) + assert "(888) 555-1212" == "bar 888-555-1212 foo".find(compiledPhonePattern, c) - def closureSingleVar = { matchArray -> - return "(${matchArray[1]}) ${matchArray[2]}-${matchArray[3]}" + def closureSingleVar = { matchArray -> + return "(${matchArray[1]}) ${matchArray[2]}-${matchArray[3]}" } - - assert "(888) 555-1212" == "bar 888-555-1212 foo".find (compiledPhonePattern, closureSingleVar) - } + + assert "(888) 555-1212" == "bar 888-555-1212 foo".find(compiledPhonePattern, closureSingleVar) + } void testFindAll() { def p = /.at/ def compiledPattern = ~p assert [] == "".findAll(p) assert [] == "".findAll(compiledPattern) - + def orig = "The cat sat on the hat" assert ["cat", "sat", "hat"] == orig.findAll(p) assert ["cat", "sat", "hat"] == orig.findAll(compiledPattern) assert ["+cat", "+sat", "+hat"] == orig.findAll(p) { "+$it" } assert ["+cat", "+sat", "+hat"] == orig.findAll(compiledPattern) { "+$it" } - } + } void testFindAllWithGroups() { def p = /(.)a(.)/ @@ -532,13 +532,13 @@ class RegularExpressionsTest extends GroovyTestCase { def orig = "The cat sat on the hat" assert ["cat", "sat", "hat"] == orig.findAll(p) assert ["cat", "sat", "hat"] == orig.findAll(compiledPattern) - - def c = { match, firstLetter, lastLetter -> return "$firstLetter+$match+$lastLetter" } - assert ["c+cat+t", "s+sat+t", "h+hat+t"] == orig.findAll(p, c) + + def c = { match, firstLetter, lastLetter -> return "$firstLetter+$match+$lastLetter" } + assert ["c+cat+t", "s+sat+t", "h+hat+t"] == orig.findAll(p, c) assert ["c+cat+t", "s+sat+t", "h+hat+t"] == orig.findAll(compiledPattern, c) def closureSingleVar = { matchArray -> return "${matchArray[1]}+${matchArray[0]}+${matchArray[2]}" } - + assert ["c+cat+t", "s+sat+t", "h+hat+t"] == orig.findAll(p, closureSingleVar) assert ["c+cat+t", "s+sat+t", "h+hat+t"] == orig.findAll(compiledPattern, closureSingleVar) } @@ -548,11 +548,11 @@ class RegularExpressionsTest extends GroovyTestCase { def pattern = /\w+@\w+\.\w{2,}/ def useCases = [ - "glafo...@gmail.com" : true, - "glaforge" : true, - "!!!!" : false, - "glaforge@" : true, - "glaforge@@" : false + "glafo...@gmail.com": true, + "glaforge" : true, + "!!!!" : false, + "glaforge@" : true, + "glaforge@@" : false ] useCases.each { String email, boolean bool -> diff --git a/src/test/groovy/ReturnTest.groovy b/src/test/groovy/ReturnTest.groovy index c0e4358..9d1c385 100644 --- a/src/test/groovy/ReturnTest.groovy +++ b/src/test/groovy/ReturnTest.groovy @@ -18,10 +18,8 @@ */ package groovy -/** +/** * Tests the use of returns in Groovy - * - * @author <a href="mailto:ja...@coredevelopers.net">James Strachan</a> */ class ReturnTest extends GroovyTestCase { void testIntegerReturnValues() { @@ -35,13 +33,13 @@ class ReturnTest extends GroovyTestCase { } def foo(x) { - return ( x * 2 ) + return (x * 2) } def bar(x) { return x > 5 } - + void testVoidReturn() { explicitVoidReturn() implicitVoidReturn() @@ -58,13 +56,13 @@ class ReturnTest extends GroovyTestCase { } void explicitVoidReturnWithoutFinalReturn() { - def x = 4; + def x = 4 if (x == 3) { - return; + return } else { try { - x = 3; - return; + x = 3 + return } finally { //do nothing } @@ -72,16 +70,16 @@ class ReturnTest extends GroovyTestCase { } def implicitVoidReturnWithoutFinalReturn() { - def x = 4; + def x = 4 if (x == 3) { - return; + return } else { try { - x = 3; - return; + x = 3 + return } finally { //do nothing } } - } + } } diff --git a/src/test/groovy/SocketTest.groovy b/src/test/groovy/SocketTest.groovy index 209c0c0..a426188 100644 --- a/src/test/groovy/SocketTest.groovy +++ b/src/test/groovy/SocketTest.groovy @@ -20,8 +20,6 @@ package groovy /** * check that groovy Socket methods do their job. - * - * @author <a href="mailto:jeremy.ray...@bigfoot.com">Jeremy Rayner</a> */ class SocketTest extends GroovyTestCase { def mySocket @@ -53,7 +51,7 @@ class SocketTest extends GroovyTestCase { } void testSocketWithStreamsClosure() { - mySocket.withStreams {i, o -> + mySocket.withStreams { i, o -> assert i instanceof InputStream assert i != null assert o instanceof OutputStream diff --git a/src/test/groovy/SortTest.groovy b/src/test/groovy/SortTest.groovy index 2aade57..90962b9 100644 --- a/src/test/groovy/SortTest.groovy +++ b/src/test/groovy/SortTest.groovy @@ -18,9 +18,6 @@ */ package groovy -/** - * @author <a href="mailto:ja...@coredevelopers.net">James Strachan</a> - */ class SortTest extends GroovyTestCase { // GROOVY-1956 @@ -42,21 +39,21 @@ class SortTest extends GroovyTestCase { // GROOVY-1956 void testSortWithNullUsingOrderBy() { def x = [1, 2, 'Z', 'a', null] - def y = x.sort() + def y = x.sort() assert y == [null, 1, 2, 'Z', 'a'] - def z = x.sort{ it?.respondsTo('toUpperCase') ? it?.toUpperCase() : it } + def z = x.sort { it?.respondsTo('toUpperCase') ? it?.toUpperCase() : it } assert z == [null, 1, 2, 'a', 'Z'] } void testSortWithOrderBy() { def list = getPeople() - def order = new OrderBy( { it.cheese } ) - list.sort(true,order) + def order = new OrderBy({ it.cheese }) + list.sort(true, order) assert list[0].name == 'Joe' assert list[-1].name == 'Chris' assert list.name == ['Joe', 'Bob', 'James', 'Chris'] } - + void testSortWithClosure() { def list = getPeople() list.sort { it.cheese } @@ -69,7 +66,9 @@ class SortTest extends GroovyTestCase { assert words.sort() == ['The', 'brown', 'dog', 'fox', 'jumped', 'lazy', 'over', 'quick', 'the'] as String[] assert words.sort(new IgnoreCaseComparator()) == ['brown', 'dog', 'fox', 'jumped', 'lazy', 'over', 'quick', 'The', 'the'] as String[] words = s.split() // back to a known order - assert words.sort{ it.size() } == ['The', 'fox', 'the', 'dog', 'over', 'lazy', 'quick', 'brown', 'jumped'] as String[] + assert words.sort { + it.size() + } == ['The', 'fox', 'the', 'dog', 'over', 'lazy', 'quick', 'brown', 'jumped'] as String[] } void testSortClassHierarchy() { @@ -78,18 +77,18 @@ class SortTest extends GroovyTestCase { new AFoo(7), new ABar(4), new ABar(6) - ] + ] def sorted = aFooList.sort() - assert sorted.collect{ it.class } == [ABar, AFoo, ABar, AFoo] - assert sorted.collect{ it.key } == (4..7).toList() + assert sorted.collect { it.class } == [ABar, AFoo, ABar, AFoo] + assert sorted.collect { it.key } == (4..7).toList() } def getPeople() { def answer = [] - answer << new Expando(name:'James', cheese:'Edam', location:'London') - answer << new Expando(name:'Bob', cheese:'Cheddar', location:'Atlanta') - answer << new Expando(name:'Chris', cheese:'Red Leicester', location:'London') - answer << new Expando(name:'Joe', cheese:'Brie', location:'London') + answer << new Expando(name: 'James', cheese: 'Edam', location: 'London') + answer << new Expando(name: 'Bob', cheese: 'Cheddar', location: 'Atlanta') + answer << new Expando(name: 'Chris', cheese: 'Red Leicester', location: 'London') + answer << new Expando(name: 'Joe', cheese: 'Brie', location: 'London') return answer } @@ -97,17 +96,20 @@ class SortTest extends GroovyTestCase { class AFoo implements Comparable { int key + AFoo(int key) { this.key = key } + int compareTo(Object rhs) { key - rhs.key } + String toString() { this.class.name + ": " + key } } class ABar extends AFoo { - public ABar(int x) {super(x)} + ABar(int x) { super(x) } } class IgnoreCaseComparator implements Comparator { - public int compare(Object o1, Object o2) { + int compare(Object o1, Object o2) { return o1.toUpperCase() <=> o2.toUpperCase() } } diff --git a/src/test/groovy/SpreadDotTest.groovy b/src/test/groovy/SpreadDotTest.groovy index 3edd010..7f0c6a9 100644 --- a/src/test/groovy/SpreadDotTest.groovy +++ b/src/test/groovy/SpreadDotTest.groovy @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - package groovy +package groovy /** * Test for the spread dot operator "*.". @@ -25,16 +25,13 @@ * list*.property * means * list.collect { it?.property } - * - * @author Pilho Kim - * @author Paul King */ -public class SpreadDotTest extends GroovyTestCase { +class SpreadDotTest extends GroovyTestCase { void testSpreadDot() { - def m1 = ["a":1, "b":2] - def m2 = ["a":11, "b":22] - def m3 = ["a":111, "b":222] - def x = [m1,m2,m3] + def m1 = ["a": 1, "b": 2] + def m2 = ["a": 11, "b": 22] + def m3 = ["a": 111, "b": 222] + def x = [m1, m2, m3] assert x*.a == [1, 11, 111] assert x*."a" == [1, 11, 111] assert x == [m1, m2, m3] @@ -66,7 +63,7 @@ public class SpreadDotTest extends GroovyTestCase { def x = [a, b] assert x*.fnB("1") == [a.fnB("1"), b.fnB("1")] - assert [a,b]*.fnB() == [a.fnB(), b.fnB()] + assert [a, b]*.fnB() == [a.fnB(), b.fnB()] } void testSpreadDotArrays() { @@ -75,7 +72,7 @@ public class SpreadDotTest extends GroovyTestCase { Object[] x = [a, b] assert x*.fnB("1") == [a.fnB("1"), b.fnB("1")] - assert [a,b]*.fnB() == [a.fnB(), b.fnB()] + assert [a, b]*.fnB() == [a.fnB(), b.fnB()] int[] nums = [3, 4, 5] assert nums*.toString() == ['3', '4', '5'] @@ -87,36 +84,36 @@ public class SpreadDotTest extends GroovyTestCase { assert pets*.length() == nums } - void testSpreadDotOnArrays2 () { + void testSpreadDotOnArrays2() { def books = [Book1, Book2, Book3] as Object[] books*.metaClass*.foo = { "Hello, ${delegate.class.name}" } - assertEquals "Hello, groovy.Book1", new Book1 ().foo () - assertEquals "Hello, groovy.Book2", new Book2 ().foo () - assertEquals "Hello, groovy.Book3", new Book3 ().foo () + assertEquals "Hello, groovy.Book1", new Book1().foo() + assertEquals "Hello, groovy.Book2", new Book2().foo() + assertEquals "Hello, groovy.Book3", new Book3().foo() } - + void testSpreadDotAdvanced() { - assertEquals ([3, 3], ['cat', 'dog']*.size()) - assertEquals ([3, 3], (['cat', 'dog'] as Vector)*.size()) - assertEquals ([3, 3], (['cat', 'dog'] as String[])*.size()) - assertEquals ([3, 3], (['cat', 'dog'] as Vector).elements()*.size()) - assertEquals ([1, 1, 1], 'zoo'*.size()) - assertEquals (Object, new Object().getClass()) - assertEquals ([Object], new Object()*.getClass()) - assertEquals ('Large', new Shirt().size()) - assertEquals (['Large'], new Shirt()*.size()) + assertEquals([3, 3], ['cat', 'dog']*.size()) + assertEquals([3, 3], (['cat', 'dog'] as Vector)*.size()) + assertEquals([3, 3], (['cat', 'dog'] as String[])*.size()) + assertEquals([3, 3], (['cat', 'dog'] as Vector).elements()*.size()) + assertEquals([1, 1, 1], 'zoo'*.size()) + assertEquals(Object, new Object().getClass()) + assertEquals([Object], new Object()*.getClass()) + assertEquals('Large', new Shirt().size()) + assertEquals(['Large'], new Shirt()*.size()) } - void testSpreadDotMap () { - def map = [A:"one", B:"two", C:"three"] - assert map.collect { child -> child.value.size() } == [3, 3, 5] + void testSpreadDotMap() { + def map = [A: "one", B: "two", C: "three"] + assert map.collect { child -> child.value.size() } == [3, 3, 5] assert map*.value*.size() == [3, 3, 5] assert map*.getKey() == ['A', 'B', 'C'] } - public void testSpreadDotAttribute() { + void testSpreadDotAttribute() { def s = new Singlet() assert s.size == 1 assert s.@size == 12 @@ -126,60 +123,68 @@ public class SpreadDotTest extends GroovyTestCase { } void testNewLine() { - def x = [ a:1, b:2 ] + def x = [a: 1, b: 2] def y = x - *.value - *.toString() - assert y == [ '1', '2' ] + *.value + *.toString() + assert y == ['1', '2'] def z = x - *.value - .sum() + *.value + .sum() assert z == 3 - x = [ new Singlet(), new Singlet() ] + x = [new Singlet(), new Singlet()] y = x - *.@size - assert y == [ 12, 12 ] + *.@size + assert y == [12, 12] } } class SpreadDotDemo { - public java.util.Date getA() { + java.util.Date getA() { return new Date() } - public String fnB() { + + String fnB() { return "bb" } - public String fnB(String m) { + + String fnB(String m) { return "BB$m" } } class SpreadDotDemo2 { - public String getAttribute(String key) { + String getAttribute(String key) { return "Attribute $key" } - public String get(String key) { + + String get(String key) { return getAttribute("Get $key") } - public String fnB() { + + String fnB() { return "cc" } - public String fnB(String m) { + + String fnB(String m) { return "CC$m" } } class Book1 {} + class Book2 {} + class Book3 {} class Shirt { - def size() { 'Large' } + def size() { 'Large' } } class Singlet { private size = 12 - def getSize() {1} + + def getSize() { 1 } } diff --git a/src/test/groovy/SwitchWithDifferentTypesTest.groovy b/src/test/groovy/SwitchWithDifferentTypesTest.groovy index 51c8306..e1968b8 100644 --- a/src/test/groovy/SwitchWithDifferentTypesTest.groovy +++ b/src/test/groovy/SwitchWithDifferentTypesTest.groovy @@ -18,10 +18,8 @@ */ package groovy -/** +/** * A test case for switch statement with different types - * - * @author <a href="mailto:ja...@coredevelopers.net">James Strachan</a> */ class SwitchWithDifferentTypesTest extends GroovyTestCase { @@ -32,7 +30,7 @@ class SwitchWithDifferentTypesTest extends GroovyTestCase { void testSwitchWithDoubleValues() { assertSwitch(1.5, 2.4, 3.2, 4.1) } - + void testSwitchWithStringValues() { assertSwitch("abc", "def", "xyz", "unknown") } @@ -59,29 +57,29 @@ class SwitchWithDifferentTypesTest extends GroovyTestCase { assertSwitchMixed(bd2, bi, 2, 3) assertSwitchMixed(bd2, bd1, 2, 3) } - + void assertSwitchMixed(switchValue, matchingValue, nonmatchingValue1, nonmatchingValue2) { - assertSwitchMatch1(switchValue, matchingValue, nonmatchingValue1, nonmatchingValue2) - assertSwitchMatch2(switchValue, nonmatchingValue1, matchingValue, nonmatchingValue2) - assertSwitchMatch3(switchValue, nonmatchingValue1, nonmatchingValue2, matchingValue) + assertSwitchMatch1(switchValue, matchingValue, nonmatchingValue1, nonmatchingValue2) + assertSwitchMatch2(switchValue, nonmatchingValue1, matchingValue, nonmatchingValue2) + assertSwitchMatch3(switchValue, nonmatchingValue1, nonmatchingValue2, matchingValue) } - + void assertSwitch(a, b, c, d) { assertSwitchMatch1(a, a, b, c) assertSwitchMatch2(b, a, b, c) assertSwitchMatch3(c, a, b, c) assertSwitchMatchDefault(d, a, b, c) } - + void assertSwitchMatch1(value, case1Value, case2Value, case3Value) { switch (value) { - case case1Value: + case case1Value: // worked break - case case2Value: + case case2Value: failNotEquals(value, case2Value) break - case case3Value: + case case3Value: failNotEquals(value, case3Value) break default: @@ -92,13 +90,13 @@ class SwitchWithDifferentTypesTest extends GroovyTestCase { void assertSwitchMatch2(value, case1Value, case2Value, case3Value) { switch (value) { - case case1Value: + case case1Value: failNotEquals(value, case1Value) break - case case2Value: + case case2Value: // worked break - case case3Value: + case case3Value: failNotEquals(value, case3Value) break default: @@ -106,16 +104,16 @@ class SwitchWithDifferentTypesTest extends GroovyTestCase { break } } - + void assertSwitchMatch3(value, case1Value, case2Value, case3Value) { switch (value) { - case case1Value: + case case1Value: failNotEquals(value, case1Value) break - case case2Value: + case case2Value: failNotEquals(value, case2Value) break - case case3Value: + case case3Value: // worked break default: @@ -123,16 +121,16 @@ class SwitchWithDifferentTypesTest extends GroovyTestCase { break } } - + void assertSwitchMatchDefault(value, case1Value, case2Value, case3Value) { switch (value) { - case case1Value: + case case1Value: failNotEquals(value, case1Value) break - case case2Value: + case case2Value: failNotEquals(value, case2Value) break - case case3Value: + case case3Value: failNotEquals(value, case3Value) break default: @@ -146,6 +144,6 @@ class SwitchWithDifferentTypesTest extends GroovyTestCase { } void failNotDefault(value) { - fail("value: " + value + " should not match the default switch clause" ) + fail("value: " + value + " should not match the default switch clause") } } diff --git a/src/test/groovy/TextPropertyTest.groovy b/src/test/groovy/TextPropertyTest.groovy index 49d9476..3f307de 100644 --- a/src/test/groovy/TextPropertyTest.groovy +++ b/src/test/groovy/TextPropertyTest.groovy @@ -17,6 +17,7 @@ * under the License. */ package groovy + /** * check that text def is available on... * @@ -26,33 +27,30 @@ package groovy * myReader.text, * myBufferedReader.text, * myProcess.text - * - * @author <a href="mailto:jeremy.ray...@bigfoot.com">Jeremy Rayner</a> */ - class TextPropertyTest extends GroovyTestCase { def myReader def myInputStream def myBigEndianEncodedInputStream - + void setUp() { myReader = new StringReader("digestive") myInputStream = new ByteArrayInputStream("chocolate chip".bytes) myBigEndianEncodedInputStream = new ByteArrayInputStream("shortbread".getBytes("UTF-16BE")) } - + void testBigEndianEncodedInputStreamText() { assert "shortbread" == myBigEndianEncodedInputStream.getText("UTF-16BE") } - + void testInputStreamText() { assert "chocolate chip" == myInputStream.text } - + void testReaderText() { assert "digestive" == myReader.text } - + void tearDown() { myInputStream = null myReader = null diff --git a/src/test/groovy/UniqueOnCollectionWithClosureTest.groovy b/src/test/groovy/UniqueOnCollectionWithClosureTest.groovy index 7cc3138..ea7b4d5 100644 --- a/src/test/groovy/UniqueOnCollectionWithClosureTest.groovy +++ b/src/test/groovy/UniqueOnCollectionWithClosureTest.groovy @@ -18,16 +18,11 @@ */ package groovy -/** - * @author Michael Baehr - * @author Paul King - * @author Tim Yates - */ class UniqueOnCollectionWithClosureTest extends GroovyTestCase { void testUniqueOnIterator() { def list = [-1, 0, 1, 1, 0, -1] - def closure = {a, b -> Math.abs(a) <=> Math.abs(b)} + def closure = { a, b -> Math.abs(a) <=> Math.abs(b) } def it = list.iterator().unique(closure) assert it instanceof Iterator def result = it.toList() @@ -37,21 +32,21 @@ class UniqueOnCollectionWithClosureTest extends GroovyTestCase { /** GROOVY-3213 */ void testUniqueWithTwoParameterClosureOnSet() { def set = [-1, 0, 1] as Set - def closure = {a, b -> Math.abs(a) <=> Math.abs(b)} + def closure = { a, b -> Math.abs(a) <=> Math.abs(b) } assert set.unique(closure).size() == 2 } /** GROOVY-1236 */ void testUniqueWithTwoParameterClosure() { def list = [-1, 0, 1, 1, 0, -1] - def closure = {a, b -> Math.abs(a) <=> Math.abs(b)} + def closure = { a, b -> Math.abs(a) <=> Math.abs(b) } assert list.unique(closure) == [-1, 0] } /** GROOVY-1236 */ void testUniqueWithOneParameterClosure() { def list = [-1, 0, 1, 1, 0, -1] - def closure = {a -> Math.abs(a)} + def closure = { a -> Math.abs(a) } assert list.unique(closure) == [-1, 0] } @@ -66,7 +61,7 @@ class UniqueOnCollectionWithClosureTest extends GroovyTestCase { /** GROOVY-4742 */ void testImmutableCollectionWithTwoParamClosure() { def orig = [2, 3, 3, 4] - def uniq = orig.unique( false ) { a, b -> a <=> b } + def uniq = orig.unique(false) { a, b -> a <=> b } assert orig == [2, 3, 3, 4] assert uniq == [2, 3, 4] } diff --git a/src/test/groovy/UniqueOnCollectionWithComparatorTest.groovy b/src/test/groovy/UniqueOnCollectionWithComparatorTest.groovy index beb8190..f8b5eed 100644 --- a/src/test/groovy/UniqueOnCollectionWithComparatorTest.groovy +++ b/src/test/groovy/UniqueOnCollectionWithComparatorTest.groovy @@ -1,80 +1,75 @@ -/* - * 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 - -/** - * @author Michael Baehr - * @author Paul King - * @author Tim Yates - */ -class UniqueOnCollectionWithComparatorTest extends GroovyTestCase { - - void testUniqueOnIterator() { - def list = [-1, 0, 1, 1, 0, -1] - def comparator = new ClosureComparator({a, b -> Math.abs(a) <=> Math.abs(b)}) - def it = list.iterator().unique(comparator) - assert it instanceof Iterator - def result = it.toList() - assert result == [-1, 0] - } - - void testUniqueWithComparatorList() { - def list = [-1, 0, 1, 1, 0, -1] - def comparator = new ClosureComparator({a, b -> Math.abs(a) <=> Math.abs(b)}) - assert list.unique(comparator) == [-1, 0] - } - - void testUniqueWithComparatorSet() { - def set = [-1, 0, 1] as Set - def comparator = new ClosureComparator({a, b -> Math.abs(a) <=> Math.abs(b)}) - assert set.unique(comparator).size() == 2 - } - - /** GROOVY-4742 */ - void testImmutableUniqueWithComparatorList() { - def list = [-1, 0, 1, 1, 0, -1] - def comparator = new ClosureComparator({a, b -> Math.abs(a) <=> Math.abs(b)}) - def result = list.unique(false, comparator) - assert result == [-1, 0] - assert list == [-1, 0, 1, 1, 0, -1] - } - - /** GROOVY-4742 */ - void testImmutableUniqueWithComparatorSet() { - def set = [-1, 0, 1] as Set - def comparator = new ClosureComparator({a, b -> Math.abs(a) <=> Math.abs(b)}) - def result = set.unique(false, comparator).size() - assert result == 2 - assert set == [-1, 0, 1] as Set - } - - /** GROOVY-4742 */ - void testImmutableUniqueWithComparator() { - def comparator = [ compare:{ p1, p2 -> p1.lname <=> p2.lname ?: p1.fname <=> p2.fname } ] as Comparator - - def a = [fname:"John", lname:"Taylor"] - def b = [fname:"Clark", lname:"Taylor"] - def c = [fname:"Tom", lname:"Cruz"] - def d = [fname:"Clark", lname:"Taylor"] - - def list = [a, b, c, d] - List list2 = list.unique(false, comparator) - assert( list2 != list && list2 == [a, b, c] ) - } +/* + * 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 + +class UniqueOnCollectionWithComparatorTest extends GroovyTestCase { + + void testUniqueOnIterator() { + def list = [-1, 0, 1, 1, 0, -1] + def comparator = new ClosureComparator({ a, b -> Math.abs(a) <=> Math.abs(b) }) + def it = list.iterator().unique(comparator) + assert it instanceof Iterator + def result = it.toList() + assert result == [-1, 0] + } + + void testUniqueWithComparatorList() { + def list = [-1, 0, 1, 1, 0, -1] + def comparator = new ClosureComparator({ a, b -> Math.abs(a) <=> Math.abs(b) }) + assert list.unique(comparator) == [-1, 0] + } + + void testUniqueWithComparatorSet() { + def set = [-1, 0, 1] as Set + def comparator = new ClosureComparator({ a, b -> Math.abs(a) <=> Math.abs(b) }) + assert set.unique(comparator).size() == 2 + } + + /** GROOVY-4742 */ + void testImmutableUniqueWithComparatorList() { + def list = [-1, 0, 1, 1, 0, -1] + def comparator = new ClosureComparator({ a, b -> Math.abs(a) <=> Math.abs(b) }) + def result = list.unique(false, comparator) + assert result == [-1, 0] + assert list == [-1, 0, 1, 1, 0, -1] + } + + /** GROOVY-4742 */ + void testImmutableUniqueWithComparatorSet() { + def set = [-1, 0, 1] as Set + def comparator = new ClosureComparator({ a, b -> Math.abs(a) <=> Math.abs(b) }) + def result = set.unique(false, comparator).size() + assert result == 2 + assert set == [-1, 0, 1] as Set + } + + /** GROOVY-4742 */ + void testImmutableUniqueWithComparator() { + def comparator = [compare: { p1, p2 -> p1.lname <=> p2.lname ?: p1.fname <=> p2.fname }] as Comparator + + def a = [fname: "John", lname: "Taylor"] + def b = [fname: "Clark", lname: "Taylor"] + def c = [fname: "Tom", lname: "Cruz"] + def d = [fname: "Clark", lname: "Taylor"] + + def list = [a, b, c, d] + List list2 = list.unique(false, comparator) + assert (list2 != list && list2 == [a, b, c]) + } } \ No newline at end of file diff --git a/src/test/groovy/VarargsMethodTest.groovy b/src/test/groovy/VarargsMethodTest.groovy index c3ea6ec..b3a2d1a 100644 --- a/src/test/groovy/VarargsMethodTest.groovy +++ b/src/test/groovy/VarargsMethodTest.groovy @@ -18,27 +18,22 @@ */ package groovy -/** +/** * VarargsMethodTest.groovy * * 1) Test to fix the Jira issues GROOVY-1023 and GROOVY-1026. * 2) Test the feature that the length of arguments can be variable * when invoking methods with or without parameters. - * - * @author Dierk Koenig - * @author Pilho Kim - * @author Hein Meling */ - -class VarargsMethodTest extends GroovyTestCase { +class VarargsMethodTest extends GroovyTestCase { void testVarargsOnly() { - assertEquals 1, varargsOnlyMethod('') - assertEquals 1, varargsOnlyMethod(1) - assertEquals 2, varargsOnlyMethod('','') - assertEquals 1, varargsOnlyMethod( ['',''] ) - assertEquals 2, varargsOnlyMethod( ['',''] as Object[]) - assertEquals 2, varargsOnlyMethod( *['',''] ) + assertEquals 1, varargsOnlyMethod('') + assertEquals 1, varargsOnlyMethod(1) + assertEquals 2, varargsOnlyMethod('','') + assertEquals 1, varargsOnlyMethod( ['',''] ) + assertEquals 2, varargsOnlyMethod( ['',''] as Object[]) + assertEquals 2, varargsOnlyMethod( *['',''] ) // GROOVY-1023 assertEquals 0, varargsOnlyMethod() @@ -46,9 +41,9 @@ class VarargsMethodTest extends GroovyTestCase { // GROOVY-1026 assertEquals(-1, varargsOnlyMethod(null)) assertEquals(2, varargsOnlyMethod(null, null)) - } + } - Integer varargsOnlyMethod(Object[] args) { + Integer varargsOnlyMethod(Object[] args) { // GROOVY-1023 (Java 5 feature) // If this method having varargs is invoked with no parameter, // then args is not null, but an array of length 0. @@ -57,29 +52,29 @@ class VarargsMethodTest extends GroovyTestCase { // null, then args is null, and so -1 is returned here. if (args == null) return -1 - return args.size() - } - - void testVarargsLast() { - assertEquals 0, varargsLastMethod('') - assertEquals 0, varargsLastMethod(1) - assertEquals 1, varargsLastMethod('','') - assertEquals 2, varargsLastMethod('','','') - assertEquals 1, varargsLastMethod('', ['',''] ) - assertEquals 2, varargsLastMethod('', ['',''] as Object[]) - assertEquals 2, varargsLastMethod('', *['',''] ) + return args.size() + } - // GROOVY-1026 - assertEquals(-1, varargsLastMethod('',null)) - assertEquals(2, varargsLastMethod('',null, null)) - } - - Integer varargsLastMethod(Object first, Object[] args) { - // GROOVY-1026 (Java 5 feature) - // If this method having varargs is invoked with two parameters - // 1 and null, then args is null, and so -1 is returned here. - if (args == null) - return -1 - return args.size() - } + void testVarargsLast() { + assertEquals 0, varargsLastMethod('') + assertEquals 0, varargsLastMethod(1) + assertEquals 1, varargsLastMethod('','') + assertEquals 2, varargsLastMethod('','','') + assertEquals 1, varargsLastMethod('', ['',''] ) + assertEquals 2, varargsLastMethod('', ['',''] as Object[]) + assertEquals 2, varargsLastMethod('', *['',''] ) + + // GROOVY-1026 + assertEquals(-1, varargsLastMethod('', null)) + assertEquals(2, varargsLastMethod('', null, null)) + } + + Integer varargsLastMethod(Object first, Object[] args) { + // GROOVY-1026 (Java 5 feature) + // If this method having varargs is invoked with two parameters + // 1 and null, then args is null, and so -1 is returned here. + if (args == null) + return -1 + return args.size() + } } diff --git a/src/test/groovy/annotations/MyIntegerAnno.groovy b/src/test/groovy/annotations/MyIntegerAnno.groovy index f182d34..db1a56a 100644 --- a/src/test/groovy/annotations/MyIntegerAnno.groovy +++ b/src/test/groovy/annotations/MyIntegerAnno.groovy @@ -1,36 +1,33 @@ -/* - * 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.annotations - -import java.lang.annotation.* - -import static java.lang.annotation.RetentionPolicy.* -import org.codehaus.groovy.transform.GroovyASTTransformationClass - -/** - * Test annotation - * - * @author Paul King - */ - -@Retention(RUNTIME) -@GroovyASTTransformationClass("groovy.annotations.MyIntegerAnnoTraceASTTransformation") -public @interface MyIntegerAnno { - int value() -} +/* + * 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.annotations + +import java.lang.annotation.* + +import static java.lang.annotation.RetentionPolicy.* +import org.codehaus.groovy.transform.GroovyASTTransformationClass + +/** + * Test annotation + */ +@Retention(RUNTIME) +@GroovyASTTransformationClass("groovy.annotations.MyIntegerAnnoTraceASTTransformation") +@interface MyIntegerAnno { + int value() +} diff --git a/src/test/groovy/beans/BindableTest.groovy b/src/test/groovy/beans/BindableTest.groovy index ca6a1aa..1b88758 100644 --- a/src/test/groovy/beans/BindableTest.groovy +++ b/src/test/groovy/beans/BindableTest.groovy @@ -1,375 +1,372 @@ -/* - * 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.beans - -import org.codehaus.groovy.control.CompilationFailedException - -import java.beans.PropertyChangeListener - -import static java.lang.reflect.Modifier.isPublic -import static java.lang.reflect.Modifier.isSynthetic - -/** - * @author Danno Ferrin (shemnon) - */ -class BindableTest extends GroovyTestCase { - - void testSimpleBindableProperty() { - assertScript """ - import groovy.beans.Bindable - - class BindableTestBean1 { - @Bindable String name - } - - sb = new BindableTestBean1() - sb.name = "bar" - changed = false - sb.propertyChange = {changed = true} - sb.name = "foo" - assert changed - """ - } - - void testMultipleBindableProperty() { - assertScript """ - import groovy.beans.Bindable - - class BindableTestBean2 { - @Bindable String name - @Bindable String value - } - - sb = new BindableTestBean2(name:"foo", value:"bar") - changed = 0 - sb.propertyChange = {changed++} - sb.name = "baz" - sb.value = "biff" - assert changed == 2 - """ - } - - void testMutatingSetter() { - assertScript """ - class BindableTestBean3 { - @groovy.beans.Bindable String name - void setName(String newName) { - this.@name = "x\$newName" - } - } - sb = new BindableTestBean3(name:"foo") - changed = 0 - sb.propertyChange = {evt -> - assert evt.newValue =~ '^x' - changed++ - } - sb.name = "baz" - assert changed == 1 - """ - } - - void testWithSettersAndGetters() { - for (int i = 0; i < 16; i++) { - boolean bindClass = i & 1 - boolean field = i & 2 - boolean setter = i & 4 - boolean getter = i & 8 - int expectedCount = (bindClass && !field)?2:1 - String script = """ - import groovy.beans.Bindable - - ${bindClass?'@Bindable ':''}class BindableTestSettersAndGetters$i { - - @Bindable String alwaysBound - ${field?'protected ':''} String name - - ${setter?'':'//'}void setName(String newName) { this.@name = "x\$newName" } - ${getter?'':'//'}String getName() { return this.@name } - } - sb = new BindableTestSettersAndGetters$i(name:"foo", alwaysBound:"bar") - changed = 0 - sb.propertyChange = {evt -> - changed++ - } - sb.alwaysBound = "baz" - sb.name = "bif" - sb.name = "bif" - assert changed == $expectedCount - """ - try { - GroovyShell shell = new GroovyShell() - shell.evaluate(script); - } catch (Throwable t) { - System.out.println("Failed Script: $script") - throw t - } - } - } - - void testOnField() { - GroovyShell shell = new GroovyShell() - shouldFail(CompilationFailedException) { - shell.evaluate(""" - class BindableTestBean4 { - public @groovy.beans.Bindable String name - } - """) - } - } - - void testOnStaticField() { - GroovyShell shell = new GroovyShell() - shouldFail(CompilationFailedException) { - shell.evaluate(""" - class BindableTestBean5 { - @groovy.beans.Bindable static String name - } - """) - } - } - - void testClassMarkers() { - for (int i = 0; i < 7; i++) { - boolean bindField = i & 1 - boolean bindClass = i & 2 - boolean staticField = i & 4 - int bindCount = bindClass?(staticField?2:3):(bindField?1:0); - - String script = """ - import groovy.beans.Bindable - - ${bindClass?'@Bindable ':''}class ClassMarkerBindable$i { - String neither - - ${bindField?'@Bindable ':''}String bind - - ${staticField?'static ':''}String staticString - } - - cb = new ClassMarkerBindable$i(neither:'a', bind:'b', staticString:'c') - bindCount = 0 - ${bindClass|bindField?'cb.propertyChange = { bindCount++ }':''} - cb.neither = 'd' - cb.bind = 'e' - cb.staticString = 'f' - assert bindCount == $bindCount - """ - try { - GroovyShell shell = new GroovyShell() - shell.evaluate(script); - } catch (Throwable t) { - System.out.println("Failed Script: $script") - throw t - } - } - } - - void testPrimitiveTypes() { - assertScript """ - import groovy.beans.Bindable - - class BindableTestBean7 { - @Bindable String testField - @Bindable boolean testBoolean - @Bindable byte testByte - @Bindable short testShort - @Bindable int testInt - @Bindable long testLong - @Bindable float testFloat - @Bindable double testDouble - } - - sb = new BindableTestBean7() - sb.testField = "bar" - int changed = 0 - sb.propertyChange = {changed++} - sb.testField = "foo" - sb.testBoolean = true - sb.testByte = 1 - sb.testShort = 1 - sb.testInt = 1 - sb.testLong = 1 - sb.testFloat = 1 - sb.testDouble = 1 - assert changed == 8 - """ - } - - void testBadInheritance() { - shouldFail(CompilationFailedException) { - GroovyShell shell = new GroovyShell() - shell.evaluate(""" - import groovy.beans.Bindable - - class BindableTestBean8 { - @Bindable String testField - void addPropertyChangeListener(java.beans.PropertyChangeListener l) {} - } - new BindableTestBean8() - """) - } - shouldFail(CompilationFailedException) { - GroovyShell shell = new GroovyShell() - shell.evaluate(""" - import groovy.beans.Bindable - - class BindableTestBean9 { - void addPropertyChangeListener(java.beans.PropertyChangeListener l) {} - } - - class BindableTestBean10 extends BindableTestBean9 { - @Bindable String testField - } - - new BindableTestBean10() - """) - } - } - - void testBindableParent() { - assertScript """ - import groovy.beans.Bindable - import java.beans.PropertyChangeEvent - import java.beans.PropertyChangeListener - - @Bindable - class BindableTestBeanChild extends BindableTestBeanParent { - String prop2 - BindableTestBeanChild() { - super() - } - } - - @Bindable - class BindableTestBeanParent implements PropertyChangeListener { - String prop1 - BindableTestBeanParent() { - addPropertyChangeListener(this) - } - - void propertyChange(PropertyChangeEvent event) {} - } - - new BindableTestBeanChild() - """ - } - - void testFinalProperty() { - shouldFail(CompilationFailedException) { - GroovyShell shell = new GroovyShell() - shell.evaluate(""" - import groovy.beans.Bindable - - class BindableTestBean11 { - @Bindable final String testField - } - 1+1 - """) - } - } - - void testOnClassFinalProperty() { - shouldFail(ReadOnlyPropertyException) { - GroovyShell shell = new GroovyShell() - shell.evaluate(""" - import groovy.beans.Bindable - - @Bindable class BindableTestBean12 { - String testField - final String anotherTestField = 'Fixed' - } - - sb = new BindableTestBean12() - int changed = 0 - sb.propertyChange = {changed++} - sb.testField = 'newValue' - assert changed == 1 - - sb.anotherTestField = 'Changed' - """) - } - } - - void testFinalClass() { - shouldFail(ReadOnlyPropertyException) { - GroovyShell shell = new GroovyShell() - shell.evaluate(""" - import groovy.beans.Bindable - - @Bindable final class BindableTestBean12 { - String testField - final String anotherTestField = 'Fixed' - } - - sb = new BindableTestBean12() - int changed = 0 - sb.propertyChange = {changed++} - sb.testField = 'newValue' - assert changed == 1 - - sb.anotherTestField = 'Changed' - """) - } - } - - void testGetPropertyChangeListeners() { - assertScript """ - import groovy.beans.Bindable - import java.beans.PropertyChangeListener - import java.beans.PropertyChangeEvent - - class BindableTestBean14 { - @Bindable String foo - @Bindable String bar - } - - class FooListener implements PropertyChangeListener { - void propertyChange( PropertyChangeEvent e ) { } - } - - sb = new BindableTestBean14() - assert !sb.propertyChangeListeners - listener = new FooListener() - sb.addPropertyChangeListener("foo",listener) - assert !sb.getPropertyChangeListeners("bar") - assert sb.getPropertyChangeListeners("foo") == [listener] - assert sb.propertyChangeListeners.size() == 1 - """ - } - - void testPropertyChangeMethodsNotSynthetic() { - def clazz = new GroovyClassLoader().parseClass('class MyBean { @groovy.beans.Bindable String dummy }', 'dummyName') - def modifiers = clazz.getMethod('addPropertyChangeListener', PropertyChangeListener).modifiers - assert isPublic(modifiers) - assert !isSynthetic(modifiers) - } - - void testPropertyChangeMethodWithCompileStatic() { - assertScript """ - import groovy.beans.Bindable - import groovy.transform.CompileStatic - - @CompileStatic - class MyBean { - @Bindable String test = "a test" - } - assert new MyBean() - """ - } +/* + * 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.beans + +import org.codehaus.groovy.control.CompilationFailedException + +import java.beans.PropertyChangeListener + +import static java.lang.reflect.Modifier.isPublic +import static java.lang.reflect.Modifier.isSynthetic + +class BindableTest extends GroovyTestCase { + + void testSimpleBindableProperty() { + assertScript """ + import groovy.beans.Bindable + + class BindableTestBean1 { + @Bindable String name + } + + sb = new BindableTestBean1() + sb.name = "bar" + changed = false + sb.propertyChange = {changed = true} + sb.name = "foo" + assert changed + """ + } + + void testMultipleBindableProperty() { + assertScript """ + import groovy.beans.Bindable + + class BindableTestBean2 { + @Bindable String name + @Bindable String value + } + + sb = new BindableTestBean2(name:"foo", value:"bar") + changed = 0 + sb.propertyChange = {changed++} + sb.name = "baz" + sb.value = "biff" + assert changed == 2 + """ + } + + void testMutatingSetter() { + assertScript """ + class BindableTestBean3 { + @groovy.beans.Bindable String name + void setName(String newName) { + this.@name = "x\$newName" + } + } + sb = new BindableTestBean3(name:"foo") + changed = 0 + sb.propertyChange = {evt -> + assert evt.newValue =~ '^x' + changed++ + } + sb.name = "baz" + assert changed == 1 + """ + } + + void testWithSettersAndGetters() { + for (int i = 0; i < 16; i++) { + boolean bindClass = i & 1 + boolean field = i & 2 + boolean setter = i & 4 + boolean getter = i & 8 + int expectedCount = (bindClass && !field) ? 2 : 1 + String script = """ + import groovy.beans.Bindable + + ${bindClass ? '@Bindable ' : ''}class BindableTestSettersAndGetters$i { + + @Bindable String alwaysBound + ${field ? 'protected ' : ''} String name + + ${setter ? '' : '//'}void setName(String newName) { this.@name = "x\$newName" } + ${getter ? '' : '//'}String getName() { return this.@name } + } + sb = new BindableTestSettersAndGetters$i(name:"foo", alwaysBound:"bar") + changed = 0 + sb.propertyChange = {evt -> + changed++ + } + sb.alwaysBound = "baz" + sb.name = "bif" + sb.name = "bif" + assert changed == $expectedCount + """ + try { + GroovyShell shell = new GroovyShell() + shell.evaluate(script); + } catch (Throwable t) { + System.out.println("Failed Script: $script") + throw t + } + } + } + + void testOnField() { + GroovyShell shell = new GroovyShell() + shouldFail(CompilationFailedException) { + shell.evaluate(""" + class BindableTestBean4 { + public @groovy.beans.Bindable String name + } + """) + } + } + + void testOnStaticField() { + GroovyShell shell = new GroovyShell() + shouldFail(CompilationFailedException) { + shell.evaluate(""" + class BindableTestBean5 { + @groovy.beans.Bindable static String name + } + """) + } + } + + void testClassMarkers() { + for (int i = 0; i < 7; i++) { + boolean bindField = i & 1 + boolean bindClass = i & 2 + boolean staticField = i & 4 + int bindCount = bindClass ? (staticField ? 2 : 3) : (bindField ? 1 : 0); + + String script = """ + import groovy.beans.Bindable + + ${bindClass ? '@Bindable ' : ''}class ClassMarkerBindable$i { + String neither + + ${bindField ? '@Bindable ' : ''}String bind + + ${staticField ? 'static ' : ''}String staticString + } + + cb = new ClassMarkerBindable$i(neither:'a', bind:'b', staticString:'c') + bindCount = 0 + ${bindClass | bindField ? 'cb.propertyChange = { bindCount++ }' : ''} + cb.neither = 'd' + cb.bind = 'e' + cb.staticString = 'f' + assert bindCount == $bindCount + """ + try { + GroovyShell shell = new GroovyShell() + shell.evaluate(script); + } catch (Throwable t) { + System.out.println("Failed Script: $script") + throw t + } + } + } + + void testPrimitiveTypes() { + assertScript """ + import groovy.beans.Bindable + + class BindableTestBean7 { + @Bindable String testField + @Bindable boolean testBoolean + @Bindable byte testByte + @Bindable short testShort + @Bindable int testInt + @Bindable long testLong + @Bindable float testFloat + @Bindable double testDouble + } + + sb = new BindableTestBean7() + sb.testField = "bar" + int changed = 0 + sb.propertyChange = {changed++} + sb.testField = "foo" + sb.testBoolean = true + sb.testByte = 1 + sb.testShort = 1 + sb.testInt = 1 + sb.testLong = 1 + sb.testFloat = 1 + sb.testDouble = 1 + assert changed == 8 + """ + } + + void testBadInheritance() { + shouldFail(CompilationFailedException) { + GroovyShell shell = new GroovyShell() + shell.evaluate(""" + import groovy.beans.Bindable + + class BindableTestBean8 { + @Bindable String testField + void addPropertyChangeListener(java.beans.PropertyChangeListener l) {} + } + new BindableTestBean8() + """) + } + shouldFail(CompilationFailedException) { + GroovyShell shell = new GroovyShell() + shell.evaluate(""" + import groovy.beans.Bindable + + class BindableTestBean9 { + void addPropertyChangeListener(java.beans.PropertyChangeListener l) {} + } + + class BindableTestBean10 extends BindableTestBean9 { + @Bindable String testField + } + + new BindableTestBean10() + """) + } + } + + void testBindableParent() { + assertScript """ + import groovy.beans.Bindable + import java.beans.PropertyChangeEvent + import java.beans.PropertyChangeListener + + @Bindable + class BindableTestBeanChild extends BindableTestBeanParent { + String prop2 + BindableTestBeanChild() { + super() + } + } + + @Bindable + class BindableTestBeanParent implements PropertyChangeListener { + String prop1 + BindableTestBeanParent() { + addPropertyChangeListener(this) + } + + void propertyChange(PropertyChangeEvent event) {} + } + + new BindableTestBeanChild() + """ + } + + void testFinalProperty() { + shouldFail(CompilationFailedException) { + GroovyShell shell = new GroovyShell() + shell.evaluate(""" + import groovy.beans.Bindable + + class BindableTestBean11 { + @Bindable final String testField + } + 1+1 + """) + } + } + + void testOnClassFinalProperty() { + shouldFail(ReadOnlyPropertyException) { + GroovyShell shell = new GroovyShell() + shell.evaluate(""" + import groovy.beans.Bindable + + @Bindable class BindableTestBean12 { + String testField + final String anotherTestField = 'Fixed' + } + + sb = new BindableTestBean12() + int changed = 0 + sb.propertyChange = {changed++} + sb.testField = 'newValue' + assert changed == 1 + + sb.anotherTestField = 'Changed' + """) + } + } + + void testFinalClass() { + shouldFail(ReadOnlyPropertyException) { + GroovyShell shell = new GroovyShell() + shell.evaluate(""" + import groovy.beans.Bindable + + @Bindable final class BindableTestBean12 { + String testField + final String anotherTestField = 'Fixed' + } + + sb = new BindableTestBean12() + int changed = 0 + sb.propertyChange = {changed++} + sb.testField = 'newValue' + assert changed == 1 + + sb.anotherTestField = 'Changed' + """) + } + } + + void testGetPropertyChangeListeners() { + assertScript """ + import groovy.beans.Bindable + import java.beans.PropertyChangeListener + import java.beans.PropertyChangeEvent + + class BindableTestBean14 { + @Bindable String foo + @Bindable String bar + } + + class FooListener implements PropertyChangeListener { + void propertyChange( PropertyChangeEvent e ) { } + } + + sb = new BindableTestBean14() + assert !sb.propertyChangeListeners + listener = new FooListener() + sb.addPropertyChangeListener("foo",listener) + assert !sb.getPropertyChangeListeners("bar") + assert sb.getPropertyChangeListeners("foo") == [listener] + assert sb.propertyChangeListeners.size() == 1 + """ + } + + void testPropertyChangeMethodsNotSynthetic() { + def clazz = new GroovyClassLoader().parseClass('class MyBean { @groovy.beans.Bindable String dummy }', 'dummyName') + def modifiers = clazz.getMethod('addPropertyChangeListener', PropertyChangeListener).modifiers + assert isPublic(modifiers) + assert !isSynthetic(modifiers) + } + + void testPropertyChangeMethodWithCompileStatic() { + assertScript """ + import groovy.beans.Bindable + import groovy.transform.CompileStatic + + @CompileStatic + class MyBean { + @Bindable String test = "a test" + } + assert new MyBean() + """ + } } \ No newline at end of file