dependencies {
implementation 'org.codehaus.groovy:groovy-all:3.0.8'
}
groovy
import org.junit.Assert
class StringHelperTest {
@Test
void testTransformToUpperCase() {
def input = "hello"
def expectedOutput = "HELLO"
def result = StringHelper.transformToUpperCase(input)
Assert.assertEquals(expectedOutput, result)
}
}
groovy
def list = [1, 2, 3, 4, 5]
def transformedList = list.collect { element ->
element * 2
}
println(transformedList)
groovy
class Calculator {
def add(int a, int b) {
a + b
}
}
Calculator.metaClass.multiply = { int a, int b ->
a * b
}
def calculator = new Calculator()
println(calculator.multiply(2, 3))
groovy
def name = "Alice"
def age = 25
def description = """
Name: $name
Age: $age
"""
println(description)