beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject [2/3] incubator-beam git commit: Add a couple more tests for TypeDescriptors
Date Wed, 11 May 2016 17:56:58 GMT
Add a couple more tests for TypeDescriptors


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

Branch: refs/heads/master
Commit: 77fe01620c96d7dae62597c52c16e82608dc1b84
Parents: a49ac72
Author: Kenneth Knowles <klk@google.com>
Authored: Tue May 10 13:37:40 2016 -0700
Committer: Kenneth Knowles <klk@google.com>
Committed: Tue May 10 13:39:43 2016 -0700

----------------------------------------------------------------------
 .../apache/beam/sdk/values/TypeDescriptors.java |  2 +-
 .../beam/sdk/values/TypeDescriptorTest.java     |  9 +-
 .../beam/sdk/values/TypeDescriptorsTest.java    | 87 ++++++--------------
 3 files changed, 31 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/77fe0162/sdks/java/core/src/main/java/org/apache/beam/sdk/values/TypeDescriptors.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/values/TypeDescriptors.java
b/sdks/java/core/src/main/java/org/apache/beam/sdk/values/TypeDescriptors.java
index 4b153e6..b833c10 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/values/TypeDescriptors.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/values/TypeDescriptors.java
@@ -160,7 +160,7 @@ public class TypeDescriptors {
    * @return A {@link TypeDescriptor} for {@link KV}
    */
   public static <K, V> TypeDescriptor<KV<K, V>>
-    kv(TypeDescriptor<K> key, TypeDescriptor<V> value) {
+    kvs(TypeDescriptor<K> key, TypeDescriptor<V> value) {
     TypeDescriptor<KV<K, V>> typeDescriptor =
         new TypeDescriptor<KV<K, V>>() {}
       .<K> where(new TypeParameter<K>() {}, key)

http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/77fe0162/sdks/java/core/src/test/java/org/apache/beam/sdk/values/TypeDescriptorTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/values/TypeDescriptorTest.java
b/sdks/java/core/src/test/java/org/apache/beam/sdk/values/TypeDescriptorTest.java
index af48af0..162c991 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/values/TypeDescriptorTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/values/TypeDescriptorTest.java
@@ -50,8 +50,13 @@ public class TypeDescriptorTest {
 
   @Test
   public void testTypeDescriptorImmediate() throws Exception {
-    TypeDescriptor<String> descriptor = new TypeDescriptor<String>(){};
-    assertEquals(String.class, descriptor.getRawType());
+    assertEquals(Boolean.class, new TypeDescriptor<Boolean>() {}.getRawType());
+    assertEquals(Double.class, new TypeDescriptor<Double>() {}.getRawType());
+    assertEquals(Float.class, new TypeDescriptor<Float>() {}.getRawType());
+    assertEquals(Integer.class, new TypeDescriptor<Integer>() {}.getRawType());
+    assertEquals(Long.class, new TypeDescriptor<Long>() {}.getRawType());
+    assertEquals(Short.class, new TypeDescriptor<Short>() {}.getRawType());
+    assertEquals(String.class, new TypeDescriptor<String>() {}.getRawType());
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/77fe0162/sdks/java/core/src/test/java/org/apache/beam/sdk/values/TypeDescriptorsTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/values/TypeDescriptorsTest.java
b/sdks/java/core/src/test/java/org/apache/beam/sdk/values/TypeDescriptorsTest.java
index a194083..59acdf0 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/values/TypeDescriptorsTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/values/TypeDescriptorsTest.java
@@ -17,100 +17,59 @@
  */
 package org.apache.beam.sdk.values;
 
-import static org.junit.Assert.assertEquals;
+import static org.apache.beam.sdk.values.TypeDescriptors.integers;
+import static org.apache.beam.sdk.values.TypeDescriptors.iterables;
+import static org.apache.beam.sdk.values.TypeDescriptors.kvs;
+import static org.apache.beam.sdk.values.TypeDescriptors.lists;
+import static org.apache.beam.sdk.values.TypeDescriptors.sets;
+import static org.apache.beam.sdk.values.TypeDescriptors.strings;
 
-import com.google.common.reflect.TypeToken;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
 
-import java.math.BigDecimal;
 import java.util.List;
 import java.util.Set;
 
 /**
- * Tests for TypeDescriptors.
+ * Tests for {@link TypeDescriptors}.
  */
 @RunWith(JUnit4.class)
 public class TypeDescriptorsTest {
   @Test
   public void testTypeDescriptorsIterables() throws Exception {
-    TypeDescriptor<Iterable<String>> descriptor =
-        TypeDescriptors.iterables(TypeDescriptors.strings());
-    TypeToken<Iterable<String>> token = new TypeToken<Iterable<String>>(){};
-    assertEquals(token.getType(), descriptor.getType());
+    TypeDescriptor<Iterable<String>> descriptor = iterables(strings());
+    assertEquals(descriptor, new TypeDescriptor<Iterable<String>>() {});
   }
 
   @Test
   public void testTypeDescriptorsSets() throws Exception {
-    TypeDescriptor<Set<String>> descriptor =
-        TypeDescriptors.sets(TypeDescriptors.strings());
-    TypeToken<Set<String>> token = new TypeToken<Set<String>>(){};
-    assertEquals(token.getType(), descriptor.getType());
+    TypeDescriptor<Set<String>> descriptor = sets(strings());
+    assertEquals(descriptor, new TypeDescriptor<Set<String>>() {});
   }
 
   @Test
   public void testTypeDescriptorsKV() throws Exception {
     TypeDescriptor<KV<String, Integer>> descriptor =
-        TypeDescriptors.kv(TypeDescriptors.strings(), TypeDescriptors.integers());
-    TypeToken<KV<String, Integer>> token = new TypeToken<KV<String, Integer>>(){};
-    assertEquals(token.getType(), descriptor.getType());
+        kvs(strings(), integers());
+    assertEquals(descriptor, new TypeDescriptor<KV<String, Integer>>() {});
   }
 
   @Test
   public void testTypeDescriptorsLists() throws Exception {
-    TypeDescriptor<List<String>> descriptor =
-        TypeDescriptors.lists(TypeDescriptors.strings());
-    TypeToken<List<String>> token = new TypeToken<List<String>>(){};
-    assertEquals(token.getType(), descriptor.getType());
-  }
-
-  @Test
-  public void testTypeDescriptorsBoolean() throws Exception {
-    TypeDescriptor<Boolean> descriptor = new TypeDescriptor<Boolean>(){};
-    assertEquals(Boolean.class, descriptor.getRawType());
-  }
-
-  @Test
-  public void testTypeDescriptorsDouble() throws Exception {
-    TypeDescriptor<Double> descriptor = new TypeDescriptor<Double>(){};
-    assertEquals(Double.class, descriptor.getRawType());
-  }
-
-  @Test
-  public void testTypeDescriptorsFloat() throws Exception {
-    TypeDescriptor<Float> descriptor = new TypeDescriptor<Float>(){};
-    assertEquals(Float.class, descriptor.getRawType());
-  }
-
-  @Test
-  public void testTypeDescriptorsInteger() throws Exception {
-    TypeDescriptor<Integer> descriptor = new TypeDescriptor<Integer>(){};
-    assertEquals(Integer.class, descriptor.getRawType());
-  }
-
-  @Test
-  public void testTypeDescriptorsLong() throws Exception {
-    TypeDescriptor<Long> descriptor = new TypeDescriptor<Long>(){};
-    assertEquals(Long.class, descriptor.getRawType());
-  }
-
-  @Test
-  public void testTypeDescriptorsShort() throws Exception {
-    TypeDescriptor<Short> descriptor = new TypeDescriptor<Short>(){};
-    assertEquals(Short.class, descriptor.getRawType());
-  }
-
-  @Test
-  public void testTypeDescriptorsBigDecimal() throws Exception {
-    TypeDescriptor<BigDecimal> descriptor = new TypeDescriptor<BigDecimal>(){};
-    assertEquals(BigDecimal.class, descriptor.getRawType());
+    TypeDescriptor<List<String>> descriptor = lists(strings());
+    assertEquals(descriptor, new TypeDescriptor<List<String>>() {});
+    assertNotEquals(descriptor, new TypeDescriptor<List<Boolean>>() {});
   }
 
   @Test
-  public void testTypeDescriptorsString() throws Exception {
-    TypeDescriptor<String> descriptor = new TypeDescriptor<String>(){};
-    assertEquals(String.class, descriptor.getRawType());
+  public void testTypeDescriptorsListsOfLists() throws Exception {
+    TypeDescriptor<List<List<String>>> descriptor = lists(lists(strings()));
+    assertEquals(descriptor, new TypeDescriptor<List<List<String>>>() {});
+    assertNotEquals(descriptor, new TypeDescriptor<List<String>>() {});
+    assertNotEquals(descriptor, new TypeDescriptor<List<Boolean>>() {});
   }
 }


Mime
View raw message