db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1634271 - in /db/torque/torque4/trunk/torque-runtime/src: main/java/org/apache/torque/sql/whereclausebuilder/EnumValueBuilder.java test/java/org/apache/torque/sql/SqlBuilderTest.java
Date Sun, 26 Oct 2014 03:19:30 GMT
Author: tfischer
Date: Sun Oct 26 03:19:30 2014
New Revision: 1634271

URL: http://svn.apache.org/r1634271
Log:
TORQUE-331 - test failure if enum does not have a getValue method

Modified:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/EnumValueBuilder.java
    db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTest.java

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/EnumValueBuilder.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/EnumValueBuilder.java?rev=1634271&r1=1634270&r2=1634271&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/EnumValueBuilder.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/EnumValueBuilder.java
Sun Oct 26 03:19:30 2014
@@ -90,7 +90,7 @@ public class EnumValueBuilder extends Ab
         }
         catch (NoSuchMethodException e)
         {
-            throw new TorqueException("An enum is given as Criterion value but its class,
" + clazz.getName()
+            throw new TorqueException("An enum is used as Criterion value but its class,
" + clazz.getName()
                     + ", does not have a parameterless getValue() method");
         }
         if (getValueMethod.getReturnType().equals(Void.class))

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTest.java?rev=1634271&r1=1634270&r2=1634271&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTest.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTest.java
Sun Oct 26 03:19:30 2014
@@ -2378,11 +2378,11 @@ public class SqlBuilderTest extends Base
         assertEquals(1, query.getPreparedStatementReplacements().get(3));
     }
 
-    public void testValueHolder() throws Exception
+    public void testEnumValues() throws Exception
     {
         Criteria criteria = new Criteria()
-            .where(new ColumnImpl("table.column1"), ValueHolderImpl.A)
-            .and(ValueHolderImpl.B, new ColumnImpl("table.column2"))
+            .where(new ColumnImpl("table.column1"), EnumWithValueMethod.A)
+            .and(EnumWithValueMethod.B, new ColumnImpl("table.column2"))
             .addSelectColumn(new ColumnImpl("table.column1"));
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals("SELECT table.column1 FROM table "
@@ -2394,7 +2394,28 @@ public class SqlBuilderTest extends Base
         assertEquals("B", query.getPreparedStatementReplacements().get(1));
     }
 
-    public static enum ValueHolderImpl
+    /**
+     * Tests that an enum which does not have a getValue() method cannot be added as select
value.
+     */
+    public void testEnumValuesNoGetValueMethod() throws Exception
+    {
+        Criteria criteria = new Criteria()
+        .where(new ColumnImpl("table.column1"), EnumWithoutValueMethod.A);
+        try
+        {
+            SqlBuilder.buildQuery(criteria);
+            fail("Exception expected");
+        }
+        catch (TorqueException e)
+        {
+            assertEquals("An enum is used as Criterion value but its class, "
+                    + "org.apache.torque.sql.SqlBuilderTest$EnumWithoutValueMethod, "
+                    + "does not have a parameterless getValue() method",
+                e.getMessage());
+        }
+    }
+
+    public static enum EnumWithValueMethod
     {
         A,
         B,
@@ -2405,9 +2426,16 @@ public class SqlBuilderTest extends Base
             return toString();
         }
 
-        public static ValueHolderImpl getByValue(final String arg)
+        public static EnumWithValueMethod getByValue(final String arg)
         {
             return valueOf(arg);
         }
     }
+
+    public static enum EnumWithoutValueMethod
+    {
+        A,
+        B,
+        C;
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message