From 4dacd115ccd668936c00b767740ec5ceff3b5d4a Mon Sep 17 00:00:00 2001 From: Vesa Marttila Date: Thu, 15 Sep 2011 11:36:09 +0300 Subject: [PATCH] lp#850693 PathImpl convenience constructor --- .../java/com/mysema/query/types/PathImpl.java | 10 ++++-- .../com/mysema/query/types/path/PathTest.java | 31 ++++++++++++------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/querydsl-core/src/main/java/com/mysema/query/types/PathImpl.java b/querydsl-core/src/main/java/com/mysema/query/types/PathImpl.java index 2fad66b7c..a422aa1e4 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/PathImpl.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/PathImpl.java @@ -13,7 +13,7 @@ import com.mysema.commons.lang.Assert; import com.mysema.util.ReflectionUtils; /** - * PathImpl defines a default implementation of the Path interface + * PathImpl defines a default implementation of the Path interface * * @author tiwe * @@ -33,14 +33,18 @@ public class PathImpl extends ExpressionBase implements Path { public PathImpl(Class type, String variable){ this(type, PathMetadataFactory.forVariable(variable)); } - + public PathImpl(Class type, PathMetadata metadata){ super(type); this.metadata = Assert.notNull(metadata,"metadata"); this.root = metadata.getRoot() != null ? metadata.getRoot() : this; } - @SuppressWarnings("unchecked") + public PathImpl(Class type, Path parent, String property) { + this(type, PathMetadataFactory.forProperty(parent, property)); + } + + @Override public boolean equals(Object o) { if (o == this){ return true; 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 aa46e9284..07ebaed59 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 @@ -38,7 +38,7 @@ import com.mysema.util.AnnotatedElementAdapter; public class PathTest { enum ExampleEnum {A,B} - + public static class Superclass { @Nullable @@ -73,7 +73,7 @@ public class PathTest { } } - + @Test public void GetAnnotatedElement(){ Entity entity = Alias.alias(Entity.class); @@ -120,14 +120,14 @@ public class PathTest { assertNotNull(property4.getAnnotation(Nullable.class)); } - + @SuppressWarnings("unchecked") @Test public void Equals(){ assertEquals(new StringPath("s"), new StringPath("s")); assertEquals(new BooleanPath("b"), new BooleanPath("b")); assertEquals(new NumberPath(Integer.class,"n"), new NumberPath(Integer.class,"n")); - + assertEquals(new ArrayPath(String[].class, "p"), new PathImpl(String.class, "p")); assertEquals(new BooleanPath("p"), new PathImpl(Boolean.class, "p")); assertEquals(new ComparablePath(String.class,"p"), new PathImpl(String.class, "p")); @@ -136,9 +136,9 @@ public class PathTest { assertEquals(new EnumPath(ExampleEnum.class,"p"), new PathImpl(ExampleEnum.class, "p")); assertEquals(new NumberPath(Integer.class,"p"), new PathImpl(Integer.class, "p")); assertEquals(new StringPath("p"), new PathImpl(String.class, "p")); - assertEquals(new TimePath(Time.class,"p"), new PathImpl(Time.class, "p")); + assertEquals(new TimePath(Time.class,"p"), new PathImpl(Time.class, "p")); } - + @SuppressWarnings("unchecked") @Test public void Various_Properties(){ @@ -159,7 +159,7 @@ public class PathTest { 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)); @@ -167,10 +167,10 @@ public class PathTest { assertEquals(path, other); assertNotNull(path.getMetadata()); assertNotNull(path.getType()); - assertEquals(parent, path.getRoot()); + assertEquals(parent, path.getRoot()); } } - + @SuppressWarnings("unchecked") @Test public void Various(){ @@ -190,7 +190,7 @@ public class PathTest { 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)); @@ -198,8 +198,15 @@ public class PathTest { assertEquals(path, other); assertNotNull(path.getMetadata()); assertNotNull(path.getType()); - assertEquals(path, path.getRoot()); + assertEquals(path, path.getRoot()); } } - + + @Test + public void Parent_Path() { + Path person = new PathImpl(Object.class, "person"); + Path name = new PathImpl(String.class, person, "name"); + assertEquals("person.name", name.toString()); + } + }