mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-30 21:08:30 +08:00
added tests
This commit is contained in:
parent
9536a0d4c5
commit
823ee0783f
@ -75,11 +75,9 @@ public class BeanPath<D> extends SimpleExpression<D> implements Path<D> {
|
||||
if (!casts.containsKey(clazz)) {
|
||||
T rv;
|
||||
if (inits != null) {
|
||||
rv = clazz.getConstructor(PathMetadata.class,
|
||||
PathInits.class).newInstance(this.getMetadata(), inits);
|
||||
rv = clazz.getConstructor(PathMetadata.class, PathInits.class).newInstance(this.getMetadata(), inits);
|
||||
} else {
|
||||
rv = (T) clazz.getConstructor(PathMetadata.class)
|
||||
.newInstance(this.getMetadata());
|
||||
rv = (T) clazz.getConstructor(PathMetadata.class).newInstance(this.getMetadata());
|
||||
}
|
||||
casts.put(clazz, rv);
|
||||
return rv;
|
||||
|
||||
@ -45,6 +45,10 @@ public class MapPath<K, V, E extends SimpleExpression<V>> extends MapExpressionB
|
||||
|
||||
private final Class<V> valueType;
|
||||
|
||||
public MapPath(Class<? super K> keyType, Class<? super V> valueType, Class<E> queryType, String variable) {
|
||||
this(keyType, valueType, queryType, PathMetadataFactory.forVariable(variable));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public MapPath(Class<? super K> keyType, Class<? super V> valueType, Class<E> queryType, PathMetadata<?> metadata) {
|
||||
super((Class)Map.class);
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
package com.mysema.query.types.path;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.mysema.query.types.ConstantImpl;
|
||||
|
||||
|
||||
public class ArrayPathTest {
|
||||
|
||||
@Test
|
||||
public void Get(){
|
||||
ArrayPath<String> arrayPath = new ArrayPath<String>(String[].class, "p");
|
||||
assertNotNull(arrayPath.get(ConstantImpl.create(0)));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package com.mysema.query.types.path;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.mysema.query.annotations.PropertyType;
|
||||
|
||||
public class BeanPathTest {
|
||||
|
||||
@Test
|
||||
public void CreateEnum(){
|
||||
BeanPath<BeanPathTest> beanPath = new BeanPath<BeanPathTest>(BeanPathTest.class, "p");
|
||||
assertNotNull(beanPath.createEnum("property", PropertyType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void As(){
|
||||
BeanPath<BeanPathTest> beanPath = new BeanPath<BeanPathTest>(BeanPathTest.class, "p");
|
||||
SimplePath<BeanPathTest> simplePath = new SimplePath<BeanPathTest>(BeanPathTest.class, "p");
|
||||
assertNotNull(beanPath.as(simplePath));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.mysema.query.types.path;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.mysema.query.types.ConstantImpl;
|
||||
|
||||
public class MapPathTest {
|
||||
|
||||
@Test
|
||||
public void Get() {
|
||||
MapPath<String,String,StringPath> mapPath = new MapPath<String,String,StringPath>(String.class, String.class, StringPath.class, "p");
|
||||
assertNotNull(mapPath.get("X"));
|
||||
assertNotNull(mapPath.get(ConstantImpl.create("X")));
|
||||
}
|
||||
|
||||
}
|
||||
@ -30,6 +30,7 @@ import com.mysema.query.annotations.QueryEntity;
|
||||
import com.mysema.query.annotations.QueryTransient;
|
||||
import com.mysema.query.types.Path;
|
||||
import com.mysema.query.types.PathImpl;
|
||||
import com.mysema.query.types.ToStringVisitor;
|
||||
import com.mysema.util.AnnotatedElementAdapter;
|
||||
|
||||
public class PathTest {
|
||||
@ -141,16 +142,22 @@ public class PathTest {
|
||||
public void Various(){
|
||||
List<Path<?>> paths = new ArrayList<Path<?>>();
|
||||
paths.add(new ArrayPath(String[].class, "p"));
|
||||
paths.add(new BeanPath(Object.class, "p"));
|
||||
paths.add(new BooleanPath("p"));
|
||||
paths.add(new ComparablePath(String.class,"p"));
|
||||
paths.add(new DatePath(Date.class,"p"));
|
||||
paths.add(new DateTimePath(Date.class,"p"));
|
||||
paths.add(new EnumPath(ExampleEnum.class,"p"));
|
||||
paths.add(new NumberPath(Integer.class,"p"));
|
||||
paths.add(new SimplePath(String.class,"p"));
|
||||
paths.add(new StringPath("p"));
|
||||
paths.add(new TimePath(Time.class,"p"));
|
||||
|
||||
for (Path<?> path : paths){
|
||||
Path other = new PathImpl(path.getType(), "p");
|
||||
assertEquals(path.toString(), path.accept(ToStringVisitor.DEFAULT, null));
|
||||
assertEquals(path.hashCode(), other.hashCode());
|
||||
assertEquals(path, other);
|
||||
assertNotNull(path.getMetadata());
|
||||
assertNotNull(path.getType());
|
||||
assertEquals(path, path.getRoot());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user