|
Groovy example source code file (GName1Test.groovy)
The Groovy GName1Test.groovy source codepackage gls.ch06.s05; import gls.ch06.s05.testClasses.Tt1cgi; import gls.ch06.s05.testClasses.Tt1cgo; import gls.ch06.s05.testClasses.Tt1gi; import gls.ch06.s05.testClasses.Tt1go; import gls.ch06.s05.testClasses.Tt1; import gls.ch06.s05.testClasses.Tt1c; class GName1Test extends GroovyTestCase { void testObjectSupportNameHandling() { Tt1 obj = new Tt1() // Test POJO def newX = "new x" def newX1 = "new x1" def newX2 = "new x2" assert obj.x == "property" assert obj.@x == "field" assert obj.x() == "method" obj.x = newX obj.@x = newX1 assert obj.x == newX assert obj.@x == newX1 obj.setX newX2 assert obj.x == newX2 assert obj.@x == newX1 } void testObjectSupportNameHandling1() { Tt1go obj = new Tt1go() // Test class subclassing GroovyObjectSupport def newX = "new x" def newX1 = "new x1" def newX2 = "new x2" assert obj.x == "property" assert obj.@x == "field" assert obj.x() == "method" obj.x = newX obj.@x = newX1 assert obj.x == newX assert obj.@x == newX1 obj.setX newX2 assert obj.x == newX2 assert obj.@x == newX1 } void testObjectSupportNameHandling2() { Tt1 obj = new Tt1gi() // Test POJO implementing GroovyObject def newX = "new x" def newX1 = "new x1" def newX2 = "new x2" assert obj.x == "dynamic property" assert obj.@x == "field" assert obj.x() == "dynamic method" obj.x = newX obj.@x = newX1 assert obj.x == "dynamic property" assert obj.@x == newX1 obj.setX newX2 assert obj.x == "dynamic property" assert obj.@x == newX1 } void testObjectSupportNameHandlingWitnClosureValues() { Tt1c obj = new Tt1c() // Test POJO def newX = {"new x"} def newX1 = {"new x1"} def newX2 = {"new x2"} assert (obj.x)() == "property" assert obj.@x() == "field" assert obj.x() == "method" obj.x = newX obj.@x = newX1 assert (obj.x)() == newX() assert obj.@x() == newX1() obj.setX newX2 assert (obj.x)() == newX2() assert obj.@x() == newX1() } void testObjectSupportNameHandlingWitnClosureValues1() { Tt1cgo obj = new Tt1cgo() // class subclassing GroovyObjectSupport def newX = {"new x"} def newX1 = {"new x1"} def newX2 = {"new x2"} assert (obj.x)() == "property" assert obj.@x() == "field" assert obj.x() == "method" obj.x = newX obj.@x = newX1 assert (obj.x)() == newX() assert (obj.@x)() == newX1() obj.setX newX2 assert (obj.x)() == newX2() assert (obj.@x)() == newX1() } void testObjectSupportNameHandlingWitnClosureValues2() { Tt1c obj = new Tt1cgi() // Test POJO implementing GroovyObject def newX = {"new x"} def newX1 = {"new x1"} def newX2 = {"new x2"} assert (obj.x)() == "property" assert (obj.@x)() == "field" // can't write obj.@x() - syntax error assert obj.x() == "method" obj.x = newX obj.@x = newX1 assert (obj.x)() == newX() assert (obj.@x)() == newX1() obj.setX newX2 assert (obj.x)() == newX2() assert (obj.@x)() == newX1() } } Other Groovy examples (source code examples)Here is a short list of links related to this Groovy GName1Test.groovy source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.