beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhalp...@apache.org
Subject [1/2] incubator-beam git commit: Use EqualsTester in ProxyInvocationHandlerTest
Date Mon, 08 Aug 2016 05:17:36 GMT
Repository: incubator-beam
Updated Branches:
  refs/heads/master c584b37b8 -> 7629f972c


Use EqualsTester in ProxyInvocationHandlerTest

This tests the equality groups instead of manual assertions, including
same-reference equality.


Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/a0e03ecd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/a0e03ecd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/a0e03ecd

Branch: refs/heads/master
Commit: a0e03ecdbdf5ad1256fa5767b10ac0cb6e76413f
Parents: c584b37
Author: Thomas Groh <tgroh@google.com>
Authored: Fri Aug 5 15:21:12 2016 -0700
Committer: Dan Halperin <dhalperi@google.com>
Committed: Sun Aug 7 22:17:25 2016 -0700

----------------------------------------------------------------------
 .../sdk/options/ProxyInvocationHandlerTest.java | 34 +++++---------------
 1 file changed, 8 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/a0e03ecd/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ProxyInvocationHandlerTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ProxyInvocationHandlerTest.java
b/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ProxyInvocationHandlerTest.java
index c4c5c1c..148b590 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ProxyInvocationHandlerTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ProxyInvocationHandlerTest.java
@@ -22,8 +22,6 @@ import static org.apache.beam.sdk.transforms.display.DisplayDataMatchers.hasKey;
 import static org.apache.beam.sdk.transforms.display.DisplayDataMatchers.hasNamespace;
 import static org.apache.beam.sdk.transforms.display.DisplayDataMatchers.hasType;
 import static org.apache.beam.sdk.transforms.display.DisplayDataMatchers.hasValue;
-
-import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.allOf;
 import static org.hamcrest.Matchers.hasItem;
 import static org.hamcrest.Matchers.not;
@@ -31,6 +29,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 import org.apache.beam.sdk.transforms.display.DisplayData;
@@ -39,11 +38,13 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Maps;
+import com.google.common.testing.EqualsTester;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.databind.JsonMappingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
+
 import org.hamcrest.Matchers;
 import org.joda.time.Instant;
 import org.junit.Rule;
@@ -216,37 +217,18 @@ public class ProxyInvocationHandlerTest {
   }
 
   @Test
-  public void testEquals() throws Exception {
-    ProxyInvocationHandler handler = new ProxyInvocationHandler(Maps.<String, Object>newHashMap());
-    Simple proxy = handler.as(Simple.class);
-    JLSDefaults sameAsProxy = proxy.as(JLSDefaults.class);
-    ProxyInvocationHandler handler2 = new ProxyInvocationHandler(Maps.<String, Object>newHashMap());
-    Simple proxy2 = handler2.as(Simple.class);
-    JLSDefaults sameAsProxy2 = proxy2.as(JLSDefaults.class);
-    assertTrue(handler.equals(proxy));
-    assertTrue(proxy.equals(proxy));
-    assertTrue(proxy.equals(sameAsProxy));
-    assertFalse(handler.equals(handler2));
-    assertFalse(proxy.equals(proxy2));
-    assertFalse(proxy.equals(sameAsProxy2));
-  }
-
-  @Test
-  public void testHashCode() throws Exception {
+  public void testEqualsAndHashCode() throws Exception {
     ProxyInvocationHandler handler = new ProxyInvocationHandler(Maps.<String, Object>newHashMap());
     Simple proxy = handler.as(Simple.class);
     JLSDefaults sameAsProxy = proxy.as(JLSDefaults.class);
-
     ProxyInvocationHandler handler2 = new ProxyInvocationHandler(Maps.<String, Object>newHashMap());
     Simple proxy2 = handler2.as(Simple.class);
     JLSDefaults sameAsProxy2 = proxy2.as(JLSDefaults.class);
 
-    // Hashcode comparisons below depend on random numbers, so could fail if seed changes.
-    assertTrue(handler.hashCode() == proxy.hashCode());
-    assertTrue(proxy.hashCode() == sameAsProxy.hashCode());
-    assertFalse(handler.hashCode() == handler2.hashCode());
-    assertFalse(proxy.hashCode() == proxy2.hashCode());
-    assertFalse(proxy.hashCode() == sameAsProxy2.hashCode());
+    new EqualsTester()
+        .addEqualityGroup(handler, proxy, sameAsProxy)
+        .addEqualityGroup(handler2, proxy2, sameAsProxy2)
+        .testEquals();
   }
 
   @Test


Mime
View raw message