| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (

This example Groovy source code file ( is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

c, exception, exception, file, file, foo, foo, groovytestcase, java2groovytest, string, string

The Groovy source code

 * Copyright 2005 Jeremy Rayner
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
package org.codehaus.groovy.antlr.treewalker;

import groovy.util.GroovyTestCase;

public class Java2GroovyTest extends GroovyTestCase {

    public void testSimpleClass() throws Exception {
        assertEquals("private class Foo {int x = 1}", convert("private class Foo{int x=1;}"));

    public void testStringLiteral() throws Exception {
        assertEquals("class Foo {String x = \"mooky\"}", convert("public class Foo{String x = \"mooky\";}"));
        assertEquals("class C {void m(String s) {File f = new File(\"sl\" + s)}}", convert("public class C{void m(String s) {File f=new File(\"sl\" + s);}}"));

    private String convert(String input) throws Exception {
        return Java2GroovyMain.convert("", input);

    private String mindmap(String input) throws Exception {
        return Java2GroovyMain.mindmap(input);

    private String nodePrinter(String input) throws Exception {
        return Java2GroovyMain.nodePrinter(input);

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.