public static CollectionType setOf( Class<?> collectedType ) { return new CollectionType( Set.class, ValueType.of( collectedType ) ); } private ValueType collectedType;
public static CollectionType collectionOf( Class<?> collectedType ) { return new CollectionType( Collection.class, ValueType.of( collectedType ) ); }
public static CollectionType listOf( Class<?> collectedType ) { return new CollectionType( List.class, ValueType.of( collectedType ) ); }
@Test public void givenAtDateFormatWhenConvertingFromSerializedStateExpectValidDate() throws Exception { long tstamp = System.currentTimeMillis(); CollectionType collectionType = new CollectionType( List.class, dateType ); List<Date> value = valueDeserializer.deserialize( collectionType, "[\"@" + tstamp + "@\"]" ); assertEquals( new Date( tstamp ), value.get( 0 ) ); }
@Test public void givenISO6801DateFormatWhenConvertingFromSerializedStateExpectValidDate() throws Exception { CollectionType collectionType = new CollectionType( List.class, dateType ); List<Date> value = valueDeserializer.deserialize( collectionType, "[\"2009-08-12T14:54:27.895+0800\"]" ); assertEquals( new DateTime( "2009-08-12T06:54:27.895Z", DateTimeZone.UTC ).toDate(), value.get( 0 ) ); }
@Test public void givenMicrosoftDateFormatWhenConvertingFromSerializedStateExpectValidDate() throws Exception { long tstamp = System.currentTimeMillis(); CollectionType collectionType = new CollectionType( List.class, dateType ); List<Date> value = valueDeserializer.deserialize( collectionType, "[\"/Date(" + tstamp + ")/\"]" ); assertEquals( new Date( tstamp ), value.get( 0 ) ); } }
@Test public void givenListOfValueCompositesAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception { String output = valueSerialization.serialize( valueCompositesList() ); ValueCompositeType valueType = module.valueDescriptor( SomeValue.class.getName() ).valueType(); CollectionType collectionType = new CollectionType( List.class, valueType ); List<SomeValue> value = valueSerialization.deserialize( collectionType, output ); assertEquals( valueCompositesList(), value ); }
@Test public void givenCollectionTypeWithByteAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception { String output = valueSerialization.serialize( byteCollection() ); CollectionType collectionType = new CollectionType( Set.class, new ValueType( Byte.class ) ); Set<Byte> list = valueSerialization.deserialize( collectionType, output ); assertEquals( new LinkedHashSet<Byte>( byteCollection() ), list ); }
@Test public void givenIterableTypeWithByteAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception { String output = valueSerialization.serialize( Iterables.iterable( byteCollection().toArray() ) ); CollectionType collectionType = new CollectionType( List.class, new ValueType( Byte.class ) ); List<Byte> list = valueSerialization.deserialize( collectionType, output ); assertEquals( byteCollection(), list ); }
@Test public void givenCollectionTypeWithCharacterAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception { String output = valueSerialization.serialize( characterCollection() ); CollectionType collectionType = new CollectionType( List.class, new ValueType( Character.class ) ); List<Character> list = valueSerialization.deserialize( collectionType, output ); assertEquals( characterCollection(), list ); }
@Test public void givenCollectionTypeWithIntegerAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception { String output = valueSerialization.serialize( integerCollection() ); CollectionType collectionType = new CollectionType( List.class, new ValueType( Integer.class ) ); List<Integer> list = valueSerialization.deserialize( collectionType, output ); assertEquals( integerCollection(), list ); }
@Test public void givenCollectionTypeWithDoubleAndNullElementWhenSerializingExpectCorrectJsonOutput() throws Exception { String output = valueSerialization.serialize( doubleCollection() ); CollectionType collectionType = new CollectionType( List.class, new ValueType( Double.class ) ); List<Double> list = valueSerialization.deserialize( collectionType, output ); assertEquals( doubleCollection(), list ); }
@Test public void givenCollectionTypeWithFloatAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception { String output = valueSerialization.serialize( floatCollection() ); CollectionType collectionType = new CollectionType( List.class, new ValueType( Float.class ) ); List<Float> list = valueSerialization.deserialize( collectionType, output ); assertEquals( floatCollection(), list ); }
@Test public void givenCollectionTypeWithBigDecimalAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception { String output = valueSerialization.serialize( bigDecimalCollection() ); CollectionType collectionType = new CollectionType( Collection.class, new ValueType( BigDecimal.class ) ); Collection<BigDecimal> collection = valueSerialization.deserialize( collectionType, output ); assertEquals( bigDecimalCollection(), collection ); }
@Test public void givenCollectionTypeWithShortAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception { String output = valueSerialization.serialize( shortCollection() ); CollectionType collectionType = new CollectionType( List.class, new ValueType( Short.class ) ); List<Short> list = valueSerialization.deserialize( collectionType, output ); assertEquals( shortCollection(), list ); }
@Test public void givenCollectionTypeWithLongAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception { String output = valueSerialization.serialize( longCollection() ); CollectionType collectionType = new CollectionType( List.class, new ValueType( Long.class ) ); List<Long> list = valueSerialization.deserialize( collectionType, output ); assertEquals( longCollection(), list ); }
@Test public void givenCollectionTypeWithBigIntegerAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception { String output = valueSerialization.serialize( bigIntegerCollection() ); CollectionType collectionType = new CollectionType( List.class, new ValueType( BigInteger.class ) ); List<BigInteger> list = valueSerialization.deserialize( collectionType, output ); assertEquals( bigIntegerCollection(), list ); }
@Test public void givenListOfMapStringStringAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception { String output = valueSerialization.serialize( stringListOfMaps() ); ValueType stringType = new ValueType( String.class ); CollectionType collectionType = new CollectionType( List.class, new MapType( Map.class, stringType, stringType ) ); List<Map<String, String>> value = valueSerialization.deserialize( collectionType, output ); assertEquals( stringListOfMaps(), value ); }
@Test public void givenMapOfStringListStringAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception { String output = valueSerialization.serialize( stringMultiMap() ); CollectionType collectionType = new CollectionType( List.class, new ValueType( String.class ) ); MapType mapType = new MapType( Map.class, new ValueType( String.class ), collectionType ); Map<String, List<String>> value = valueSerialization.deserialize( mapType, output ); assertEquals( stringMultiMap(), value ); }