You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by be...@apache.org on 2021/04/27 12:00:24 UTC

[tapestry-5] branch master updated: TAP5-2674: commons - CoercionTuple.Key#equals fixed (by Volker Lamp)

This is an automated email from the ASF dual-hosted git repository.

benw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git


The following commit(s) were added to refs/heads/master by this push:
     new 1e073f0  TAP5-2674: commons - CoercionTuple.Key#equals fixed (by Volker Lamp)
1e073f0 is described below

commit 1e073f0867afd19ef813dceabbb94a0b8296e279
Author: Benjamin Weidig <be...@netzgut.net>
AuthorDate: Tue Apr 27 13:59:46 2021 +0200

    TAP5-2674: commons - CoercionTuple.Key#equals fixed (by Volker Lamp)
---
 commons/build.gradle                               |  4 +++
 .../tapestry5/commons/services/CoercionTuple.java  | 21 +++++++++----
 .../groovy/commons/specs/CoercionTupleSpec.groovy  | 35 ++++++++++++++++++++++
 3 files changed, 55 insertions(+), 5 deletions(-)

diff --git a/commons/build.gradle b/commons/build.gradle
index 98ae8bf..31859b4 100644
--- a/commons/build.gradle
+++ b/commons/build.gradle
@@ -17,3 +17,7 @@ jar {
 	manifest {	
 	}
 }
+
+test {
+    useJUnit()
+}
\ No newline at end of file
diff --git a/commons/src/main/java/org/apache/tapestry5/commons/services/CoercionTuple.java b/commons/src/main/java/org/apache/tapestry5/commons/services/CoercionTuple.java
index e5d3d62..1a4ab17 100644
--- a/commons/src/main/java/org/apache/tapestry5/commons/services/CoercionTuple.java
+++ b/commons/src/main/java/org/apache/tapestry5/commons/services/CoercionTuple.java
@@ -157,6 +157,16 @@ public final class CoercionTuple<S, T>
     public final class Key 
     {
         
+        protected Class<S> getSourceType()
+        {
+            return sourceType;
+        }
+
+        protected Class<T> getTargetType()
+        {
+            return targetType;
+        }
+        
         @Override
         public String toString() {
             return String.format("%s -> %s", sourceType.getName(), targetType.getName());
@@ -181,18 +191,19 @@ public final class CoercionTuple<S, T>
                 return false;
             if (getClass() != obj.getClass())
                 return false;
-            CoercionTuple other = (CoercionTuple) obj;
+
+            Key other = (Key) obj;
             if (sourceType == null) 
             {
-                if (other.sourceType != null)
+                if (other.getSourceType() != null)
                     return false;
-            } else if (!sourceType.equals(other.sourceType))
+            } else if (!sourceType.equals(other.getSourceType()))
                 return false;
             if (targetType == null) 
             {
-                if (other.targetType != null)
+                if (other.getTargetType() != null)
                     return false;
-            } else if (!targetType.equals(other.targetType))
+            } else if (!targetType.equals(other.getTargetType()))
                 return false;
             return true;
         }
diff --git a/commons/src/test/groovy/commons/specs/CoercionTupleSpec.groovy b/commons/src/test/groovy/commons/specs/CoercionTupleSpec.groovy
new file mode 100644
index 0000000..42ac834
--- /dev/null
+++ b/commons/src/test/groovy/commons/specs/CoercionTupleSpec.groovy
@@ -0,0 +1,35 @@
+package commons.specs
+
+import java.time.LocalDate
+import java.time.LocalTime
+
+import org.apache.tapestry5.commons.services.Coercion
+import org.apache.tapestry5.commons.services.CoercionTuple
+
+import spock.lang.Specification
+
+class CoercionTupleSpec extends Specification {
+
+    def "corcion tuples key equality"() {
+
+        when:
+
+        def tuple1 = CoercionTuple.create(String.class, LocalDate.class, { input ->
+            return LocalDate.parse(input)
+        })
+
+        def tuple2 = CoercionTuple.create(String.class, LocalDate.class, { input ->
+            return null
+        })
+
+        def key1 = tuple1.getKey()
+        def key2 = tuple2.getKey()
+
+        then:
+
+        tuple1.equals(tuple2) == false
+        key1.equals(key1) == true
+        key1.equals(new String()) == false
+        key1.equals(key2)
+    }
+}