Skip to content
Permalink
Browse files
convert to JUnit 4
  • Loading branch information
eric-milles committed Mar 13, 2022
1 parent a91d120 commit cee05a4d544fed5c73066e465384d604fd7ad97a
Show file tree
Hide file tree
Showing 5 changed files with 348 additions and 367 deletions.
@@ -18,51 +18,57 @@
*/
package org.codehaus.groovy.transform

import groovy.test.GroovyShellTestCase
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.control.customizers.ImportCustomizer
import org.junit.Test

class AutoCloneTransformTest extends GroovyShellTestCase {
import static groovy.test.GroovyAssert.assertScript
import static groovy.test.GroovyAssert.shouldFail

void testOk() {
assertScript """
import groovy.transform.AutoClone
@AutoClone
class Person {
String first, last
List favItems
Date since
}
/**
* Tests for the {@code @AutoClone} AST transform.
*/
final class AutoCloneTransformTest {

def p = new Person(first:'John', last:'Smith', favItems:['ipod', 'shiraz'], since:new Date())
def p2 = p.clone()
private final GroovyShell shell = new GroovyShell(new CompilerConfiguration().
addCompilationCustomizers(new ImportCustomizer().tap { addImports('groovy.transform.AutoClone') })
)

assert p instanceof Cloneable
assert p.favItems instanceof Cloneable
assert p.since instanceof Cloneable
assert !(p.first instanceof Cloneable)
@Test
void testBasics() {
assertScript shell, '''
@AutoClone
class Person {
String first, last
List favItems
Date since
}
assert !p.is(p2)
assert !p.favItems.is(p2.favItems)
assert !p.since.is(p2.since)
assert p.first.is(p2.first)
"""
}
def p = new Person(first:'John', last:'Smith', favItems:['ipod','shiraz'], since:new Date())
void testExcludesWithInvalidPropertyNameResultsInError() {
def message = shouldFail {
evaluate """
import groovy.transform.AutoClone
assert p instanceof Cloneable
assert p.favItems instanceof Cloneable
assert p.since instanceof Cloneable
assert p.first !instanceof Cloneable
@AutoClone(excludes='sirName')
class Person {
String firstName
String surName
}
def p2 = p.clone()
new Person(firstName: "John", surName: "Doe").clone()
"""
}
assert message.contains("Error during @AutoClone processing: 'excludes' property 'sirName' does not exist.")
assert !p.is(p2)
assert !p.favItems.is(p2.favItems)
assert !p.since.is(p2.since)
assert p.first.is(p2.first)
'''
}

@Test
void testExcludesWithInvalidPropertyNameResultsInError() {
def err = shouldFail shell, '''
@AutoClone(excludes='sirName')
class Person {
String firstName
String surName
}
'''
assert err =~ /Error during @AutoClone processing: 'excludes' property 'sirName' does not exist./
}
}
@@ -18,17 +18,25 @@
*/
package org.codehaus.groovy.transform

import gls.CompilableTestSupport
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.control.customizers.ImportCustomizer
import org.junit.Test

import static groovy.test.GroovyAssert.assertScript

/**
* Tests for the {@code @AutoFinal} AST transform.
*/
class AutoFinalTransformTest extends CompilableTestSupport {
final class AutoFinalTransformTest {

private final GroovyShell shell = new GroovyShell(new CompilerConfiguration().
addCompilationCustomizers(new ImportCustomizer().tap { addImports('groovy.transform.AutoFinal', 'groovy.transform.ASTTest') })
)

@Test
void testAutoFinalOnClass() {
// use ASTTest here since final modifier isn't put into bytecode so not available via reflection
assertScript '''
import groovy.transform.*
assertScript shell, '''
import static java.lang.reflect.Modifier.isFinal
@ASTTest(phase=SEMANTIC_ANALYSIS, value={
@@ -60,10 +68,10 @@ class AutoFinalTransformTest extends CompilableTestSupport {
'''
}

@Test
void testAutoFinalOnClassButDisabledOnMethod() {
// use ASTTest here since final modifier isn't put into bytecode so not available via reflection
assertScript '''
import groovy.transform.*
assertScript shell, '''
import static java.lang.reflect.Modifier.isFinal
@ASTTest(phase=SEMANTIC_ANALYSIS, value={

0 comments on commit cee05a4

Please sign in to comment.