From e2612fb9e1f26b8cfc51f99ea9658dc2f84166e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Westk=C3=A4mper?= Date: Tue, 20 Oct 2009 09:48:32 +0000 Subject: [PATCH] improved tests --- .../com/mysema/query/domain/AbstractTest.java | 13 ++++ .../query/domain/InterfaceTypeTest.java | 16 +++-- .../mysema/query/domain/SimpleTypesTest.java | 67 ++++++++++++++++--- 3 files changed, 81 insertions(+), 15 deletions(-) create mode 100644 querydsl-apt/src/test/java/com/mysema/query/domain/AbstractTest.java diff --git a/querydsl-apt/src/test/java/com/mysema/query/domain/AbstractTest.java b/querydsl-apt/src/test/java/com/mysema/query/domain/AbstractTest.java new file mode 100644 index 000000000..6d76b9e2a --- /dev/null +++ b/querydsl-apt/src/test/java/com/mysema/query/domain/AbstractTest.java @@ -0,0 +1,13 @@ +package com.mysema.query.domain; + +import static org.junit.Assert.assertEquals; + +public abstract class AbstractTest { + + public Class cl; + + protected void match(Class expectedType, String name) throws SecurityException, NoSuchFieldException{ + assertEquals(cl.getSimpleName()+"."+name + " failed", expectedType, cl.getField(name).getType()); + } + +} diff --git a/querydsl-apt/src/test/java/com/mysema/query/domain/InterfaceTypeTest.java b/querydsl-apt/src/test/java/com/mysema/query/domain/InterfaceTypeTest.java index a3f82c62b..22ee4080c 100644 --- a/querydsl-apt/src/test/java/com/mysema/query/domain/InterfaceTypeTest.java +++ b/querydsl-apt/src/test/java/com/mysema/query/domain/InterfaceTypeTest.java @@ -1,7 +1,5 @@ package com.mysema.query.domain; -import static org.junit.Assert.assertEquals; - import java.util.List; import org.junit.Test; @@ -11,7 +9,7 @@ import com.mysema.query.types.path.PEntityList; import com.mysema.query.types.path.PNumber; -public class InterfaceTypeTest { +public class InterfaceTypeTest extends AbstractTest{ @QueryEntity public interface InterfaceType { @@ -56,22 +54,26 @@ public class InterfaceTypeTest { @Test public void QInterfaceType_reation() throws SecurityException, NoSuchFieldException{ - assertEquals(QInterfaceType.class, QInterfaceType.class.getField("relation").getType()); + cl = QInterfaceType.class; + match(QInterfaceType.class, "relation"); } @Test public void QInterfaceType_reation2() throws SecurityException, NoSuchFieldException{ - assertEquals(PEntityList.class, QInterfaceType.class.getField("relation2").getType()); + cl = QInterfaceType.class; + match(PEntityList.class, "relation2"); } @Test public void QInterfaceType_reation3() throws SecurityException, NoSuchFieldException{ - assertEquals(PEntityList.class, QInterfaceType.class.getField("relation3").getType()); + cl = QInterfaceType.class; + match(PEntityList.class, "relation3"); } @Test public void QInterfaceType_reation4() throws SecurityException, NoSuchFieldException{ - assertEquals(PNumber.class, QInterfaceType.class.getField("relation4").getType()); + cl = QInterfaceType.class; + match(PNumber.class, "relation4"); } @Test diff --git a/querydsl-apt/src/test/java/com/mysema/query/domain/SimpleTypesTest.java b/querydsl-apt/src/test/java/com/mysema/query/domain/SimpleTypesTest.java index 76864ec70..643cf7a0b 100644 --- a/querydsl-apt/src/test/java/com/mysema/query/domain/SimpleTypesTest.java +++ b/querydsl-apt/src/test/java/com/mysema/query/domain/SimpleTypesTest.java @@ -1,7 +1,5 @@ package com.mysema.query.domain; -import static org.junit.Assert.assertEquals; - import java.io.Serializable; import java.math.BigDecimal; import java.util.Date; @@ -12,10 +10,13 @@ import org.junit.Test; import com.mysema.query.annotations.QueryEntity; import com.mysema.query.annotations.QueryTransient; import com.mysema.query.types.path.PComparable; +import com.mysema.query.types.path.PDateTime; import com.mysema.query.types.path.PNumber; import com.mysema.query.types.path.PSimple; +import com.mysema.query.types.path.PString; +import com.mysema.query.types.path.PTime; -public class SimpleTypesTest { +public class SimpleTypesTest extends AbstractTest{ public static class CustomLiteral { @@ -100,30 +101,80 @@ public class SimpleTypesTest { @QueryTransient String skipMe; } + + @Test + public void testSimpleTypes() throws SecurityException, NoSuchFieldException{ + cl = QSimpleTypes.class; + match(PNumber.class, "id"); + match(PNumber.class, "bigDecimal"); + match(PNumber.class, "bbyte"); + match(PNumber.class, "bbyte2"); + match(PNumber.class, "ddouble"); + match(PNumber.class, "ddouble2"); + match(PNumber.class, "ffloat"); + match(PNumber.class, "ffloat2"); + match(PNumber.class, "iint"); + match(PNumber.class, "iint2"); + match(PNumber.class, "llong"); + match(PNumber.class, "llong2"); + + match(PComparable.class, "cchar"); + match(PComparable.class, "cchar2"); + + match(PString.class, "sstring"); + + match(PDateTime.class, "date"); + match(PDateTime.class, "timestamp"); + + match(PTime.class, "time"); + + match(PSimple.class, "llocale"); + match(PSimple.class, "serializable"); + match(PSimple.class, "object"); + match(PSimple.class, "clazz"); + match(PSimple.class, "packageAsLiteral"); + +// CustomLiteral customLiteral; +// CustomComparableLiteral customComparableLiteral; +// CustomNumber customNumber; +// CustomComparableNumber customComparableNumber; + + match(PSimple.class, "clob"); + match(PSimple.class, "blob"); + } @Test public void customLiteral() throws SecurityException, NoSuchFieldException{ - assertEquals(PSimple.class, QSimpleTypes.class.getField("customLiteral").getType()); + cl = QSimpleTypes.class; + match(PSimple.class, "customLiteral"); } @Test public void customComparableLiteral() throws SecurityException, NoSuchFieldException{ - assertEquals(PComparable.class, QSimpleTypes.class.getField("customComparableLiteral").getType()); + cl = QSimpleTypes.class; + match(PComparable.class, "customComparableLiteral"); } @Test public void customNumber() throws SecurityException, NoSuchFieldException{ - assertEquals(PSimple.class, QSimpleTypes.class.getField("customNumber").getType()); + cl = QSimpleTypes.class; + match(PSimple.class, "customNumber"); } @Test public void customComparableNumber() throws SecurityException, NoSuchFieldException{ - assertEquals(PNumber.class, QSimpleTypes.class.getField("customComparableNumber").getType()); + cl = QSimpleTypes.class; + match(PNumber.class, "customComparableNumber"); } @Test(expected=NoSuchFieldException.class) - public void skippedFields() throws SecurityException, NoSuchFieldException { + public void skippedField1() throws SecurityException, NoSuchFieldException { QSimpleTypes.class.getField("skipMe"); } + + @Test(expected=NoSuchFieldException.class) + public void skippedField2() throws SecurityException, NoSuchFieldException { + QSimpleTypes.class.getField("test"); + } }