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

Groovy example source code file (VariableExpressionTest.java)

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

Java - Groovy tags/keywords

dynamicvariable, dynamicvariable, parameter, parameter, testcase, variableexpression, variableexpression, variableexpressiontest, variableexpressiontest

The Groovy VariableExpressionTest.java source code

/**
 * 
 */
package org.codehaus.groovy.ast;

import junit.framework.TestCase;

import org.codehaus.groovy.ast.expr.VariableExpression;

/**
 * Tests the VariableExpressionNode
 * 
 * @author <a href="mailto:martin.kempf@gmail.com">Martin Kempf
 *
 */
public class VariableExpressionTest extends TestCase {

    public void testPrimitiveOriginType() {
        VariableExpression boolExpression = new VariableExpression("fo",ClassHelper.boolean_TYPE);
        VariableExpression intExpression = new VariableExpression("foo", ClassHelper.int_TYPE);
        assertEquals(boolExpression.getOriginType().getName(),"boolean");
        assertEquals(intExpression.getOriginType().getName(),"int");
    }
    
    public void testNonPrimitiveOriginType() {
        VariableExpression boolExpression = new VariableExpression("foo",ClassHelper.Boolean_TYPE);
        VariableExpression intExpression = new VariableExpression("foo", ClassHelper.Integer_TYPE);
        assertEquals(boolExpression.getOriginType().getName(),"java.lang.Boolean");
        assertEquals(intExpression.getOriginType().getName(),"java.lang.Integer");        
    }
    
    public void testPrimitiveOriginTypeConstructorVariableExpression() {
        VariableExpression boolExpression = new VariableExpression("foo",ClassHelper.boolean_TYPE);
        VariableExpression intExpression = new VariableExpression("foo", ClassHelper.int_TYPE);
        VariableExpression newBoolExpression = new VariableExpression(boolExpression);
        VariableExpression newIntExpression = new VariableExpression(intExpression);
        assertEquals(newBoolExpression.getOriginType().getName(),"boolean");
        assertEquals(newIntExpression.getOriginType().getName(),"int"); 
    }
    
    public void testPrimitiveOriginTypeConstructorParameter() {
        Parameter boolParameter = new Parameter(ClassHelper.boolean_TYPE,"foo");
        Parameter intParameter = new Parameter(ClassHelper.int_TYPE,"foo");
        VariableExpression newBoolExpression = new VariableExpression(boolParameter);
        VariableExpression newIntExpression = new VariableExpression(intParameter);
        assertEquals(newBoolExpression.getOriginType().getName(),"boolean");
        assertEquals(newIntExpression.getOriginType().getName(),"int"); 
    }
    
    public void testPrimitiveOriginTypeConstructorDynVariable() {
        DynamicVariable dynVariable = new DynamicVariable("foo",false);
        assertEquals(dynVariable.getOriginType().getName(),"java.lang.Object");
    }
    
    public void testIsDynamicTypedExplicitObject() {
        VariableExpression intExpression = new VariableExpression("foo", new ClassNode(Object.class));
        assertFalse(intExpression.isDynamicTyped());
    }
    
    public void testIsDynamicTyped_DYNMAMIC_TYPE() {
        VariableExpression intExpression = new VariableExpression("foo", ClassHelper.DYNAMIC_TYPE);
        assertTrue(intExpression.isDynamicTyped());
    }
    
    public void testIsDynamicTyped_DynamicVariable() {
        VariableExpression intExpression = new VariableExpression(new DynamicVariable("foo",false));
        assertTrue(intExpression.isDynamicTyped());
    }
}

Other Groovy examples (source code examples)

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

new blog posts

 

Copyright 1998-2014 Alvin Alexander, alvinalexander.com
All Rights Reserved.