mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
added test for projecting paths of custom types
added parent classLoader for MemClassLoader
This commit is contained in:
parent
3aeb109a4d
commit
699ecf87f6
@ -46,7 +46,7 @@ public class EvaluatorFactory {
|
||||
}
|
||||
|
||||
public EvaluatorFactory(URLClassLoader parent, JavaCompiler compiler) {
|
||||
this.fileManager = new MemFileManager(compiler.getStandardFileManager(null, null, null));
|
||||
this.fileManager = new MemFileManager(parent, compiler.getStandardFileManager(null, null, null));
|
||||
this.compiler = compiler;
|
||||
this.classpath = SimpleCompiler.getClassPath(parent);
|
||||
this.loader = fileManager.getClassLoader(StandardLocation.CLASS_OUTPUT);
|
||||
|
||||
@ -36,7 +36,8 @@ public final class MemClassLoader extends ClassLoader {
|
||||
|
||||
private final Map<LocationAndKind, Map<String, JavaFileObject>> memFileSystem;
|
||||
|
||||
public MemClassLoader(Map<LocationAndKind, Map<String, JavaFileObject>> ramFileSystem) {
|
||||
public MemClassLoader(ClassLoader parent, Map<LocationAndKind, Map<String, JavaFileObject>> ramFileSystem) {
|
||||
super(parent);
|
||||
this.memFileSystem = ramFileSystem;
|
||||
}
|
||||
|
||||
|
||||
@ -36,12 +36,12 @@ public class MemFileManager extends ForwardingJavaFileManager<JavaFileManager> {
|
||||
|
||||
private final String urlPrefix;
|
||||
|
||||
public MemFileManager(StandardJavaFileManager sjfm) {
|
||||
public MemFileManager(ClassLoader parent, StandardJavaFileManager sjfm) {
|
||||
super(sjfm);
|
||||
ramFileSystem = new HashMap<LocationAndKind,Map<String,JavaFileObject>>();
|
||||
Map<String,JavaFileObject> classLoaderContent = new HashMap<String,JavaFileObject>();
|
||||
ramFileSystem.put(new LocationAndKind(StandardLocation.CLASS_OUTPUT, Kind.CLASS),classLoaderContent);
|
||||
classLoader = new MemClassLoader(ramFileSystem);
|
||||
classLoader = new MemClassLoader(parent, ramFileSystem);
|
||||
urlPrefix = MemFileSystemRegistry.DEFAULT.getUrlPrefix(this);
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ package com.mysema.codegen;
|
||||
import java.io.IOException;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
@ -17,6 +18,20 @@ import org.junit.Test;
|
||||
|
||||
public class EvaluatorFactoryTest {
|
||||
|
||||
public static class TestEntity {
|
||||
|
||||
private final String name;
|
||||
|
||||
public TestEntity(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private EvaluatorFactory factory;
|
||||
|
||||
private List<String> names = Arrays.asList("a","b");
|
||||
@ -55,6 +70,14 @@ public class EvaluatorFactoryTest {
|
||||
test("a + b", int.class, names, ints, Arrays.asList(1,2), 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomType(){
|
||||
test("a.getName()", String.class,
|
||||
Collections.singletonList("a"), Collections.singletonList(TestEntity.class),
|
||||
Arrays.asList(new TestEntity("Hello World")), "Hello World");
|
||||
|
||||
}
|
||||
|
||||
private void test(String source, Class<?> projectionType, List<String> names, List<? extends Class<?>> types, List<?> args, Object expectedResult){
|
||||
Assert.assertEquals(expectedResult, test(source, projectionType, names, types, args));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user