Package com.mysema.query.support

Source Code of com.mysema.query.support.ReplaceVisitorTest

package com.mysema.query.support;

import com.mysema.query.types.*;
import com.mysema.query.types.path.StringPath;
import org.junit.Test;

import javax.annotation.Nullable;

import static org.junit.Assert.assertEquals;

public class ReplaceVisitorTest {

    private static final ReplaceVisitor visitor = new ReplaceVisitor() {
        public Expression<?> visit(Path<?> expr, @Nullable Void context) {
            if (expr.getMetadata().isRoot()) {
                return new PathImpl(expr.getType(), expr.getMetadata().getName() + "_");
            } else {
                return super.visit(expr, context);
            }
        }
    };

    @Test
    public void Operation() {
        Expression<String> str = new StringPath(new PathImpl(Object.class, "customer"), "name");
        Expression<String> str2 = new StringPath("str");
        Expression<String> concat = Expressions.stringOperation(Ops.CONCAT, str, str2);
        assertEquals("customer.name + str", concat.toString());
        assertEquals("customer_.name + str_", concat.accept(visitor, null).toString());
    }

    @Test
    public void TemplateExpression() {
        Expression<String> str = new StringPath(new PathImpl(Object.class, "customer"), "name");
        Expression<String> str2 = new StringPath("str");
        Expression<String> concat = Expressions.stringTemplate("{0} + {1}", str, str2);
        assertEquals("customer.name + str", concat.toString());
        assertEquals("customer_.name + str_", concat.accept(visitor, null).toString());
    }
}
TOP

Related Classes of com.mysema.query.support.ReplaceVisitorTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.