diff --git a/querydsl-core/src/main/java/com/mysema/query/types/path/ArrayPath.java b/querydsl-core/src/main/java/com/mysema/query/types/path/ArrayPath.java index cc6a19033..92531659a 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/path/ArrayPath.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/path/ArrayPath.java @@ -45,6 +45,10 @@ public class ArrayPath extends SimpleExpression implements Path, Ar this(type, PathMetadataFactory.forVariable(variable)); } + public ArrayPath(Class type, Path parent, String property) { + this(type, PathMetadataFactory.forProperty(parent, property)); + } + @SuppressWarnings("unchecked") public ArrayPath(Class type, PathMetadata metadata) { super((Class)type); diff --git a/querydsl-core/src/main/java/com/mysema/query/types/path/BeanPath.java b/querydsl-core/src/main/java/com/mysema/query/types/path/BeanPath.java index 1d580f18e..bcf8d7f22 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/path/BeanPath.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/path/BeanPath.java @@ -46,6 +46,10 @@ public class BeanPath extends SimpleExpression implements Path { public BeanPath(Class type, String variable) { this(type, PathMetadataFactory.forVariable(variable), null); } + + public BeanPath(Class type, Path parent, String property) { + this(type, PathMetadataFactory.forProperty(parent, property), null); + } public BeanPath(Class type, PathMetadata metadata) { this(type, metadata, null); diff --git a/querydsl-core/src/main/java/com/mysema/query/types/path/CollectionPath.java b/querydsl-core/src/main/java/com/mysema/query/types/path/CollectionPath.java index 62b0307f3..1a1719450 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/path/CollectionPath.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/path/CollectionPath.java @@ -6,13 +6,11 @@ package com.mysema.query.types.path; import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.InvocationTargetException; import java.util.Collection; import javax.annotation.Nullable; import com.mysema.commons.lang.Assert; -import com.mysema.query.types.ExpressionException; import com.mysema.query.types.Path; import com.mysema.query.types.PathImpl; import com.mysema.query.types.PathMetadata; @@ -44,6 +42,10 @@ public class CollectionPath> extends Collection this(type, queryType, PathMetadataFactory.forVariable(variable)); } + public CollectionPath(Class type, Class queryType, Path parent, String property) { + this(type, queryType, PathMetadataFactory.forProperty(parent, property)); + } + @SuppressWarnings("unchecked") public CollectionPath(Class type, Class queryType, PathMetadata metadata) { super((Class)Collection.class); @@ -60,17 +62,7 @@ public class CollectionPath> extends Collection @Override public Q any(){ if (any == null){ - try { - any = newInstance(queryType, PathMetadataFactory.forCollectionAny(this)); - } catch (NoSuchMethodException e) { - throw new ExpressionException(e); - } catch (InstantiationException e) { - throw new ExpressionException(e); - } catch (IllegalAccessException e) { - throw new ExpressionException(e); - } catch (InvocationTargetException e) { - throw new ExpressionException(e); - } + any = newInstance(queryType, PathMetadataFactory.forCollectionAny(this)); } return any; } diff --git a/querydsl-core/src/main/java/com/mysema/query/types/path/CollectionPathBase.java b/querydsl-core/src/main/java/com/mysema/query/types/path/CollectionPathBase.java index 320c2dfc2..054a8407f 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/path/CollectionPathBase.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/path/CollectionPathBase.java @@ -6,6 +6,7 @@ import java.util.Collection; import javax.annotation.Nullable; +import com.mysema.query.types.ExpressionException; import com.mysema.query.types.Path; import com.mysema.query.types.PathMetadata; import com.mysema.query.types.expr.CollectionExpressionBase; @@ -33,21 +34,30 @@ public abstract class CollectionPathBase, E> extends Col public abstract SimpleExpression any(); @SuppressWarnings("unchecked") - protected > Q newInstance(Class queryType, PathMetadata pm) throws NoSuchMethodException, - InstantiationException, IllegalAccessException, - InvocationTargetException { - if (constructor == null) { - if (Constants.isTyped(queryType)){ - constructor = queryType.getConstructor(Class.class, PathMetadata.class); - }else{ - constructor = queryType.getConstructor(PathMetadata.class); + protected > Q newInstance(Class queryType, PathMetadata pm){ + try{ + if (constructor == null) { + if (Constants.isTyped(queryType)){ + constructor = queryType.getConstructor(Class.class, PathMetadata.class); + }else{ + constructor = queryType.getConstructor(PathMetadata.class); + } } + if (Constants.isTyped(queryType)){ + return (Q)constructor.newInstance(getElementType(), pm); + }else{ + return (Q)constructor.newInstance(pm); + } + } catch (NoSuchMethodException e) { + throw new ExpressionException(e); + } catch (InstantiationException e) { + throw new ExpressionException(e); + } catch (IllegalAccessException e) { + throw new ExpressionException(e); + } catch (InvocationTargetException e) { + throw new ExpressionException(e); } - if (Constants.isTyped(queryType)){ - return (Q)constructor.newInstance(getElementType(), pm); - }else{ - return (Q)constructor.newInstance(pm); - } + } } diff --git a/querydsl-core/src/main/java/com/mysema/query/types/path/ComparablePath.java b/querydsl-core/src/main/java/com/mysema/query/types/path/ComparablePath.java index 69f3c61d0..c66e92b15 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/path/ComparablePath.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/path/ComparablePath.java @@ -42,10 +42,6 @@ public class ComparablePath extends ComparableExpression parent, String property) { - this((Class) Comparable.class, PathMetadataFactory.forProperty(parent, property)); - } - @Override public R accept(Visitor v, C context) { return v.visit(this, context); diff --git a/querydsl-core/src/main/java/com/mysema/query/types/path/ListPath.java b/querydsl-core/src/main/java/com/mysema/query/types/path/ListPath.java index 5989e2383..97ab32ca2 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/path/ListPath.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/path/ListPath.java @@ -6,7 +6,6 @@ package com.mysema.query.types.path; import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -15,7 +14,6 @@ import javax.annotation.Nullable; import com.mysema.commons.lang.Assert; import com.mysema.query.types.Expression; -import com.mysema.query.types.ExpressionException; import com.mysema.query.types.Path; import com.mysema.query.types.PathImpl; import com.mysema.query.types.PathMetadata; @@ -50,6 +48,10 @@ public class ListPath> extends CollectionPathBa this(elementType, queryType, PathMetadataFactory.forVariable(variable)); } + public ListPath(Class elementType, Class queryType, Path parent, String property) { + this(elementType, queryType, PathMetadataFactory.forProperty(parent, property)); + } + @SuppressWarnings("unchecked") public ListPath(Class elementType, Class queryType, PathMetadata metadata) { super((Class)List.class); @@ -66,17 +68,7 @@ public class ListPath> extends CollectionPathBa @Override public Q any(){ if (any == null){ - try { - any = newInstance(queryType, PathMetadataFactory.forCollectionAny(this)); - } catch (NoSuchMethodException e) { - throw new ExpressionException(e); - } catch (InstantiationException e) { - throw new ExpressionException(e); - } catch (IllegalAccessException e) { - throw new ExpressionException(e); - } catch (InvocationTargetException e) { - throw new ExpressionException(e); - } + any = newInstance(queryType, PathMetadataFactory.forCollectionAny(this)); } return any; } @@ -90,18 +82,8 @@ public class ListPath> extends CollectionPathBa } private Q create(int index){ - try { - PathMetadata md = forListAccess(index); - return newInstance(queryType, md); - } catch (NoSuchMethodException e) { - throw new ExpressionException(e); - } catch (InstantiationException e) { - throw new ExpressionException(e); - } catch (IllegalAccessException e) { - throw new ExpressionException(e); - } catch (InvocationTargetException e) { - throw new ExpressionException(e); - } + PathMetadata md = forListAccess(index); + return newInstance(queryType, md); } @Override @@ -111,18 +93,8 @@ public class ListPath> extends CollectionPathBa @Override public Q get(Expression index) { - try { - PathMetadata md = forListAccess(index); - return newInstance(queryType, md); - } catch (NoSuchMethodException e) { - throw new ExpressionException(e); - } catch (InstantiationException e) { - throw new ExpressionException(e); - } catch (IllegalAccessException e) { - throw new ExpressionException(e); - } catch (InvocationTargetException e) { - throw new ExpressionException(e); - } + PathMetadata md = forListAccess(index); + return newInstance(queryType, md); } diff --git a/querydsl-core/src/main/java/com/mysema/query/types/path/MapPath.java b/querydsl-core/src/main/java/com/mysema/query/types/path/MapPath.java index 58c208b50..a05ad8901 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/path/MapPath.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/path/MapPath.java @@ -15,9 +15,9 @@ import javax.annotation.Nullable; import com.mysema.query.types.Expression; import com.mysema.query.types.ExpressionException; import com.mysema.query.types.Path; +import com.mysema.query.types.PathImpl; import com.mysema.query.types.PathMetadata; import com.mysema.query.types.PathMetadataFactory; -import com.mysema.query.types.PathImpl; import com.mysema.query.types.Visitor; import com.mysema.query.types.expr.MapExpressionBase; import com.mysema.query.types.expr.SimpleExpression; @@ -49,6 +49,10 @@ public class MapPath> extends MapExpressionB this(keyType, valueType, queryType, PathMetadataFactory.forVariable(variable)); } + public MapPath(Class keyType, Class valueType, Class queryType, Path parent, String property) { + this(keyType, valueType, queryType, PathMetadataFactory.forProperty(parent, property)); + } + @SuppressWarnings("unchecked") public MapPath(Class keyType, Class valueType, Class queryType, PathMetadata metadata) { super((Class)Map.class); diff --git a/querydsl-core/src/main/java/com/mysema/query/types/path/SetPath.java b/querydsl-core/src/main/java/com/mysema/query/types/path/SetPath.java index c44000ca5..a58e42e5d 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/path/SetPath.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/path/SetPath.java @@ -6,13 +6,11 @@ package com.mysema.query.types.path; import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.InvocationTargetException; import java.util.Set; import javax.annotation.Nullable; import com.mysema.commons.lang.Assert; -import com.mysema.query.types.ExpressionException; import com.mysema.query.types.Path; import com.mysema.query.types.PathImpl; import com.mysema.query.types.PathMetadata; @@ -44,6 +42,10 @@ public class SetPath> extends CollectionPathBas this(type, queryType, PathMetadataFactory.forVariable(variable)); } + public SetPath(Class type, Class queryType, Path parent, String property) { + this(type, queryType, PathMetadataFactory.forProperty(parent, property)); + } + @SuppressWarnings("unchecked") public SetPath(Class type, Class queryType, PathMetadata metadata) { super((Class)Set.class); @@ -60,17 +62,7 @@ public class SetPath> extends CollectionPathBas @Override public Q any(){ if (any == null){ - try { - any = newInstance(queryType, PathMetadataFactory.forCollectionAny(this)); - } catch (NoSuchMethodException e) { - throw new ExpressionException(e); - } catch (InstantiationException e) { - throw new ExpressionException(e); - } catch (IllegalAccessException e) { - throw new ExpressionException(e); - } catch (InvocationTargetException e) { - throw new ExpressionException(e); - } + any = newInstance(queryType, PathMetadataFactory.forCollectionAny(this)); } return any; } diff --git a/querydsl-core/src/test/java/com/mysema/query/types/expr/BooleanExpressionTest.java b/querydsl-core/src/test/java/com/mysema/query/types/expr/BooleanExpressionTest.java new file mode 100644 index 000000000..cf6309f3d --- /dev/null +++ b/querydsl-core/src/test/java/com/mysema/query/types/expr/BooleanExpressionTest.java @@ -0,0 +1,29 @@ +package com.mysema.query.types.expr; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.mysema.query.types.path.BooleanPath; + +public class BooleanExpressionTest { + + private BooleanExpression a = new BooleanPath("a"); + private BooleanExpression b = new BooleanPath("b"); + private BooleanExpression c = new BooleanPath("c"); + + @Test + public void AnyOf(){ + assertEquals(a.or(b).or(c), BooleanExpression.anyOf(a, b, c)); + } + + @Test + public void AllOf(){ + assertEquals(a.and(b).and(c), BooleanExpression.allOf(a, b, c)); + } + + @Test + public void Not(){ + assertEquals(a, a.not().not()); + } +} diff --git a/querydsl-core/src/test/java/com/mysema/query/types/expr/SimpleExpressionTest.java b/querydsl-core/src/test/java/com/mysema/query/types/expr/SimpleExpressionTest.java index c8cabcd44..832c3ecf2 100644 --- a/querydsl-core/src/test/java/com/mysema/query/types/expr/SimpleExpressionTest.java +++ b/querydsl-core/src/test/java/com/mysema/query/types/expr/SimpleExpressionTest.java @@ -8,16 +8,24 @@ package com.mysema.query.types.expr; import static org.junit.Assert.assertEquals; import java.lang.reflect.Method; +import java.sql.Time; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; import org.junit.Test; +import com.mysema.query.types.OperationImpl; +import com.mysema.query.types.Ops; import com.mysema.query.types.Path; -import com.mysema.query.types.path.StringPath; +import com.mysema.query.types.PathImpl; +import com.mysema.query.types.path.*; public class SimpleExpressionTest { + enum ExampleEnum {A,B} + @Test public void As_usage(){ SimpleExpression str = new StringPath("str"); @@ -46,5 +54,32 @@ public class SimpleExpressionTest { assertEquals(cl, asString.getReturnType()); } } - + + @SuppressWarnings("unchecked") + @Test + public void Various(){ + List> paths = new ArrayList>(); + paths.add(new ArrayPath(String[].class, "p")); + paths.add(new BeanPath(Object.class, "p")); + paths.add(new BooleanPath("p")); + paths.add(new CollectionPath(String.class, StringPath.class, "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 ListPath(String.class, StringPath.class, "p")); + paths.add(new MapPath(String.class, String.class, StringPath.class, "p")); + paths.add(new NumberPath(Integer.class,"p")); + paths.add(new SetPath(String.class, StringPath.class, "p")); + paths.add(new SimplePath(String.class,"p")); + paths.add(new StringPath("p")); + paths.add(new TimePath(Time.class,"p")); + + for (SimpleExpression expr : paths){ + Path o = new PathImpl(expr.getType(), "o"); + assertEquals(OperationImpl.create(expr.getType(), Ops.ALIAS, expr, o), expr.as("o")); + Path p = new PathImpl(expr.getType(), "p"); + assertEquals(OperationImpl.create(expr.getType(), Ops.ALIAS, expr, p), expr.as(p)); + } + } } diff --git a/querydsl-core/src/test/java/com/mysema/query/types/path/BeanPathTest.java b/querydsl-core/src/test/java/com/mysema/query/types/path/BeanPathTest.java index 2c87e800c..543750692 100644 --- a/querydsl-core/src/test/java/com/mysema/query/types/path/BeanPathTest.java +++ b/querydsl-core/src/test/java/com/mysema/query/types/path/BeanPathTest.java @@ -1,18 +1,29 @@ package com.mysema.query.types.path; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import javax.annotation.Nullable; import org.junit.Test; import com.mysema.query.annotations.PropertyType; import com.mysema.query.types.PathMetadata; +import com.mysema.query.types.PathMetadataFactory; public class BeanPathTest { - public static class MyBeanPath extends BeanPath{ + public static class MyBeanPath extends BeanPath{ + + private static final long serialVersionUID = 6225684967115368814L; public MyBeanPath(PathMetadata metadata) { - super(Object.class, metadata); + super(BeanPathTest.class, metadata); + } + + public MyBeanPath(PathMetadata metadata, @Nullable PathInits inits) { + super(BeanPathTest.class, metadata); } } @@ -25,11 +36,33 @@ public class BeanPathTest { assertNotNull(beanPath.as(simplePath)); } -// @Test -// public void As_Class(){ -// MyBeanPath otherPath = beanPath.as(MyBeanPath.class); -// assertEquals(beanPath, otherPath); -// } + @Test + public void As_Class(){ + MyBeanPath otherPath = beanPath.as(MyBeanPath.class); + assertEquals(beanPath, otherPath); + } + + @Test + public void As_Class_Cached(){ + MyBeanPath otherPath = beanPath.as(MyBeanPath.class); + assertEquals(beanPath, otherPath); + assertTrue(otherPath == beanPath.as(MyBeanPath.class)); + } + + @Test + public void As_Class_with_Inits(){ + beanPath = new BeanPath(BeanPathTest.class, PathMetadataFactory.forVariable("p"), PathInits.DEFAULT); + MyBeanPath otherPath = beanPath.as(MyBeanPath.class); + assertEquals(beanPath, otherPath); + } + + @Test + public void As_Class_with_Inits_Cached(){ + beanPath = new BeanPath(BeanPathTest.class, PathMetadataFactory.forVariable("p"), PathInits.DEFAULT); + MyBeanPath otherPath = beanPath.as(MyBeanPath.class); + assertEquals(beanPath, otherPath); + assertTrue(otherPath == beanPath.as(MyBeanPath.class)); + } @Test public void CreateEnum(){ diff --git a/querydsl-core/src/test/java/com/mysema/query/types/path/CollectionPathTest.java b/querydsl-core/src/test/java/com/mysema/query/types/path/CollectionPathTest.java index 2f592b833..0aad14fd9 100644 --- a/querydsl-core/src/test/java/com/mysema/query/types/path/CollectionPathTest.java +++ b/querydsl-core/src/test/java/com/mysema/query/types/path/CollectionPathTest.java @@ -8,14 +8,25 @@ import com.mysema.query.types.PathMetadataFactory; public class CollectionPathTest { + private CollectionPath stringPath = new CollectionPath( + String.class, StringPath.class, + PathMetadataFactory.forVariable("stringPath")); + @Test - public void test(){ - CollectionPath stringPath = new CollectionPath( - String.class, StringPath.class, - PathMetadataFactory.forVariable("stringPath")); + public void ToString(){ assertEquals("stringPath", stringPath.toString()); assertEquals("any(stringPath)", stringPath.any().toString()); assertEquals("eqIc(any(stringPath),X)", stringPath.any().equalsIgnoreCase("X").toString()); } + + @Test + public void GetElementType(){ + assertEquals(String.class, stringPath.getElementType()); + } + + @Test + public void GetParameter(){ + assertEquals(String.class, stringPath.getParameter(0)); + } } diff --git a/querydsl-core/src/test/java/com/mysema/query/types/path/ListPathTest.java b/querydsl-core/src/test/java/com/mysema/query/types/path/ListPathTest.java index 00f537d9c..e61f35701 100644 --- a/querydsl-core/src/test/java/com/mysema/query/types/path/ListPathTest.java +++ b/querydsl-core/src/test/java/com/mysema/query/types/path/ListPathTest.java @@ -9,17 +9,27 @@ import com.mysema.query.types.PathMetadataFactory; public class ListPathTest { + private ListPath stringPath = new ListPath( + String.class, StringPath.class, + PathMetadataFactory.forVariable("stringPath")); + @Test - public void test(){ - ListPath stringPath = new ListPath( - String.class, StringPath.class, - PathMetadataFactory.forVariable("stringPath")); + public void ToString(){ assertEquals("stringPath", stringPath.toString()); assertEquals("any(stringPath)", stringPath.any().toString()); assertEquals("eqIc(stringPath.get(0),X)", stringPath.get(0).equalsIgnoreCase("X").toString()); assertEquals("eqIc(any(stringPath),X)", stringPath.any().equalsIgnoreCase("X").toString()); - assertEquals("stringPath.get(0)", stringPath.get(ConstantImpl.create(0)).toString()); - + assertEquals("stringPath.get(0)", stringPath.get(ConstantImpl.create(0)).toString()); + } + + @Test + public void GetElementType(){ + assertEquals(String.class, stringPath.getElementType()); + } + + @Test + public void GetParameter(){ + assertEquals(String.class, stringPath.getParameter(0)); } } diff --git a/querydsl-core/src/test/java/com/mysema/query/types/path/MapPathTest.java b/querydsl-core/src/test/java/com/mysema/query/types/path/MapPathTest.java index d33115d16..e24ba86ee 100644 --- a/querydsl-core/src/test/java/com/mysema/query/types/path/MapPathTest.java +++ b/querydsl-core/src/test/java/com/mysema/query/types/path/MapPathTest.java @@ -8,11 +8,28 @@ import com.mysema.query.types.ConstantImpl; public class MapPathTest { + private MapPath mapPath = new MapPath(String.class, String.class, StringPath.class, "p"); + @Test public void Get() { - MapPath mapPath = new MapPath(String.class, String.class, StringPath.class, "p"); assertNotNull(mapPath.get("X")); assertNotNull(mapPath.get(ConstantImpl.create("X"))); } + + @Test + public void GetKeytType(){ + assertEquals(String.class, mapPath.getKeyType()); + } + + @Test + public void GetValueType(){ + assertEquals(String.class, mapPath.getValueType()); + } + + @Test + public void GetParameter(){ + assertEquals(String.class, mapPath.getParameter(0)); + assertEquals(String.class, mapPath.getParameter(1)); + } } diff --git a/querydsl-core/src/test/java/com/mysema/query/types/path/PathInitsTest.java b/querydsl-core/src/test/java/com/mysema/query/types/path/PathInitsTest.java index a30588846..2234eda25 100644 --- a/querydsl-core/src/test/java/com/mysema/query/types/path/PathInitsTest.java +++ b/querydsl-core/src/test/java/com/mysema/query/types/path/PathInitsTest.java @@ -16,14 +16,14 @@ public class PathInitsTest { public void Default(){ assertFalse(PathInits.DEFAULT.isInitialized("")); } - + @Test - public void test(){ - PathInits Inits = new PathInits(".2").get(""); - assertFalse(Inits.isInitialized("1")); - assertTrue(Inits.isInitialized("2")); + public void IsInitialized(){ + PathInits inits = new PathInits(".2").get(""); + assertFalse(inits.isInitialized("1")); + assertTrue(inits.isInitialized("2")); } - + @Test public void Wildcard(){ assertTrue(new PathInits("*").isInitialized("")); @@ -31,8 +31,8 @@ public class PathInitsTest { @Test public void Wildcard2(){ - PathInits Inits = new PathInits(".*").get(""); - assertTrue(Inits.isInitialized("1")); - assertTrue(Inits.isInitialized("2")); + PathInits inits = new PathInits(".*").get(""); + assertTrue(inits.isInitialized("1")); + assertTrue(inits.isInitialized("2")); } } diff --git a/querydsl-core/src/test/java/com/mysema/query/types/path/PathTest.java b/querydsl-core/src/test/java/com/mysema/query/types/path/PathTest.java index 1239eedc6..aa46e9284 100644 --- a/querydsl-core/src/test/java/com/mysema/query/types/path/PathTest.java +++ b/querydsl-core/src/test/java/com/mysema/query/types/path/PathTest.java @@ -30,6 +30,8 @@ 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.PathMetadataFactory; +import com.mysema.query.types.Templates; import com.mysema.query.types.ToStringVisitor; import com.mysema.util.AnnotatedElementAdapter; @@ -137,6 +139,38 @@ public class PathTest { assertEquals(new TimePath(Time.class,"p"), new PathImpl(Time.class, "p")); } + @SuppressWarnings("unchecked") + @Test + public void Various_Properties(){ + Path parent = new PathImpl(Object.class, "parent"); + List> paths = new ArrayList>(); + paths.add(new ArrayPath(String[].class, parent, "p")); + paths.add(new BeanPath(Object.class, parent, "p")); + paths.add(new BooleanPath(parent, "p")); + paths.add(new CollectionPath(String.class, StringPath.class, parent, "p")); + paths.add(new ComparablePath(String.class, parent, "p")); + paths.add(new DatePath(Date.class, parent, "p")); + paths.add(new DateTimePath(Date.class, parent, "p")); + paths.add(new EnumPath(ExampleEnum.class, parent, "p")); + paths.add(new ListPath(String.class, StringPath.class, parent, "p")); + paths.add(new MapPath(String.class, String.class, StringPath.class, parent, "p")); + paths.add(new NumberPath(Integer.class, parent, "p")); + paths.add(new SetPath(String.class, StringPath.class, parent, "p")); + paths.add(new SimplePath(String.class, parent, "p")); + paths.add(new StringPath(parent, "p")); + paths.add(new TimePath(Time.class, parent, "p")); + + for (Path path : paths){ + Path other = new PathImpl(path.getType(), PathMetadataFactory.forProperty(parent, "p")); + assertEquals(path.toString(), path.accept(ToStringVisitor.DEFAULT, Templates.DEFAULT)); + assertEquals(path.hashCode(), other.hashCode()); + assertEquals(path, other); + assertNotNull(path.getMetadata()); + assertNotNull(path.getType()); + assertEquals(parent, path.getRoot()); + } + } + @SuppressWarnings("unchecked") @Test public void Various(){ @@ -152,6 +186,7 @@ public class PathTest { paths.add(new ListPath(String.class, StringPath.class, "p")); paths.add(new MapPath(String.class, String.class, StringPath.class, "p")); paths.add(new NumberPath(Integer.class,"p")); + paths.add(new SetPath(String.class, StringPath.class, "p")); paths.add(new SimplePath(String.class,"p")); paths.add(new StringPath("p")); paths.add(new TimePath(Time.class,"p")); diff --git a/querydsl-core/src/test/java/com/mysema/query/types/path/SetPathTest.java b/querydsl-core/src/test/java/com/mysema/query/types/path/SetPathTest.java index 7a679ea7a..7ea075da6 100644 --- a/querydsl-core/src/test/java/com/mysema/query/types/path/SetPathTest.java +++ b/querydsl-core/src/test/java/com/mysema/query/types/path/SetPathTest.java @@ -8,14 +8,25 @@ import com.mysema.query.types.PathMetadataFactory; public class SetPathTest { + private SetPath stringPath = new SetPath( + String.class, StringPath.class, + PathMetadataFactory.forVariable("stringPath")); + @Test - public void test(){ - SetPath stringPath = new SetPath( - String.class, StringPath.class, - PathMetadataFactory.forVariable("stringPath")); + public void ToString(){ assertEquals("stringPath", stringPath.toString()); assertEquals("any(stringPath)", stringPath.any().toString()); assertEquals("eqIc(any(stringPath),X)", stringPath.any().equalsIgnoreCase("X").toString()); } + + @Test + public void GetElementType(){ + assertEquals(String.class, stringPath.getElementType()); + } + + @Test + public void GetParameter(){ + assertEquals(String.class, stringPath.getParameter(0)); + } }