mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-06 21:05:50 +08:00
This commit is contained in:
parent
0122f762a9
commit
ab38def6f4
@ -6,43 +6,57 @@
|
||||
package com.mysema.query.types.custom;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.sql.Time;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.mysema.query.serialization.JavaTemplates;
|
||||
import com.mysema.query.types.Custom;
|
||||
import com.mysema.query.types.Expr;
|
||||
import com.mysema.query.types.Template;
|
||||
import com.mysema.query.types.TemplateFactory;
|
||||
import com.mysema.query.types.ToStringVisitor;
|
||||
import com.mysema.query.types.Visitor;
|
||||
import com.mysema.query.types.expr.EBoolean;
|
||||
import com.mysema.query.types.expr.EBooleanConst;
|
||||
import com.mysema.query.types.path.PString;
|
||||
|
||||
public class CustomTest {
|
||||
|
||||
@Test
|
||||
public void constructors(){
|
||||
Template template = TemplateFactory.DEFAULT.create("");
|
||||
List<Expr<?>> args = Collections.<Expr<?>>emptyList();
|
||||
Visitor visitor = new ToStringVisitor(new JavaTemplates());
|
||||
Template template = TemplateFactory.DEFAULT.create("{0}");
|
||||
List<Expr<?>> args = Arrays.<Expr<?>>asList(new PString("a"));
|
||||
List<Custom<?>> customs = Arrays.<Custom<?>>asList(
|
||||
new CBoolean(template, args),
|
||||
new CComparable<String>(String.class, template, args),
|
||||
new CDate<Date>(Date.class, template, args),
|
||||
new CDate<java.sql.Date>(java.sql.Date.class, template, args),
|
||||
new CDateTime<Date>(Date.class, template, args),
|
||||
new CNumber<Integer>(Integer.class, template, args),
|
||||
new CSimple<Object>(Object.class, template, args),
|
||||
new CString(template, args),
|
||||
new CTime<Time>(Time.class, template, args)
|
||||
);
|
||||
Custom<?> prev = null;
|
||||
for (Custom<?> custom : customs){
|
||||
assertNotNull(custom.asExpr());
|
||||
assertNotNull(custom.getTemplate());
|
||||
assertNotNull(custom.getType());
|
||||
assertNotNull(custom.getArgs());
|
||||
assertEquals(custom, custom);
|
||||
if (prev != null){
|
||||
assertFalse(custom.equals(prev));
|
||||
}
|
||||
assertEquals(custom.asExpr().getType().hashCode(), custom.hashCode());
|
||||
custom.asExpr().accept(visitor);
|
||||
prev = custom;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -10,13 +10,17 @@ import org.junit.Test;
|
||||
|
||||
import com.mysema.query.DefaultQueryMetadata;
|
||||
import com.mysema.query.QueryMetadata;
|
||||
import com.mysema.query.serialization.JavaTemplates;
|
||||
import com.mysema.query.types.SubQuery;
|
||||
import com.mysema.query.types.ToStringVisitor;
|
||||
import com.mysema.query.types.Visitor;
|
||||
|
||||
public class SubQueryTest {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void test(){
|
||||
Visitor visitor = new ToStringVisitor(new JavaTemplates());
|
||||
QueryMetadata metadata = new DefaultQueryMetadata();
|
||||
List<SubQuery> subQueries = Arrays.<SubQuery>asList(
|
||||
new BooleanSubQuery(metadata),
|
||||
@ -29,11 +33,19 @@ public class SubQueryTest {
|
||||
new StringSubQuery(metadata),
|
||||
new TimeSubQuery(Date.class,metadata)
|
||||
);
|
||||
SubQuery prev = null;
|
||||
for (SubQuery sq : subQueries){
|
||||
assertNotNull(sq.asExpr());
|
||||
assertNotNull(sq.exists());
|
||||
assertNotNull(sq.getMetadata());
|
||||
assertNotNull(sq.notExists());
|
||||
assertEquals(sq, sq);
|
||||
if (prev != null){
|
||||
assertEquals(sq, prev);
|
||||
}
|
||||
assertEquals(sq.asExpr().getType().hashCode(), sq.hashCode());
|
||||
sq.asExpr().accept(visitor);
|
||||
prev = sq;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user