Since the Jenkins build is broken anyway, I am committing this testcase, which 
exposes a Value Equality issue. The two values should be equal, but are not.


Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/c62ee068
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/c62ee068
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/c62ee068

Branch: refs/heads/ValueSerializationCleaning
Commit: c62ee068d5d82608bb3ab556899220c5ef2d389a
Parents: 65c7df3
Author: Niclas Hedhman <[email protected]>
Authored: Thu Jun 16 18:05:30 2016 +0800
Committer: Niclas Hedhman <[email protected]>
Committed: Thu Jun 16 18:05:30 2016 +0800

----------------------------------------------------------------------
 .../zest/runtime/value/ValueEqualityTest.java   | 43 +++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/c62ee068/core/runtime/src/test/java/org/apache/zest/runtime/value/ValueEqualityTest.java
----------------------------------------------------------------------
diff --git 
a/core/runtime/src/test/java/org/apache/zest/runtime/value/ValueEqualityTest.java
 
b/core/runtime/src/test/java/org/apache/zest/runtime/value/ValueEqualityTest.java
index 91c5868..c88f4ae 100644
--- 
a/core/runtime/src/test/java/org/apache/zest/runtime/value/ValueEqualityTest.java
+++ 
b/core/runtime/src/test/java/org/apache/zest/runtime/value/ValueEqualityTest.java
@@ -19,6 +19,15 @@
  */
 package org.apache.zest.runtime.value;
 
+import java.time.Duration;
+import java.time.Period;
+import java.time.temporal.ChronoUnit;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.zest.api.common.UseDefaults;
+import org.apache.zest.api.property.Property;
+import org.apache.zest.api.value.ValueBuilder;
+import org.apache.zest.test.value.AbstractValueCompositeSerializationTest;
 import org.junit.Test;
 import org.apache.zest.api.association.AssociationStateHolder;
 import org.apache.zest.api.value.ValueComposite;
@@ -55,7 +64,7 @@ public class ValueEqualityTest
     public void assemble( ModuleAssembly module )
         throws AssemblyException
     {
-        module.values( PrimitivesValue.class, Some.class, AnotherSome.class, 
Other.class );
+        module.values( PrimitivesValue.class, Some.class, AnotherSome.class, 
Other.class, ComplexKey.class );
     }
 
     //
@@ -238,4 +247,36 @@ public class ValueEqualityTest
                     some.hashCode(),
                     not( equalTo( anotherSome.hashCode() ) ) );
     }
+
+    @Test
+    public void givenComplexKeyWhenEqualityCheckExpectEqual()
+        throws Exception
+    {
+        Map<String, Map<Duration, Period>> map3 = new HashMap<>();
+        Map<Duration, Period> map4 = new HashMap<>();
+        map4.put( Duration.of( 1000, ChronoUnit.MILLIS ), Period.of( 1, 2, 3 ) 
);
+        map3.put( "habba", map4 );
+        ValueBuilder<ComplexKey> builder1 = 
valueBuilderFactory.newValueBuilder( ComplexKey.class );
+        builder1.prototype().durations().set( map3 );
+        ComplexKey key1 = builder1.newInstance();
+
+        Map<String, Map<Duration, Period>> map1 = new HashMap<>();
+        Map<Duration, Period> map2 = new HashMap<>();
+        map2.put( Duration.of( 1000, ChronoUnit.MILLIS ), Period.of( 1, 2, 3 ) 
);
+        map1.put( "habba", map2 );
+        ValueBuilder<ComplexKey> builder2 = 
valueBuilderFactory.newValueBuilder( ComplexKey.class );
+        builder2.prototype().durations().set( map1 );
+        ComplexKey key2 = builder2.newInstance();
+
+        assertThat( key1, equalTo( key2 ) );
+    }
+
+    public interface ComplexKey
+    {
+        @UseDefaults
+        Property<Map<String, Map<Duration, Period>>> durations();
+    }
+
+
+
 }

Reply via email to