|
Groovy example source code file (MapPropertyTest.groovy)
The Groovy MapPropertyTest.groovy source code
package groovy
/**
* @author <a href="mailto:james@coredevelopers.net">James Strachan
* @version $Revision: 5137 $
*/
class MapPropertyTest extends GroovyTestCase {
void testGetAndSetProperties() {
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
}
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()
c.id = "hello"
c.class = 1
c.myMethod()
assert c.id == "hello"
assert c.class == 1
assert c.getClass() != 1
}
}
class MyClass extends HashMap {
def myMethod() {
assert id == "hello"
assert this.class == 1
}
}
Other Groovy examples (source code examples)Here is a short list of links related to this Groovy MapPropertyTest.groovy source code file: |
Other websites by Alvin Alexander:
Life/living in Alaska (OneMansAlaska.com)
How I Sold My Business (HowISoldMyBusiness.com)
Copyright 1998-2011 Alvin Alexander, devdaily.com
All Rights Reserved.