GroovyMerger extends AbstractGroovyMerger implements SinglePropertyValueMerger<Object, Object> { @Override public Object mergeObjects(Object value, String[] extraParam) { String expression = getExpression(extraParam); Binding binding = new Binding(); binding.setVariable(SOURCE_VARIABLE_NAME, value); return evaluateGroovyScript(binding, expression); }  @Override Object mergeObjects(Object value, String[] extraParam);  }
@Test public void testToString() { Integer myInt = 20; String[] script = { "sourceValue.toString()" }; String result = (String) groovyMerger.mergeObjects(myInt, script); assertEquals("Should be equals: ", myInt.toString(), result); }
@Test public void testNullChecks() { String[] script = { " sourceValue == null ? 'isNull' : 'isNotNull' " }; String result = (String) groovyMerger.mergeObjects(null, script); assertEquals("Should say 'isNull' ", "isNull", result); }
@Test public void testCommons() { String[] script = {"StringUtils.reverse(sourceValue)"}; String object = "start"; String result = (String) groovyMerger.mergeObjects(object, script); assertEquals("Should be the reverse of the string", StringUtils.reverse(object), result); }
@Test public void testLogging() { String[] script = {"logger.error('Value is: ' + sourceValue); return sourceValue;"}; String original = "TEST"; String result = (String) groovyMerger.mergeObjects(original, script); assertEquals("Object should remain unchanged.", original, result); }