CoderProviders { public static CoderProvider fromStaticMethods(Class<?> rawType, Class<?> coderClazz) { checkArgument( Coder.class.isAssignableFrom(coderClazz), "%s is not a subtype of %s", coderClazz.getName(), Coder.class.getSimpleName()); return new CoderProviderFromStaticMethods(rawType, coderClazz); } private  CoderProviders(); static CoderProvider fromStaticMethods(Class<?> rawType, Class<?> coderClazz); static CoderProvider forCoder(TypeDescriptor<?> type, Coder<?> coder);  }
@Test public void testCoderProvidersFromStaticMethodsForParameterlessTypes() throws Exception { CoderProvider factory = CoderProviders.fromStaticMethods(String.class, StringUtf8Coder.class); assertEquals( StringUtf8Coder.of(), factory.coderFor(TypeDescriptors.strings(), Collections.emptyList())); factory = CoderProviders.fromStaticMethods(Double.class, DoubleCoder.class); assertEquals( DoubleCoder.of(), factory.coderFor(TypeDescriptors.doubles(), Collections.emptyList())); factory = CoderProviders.fromStaticMethods(byte[].class, ByteArrayCoder.class); assertEquals( ByteArrayCoder.of(), factory.coderFor(TypeDescriptor.of(byte[].class), Collections.emptyList())); }
@Test public void testKvCoderProvider() throws Exception { TypeDescriptor<KV<Double, Double>> type = TypeDescriptors.kvs(TypeDescriptors.doubles(), TypeDescriptors.doubles()); CoderProvider kvCoderProvider = CoderProviders.fromStaticMethods(KV.class, KvCoder.class); assertEquals( KvCoder.of(DoubleCoder.of(), DoubleCoder.of()), kvCoderProvider.coderFor(type, Arrays.asList(DoubleCoder.of(), DoubleCoder.of()))); }
@Test public void testListCoderProvider() throws Exception { TypeDescriptor<List<Double>> type = TypeDescriptors.lists(TypeDescriptors.doubles()); CoderProvider listCoderProvider = CoderProviders.fromStaticMethods(List.class, ListCoder.class); assertEquals( ListCoder.of(DoubleCoder.of()), listCoderProvider.coderFor(type, Arrays.asList(DoubleCoder.of()))); }
@Test public void testIterableCoderProvider() throws Exception { TypeDescriptor<Iterable<Double>> type = TypeDescriptors.iterables(TypeDescriptors.doubles()); CoderProvider iterableCoderProvider = CoderProviders.fromStaticMethods(Iterable.class, IterableCoder.class); assertEquals( IterableCoder.of(DoubleCoder.of()), iterableCoderProvider.coderFor(type, Arrays.asList(DoubleCoder.of()))); }