Skip to content

Commit 2e99f89

Browse files
committed
BAEL-2661 - Groovy def keyword - variable names
1 parent d0a6c57 commit 2e99f89

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

‎core-groovy-2/src/test/groovy/com/baeldung/defkeyword/DefUnitTest.groovy‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,29 @@ class DefUnitTest extends GroovyTestCase {
1919
}
2020

2121
@TypeChecked(TypeCheckingMode.SKIP)
22-
void testDef() {
22+
void testDefVariableDeclaration() {
2323

2424
def list
2525
assert list.getClass() == org.codehaus.groovy.runtime.NullObject
2626
assert list.is(null)
2727

2828
list = [1,2,4]
2929
assert list instanceof ArrayList
30-
31-
int sum = 200
30+
}
31+
32+
@TypeChecked(TypeCheckingMode.SKIP)
33+
void testTypeVariables() {
34+
int rate = 200
3235
try {
33-
sum = [12] //GroovyCastException
34-
sum = "nill" //GroovyCastException
36+
rate = [12] //GroovyCastException
37+
rate = "nill" //GroovyCastException
3538
} catch(GroovyCastException) {
3639
println "Cannot assign anything other than integer"
3740
}
38-
41+
}
42+
43+
@TypeChecked(TypeCheckingMode.SKIP)
44+
void testDefVariableMultipleAssignment() {
3945
def rate
4046
assert rate == null
4147
assert rate.getClass() == org.codehaus.groovy.runtime.NullObject

0 commit comments

Comments
 (0)