use of com.querydsl.codegen.utils.support.Cat in project querydsl by querydsl.
the class ComplexEvaluationTest method ComplexClassLoading.
@Test
@SuppressWarnings("unchecked")
public void ComplexClassLoading() {
ClassType resultType = new ClassType(TypeCategory.LIST, List.class, Types.OBJECTS);
StringBuilder source = new StringBuilder();
source.append("java.util.List<Object[]> rv = new java.util.ArrayList<Object[]>();\n");
source.append("for (com.querydsl.codegen.utils.support.Cat cat : (java.util.List<com.querydsl.codegen.utils.support.Cat>)cat_){\n");
source.append("for (com.querydsl.codegen.utils.support.Cat otherCat : (java.util.List<com.querydsl.codegen.utils.support.Cat>)otherCat_){\n");
source.append("rv.add(new Object[]{cat,otherCat});\n");
source.append("}\n");
source.append("}\n");
source.append("return rv;\n");
Cat fuzzy = new Cat("fuzzy");
Cat spot = new Cat("spot");
Cat mittens = new Cat("mittens");
Cat sparkles = new Cat("sparkles");
List<Cat> a = Arrays.asList(fuzzy, spot);
List<Cat> b = Arrays.asList(mittens, sparkles);
ClassType argType = new ClassType(TypeCategory.LIST, List.class, new ClassType(Cat.class));
// cannot specify further than List.class
@SuppressWarnings("rawtypes") Evaluator<List> evaluator = factory.createEvaluator(source.toString(), resultType, new String[] { "cat_", "otherCat_" }, new Type[] { argType, argType }, new Class<?>[] { List.class, List.class }, Collections.<String, Object>emptyMap());
Object[][] expResults = { { fuzzy, mittens }, { fuzzy, sparkles }, { spot, mittens }, { spot, sparkles } };
List<Object[]> result = evaluator.evaluate(a, b);
assertEquals(expResults.length, result.size());
for (int i = 0; i < expResults.length; i++) {
assertEquals(expResults[i].length, result.get(i).length);
for (int j = 0; j < expResults[i].length; j++) {
assertEquals(expResults[i][j], result.get(i)[j]);
}
}
}
use of com.querydsl.codegen.utils.support.Cat in project querydsl by querydsl.
the class ComplexEvaluationTest method ComplexDifferentConstants.
@Test
public void ComplexDifferentConstants() {
ClassType resultType = new ClassType(TypeCategory.LIST, List.class, new ClassType(Cat.class));
String source = new StringBuilder().append("java.util.List<com.querydsl.codegen.utils.support.Cat> rv = new java.util.ArrayList<com.querydsl.codegen.utils.support.Cat>();\n").append("for (com.querydsl.codegen.utils.support.Cat cat : (java.util.List<com.querydsl.codegen.utils.support.Cat>)cat_){\n").append("if (cat.equals(a1)) {\n").append("rv.add(cat);\n").append("}\n").append("}\n").append("return rv;\n").toString();
List<Cat> cats = Arrays.asList(new Cat("fuzzy"), new Cat("spot"));
String[] names = new String[] { "cat_" };
Type[] types = new Type[] { new ClassType(TypeCategory.LIST, List.class, new ClassType(Cat.class)) };
Class<?>[] classes = new Class<?>[] { List.class };
// first pass
factory.createEvaluator(source, resultType, names, types, classes, Collections.singletonMap("a1", (Object) new SuperCat("superMittens"))).evaluate(cats);
// second pass
factory.createEvaluator(source, resultType, names, types, classes, Collections.singletonMap("a1", (Object) new Cat("normalMittens"))).evaluate(cats);
}