public void testRejectsIfNoConstuctorMarked() throws IOException { TypeAdapter<DefaultConstructor> adapter = parameterizedCtorFactory.create(gson, TypeToken.get(DefaultConstructor.class)); assertNull(adapter); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Incorrect count of names on annotation of .*") public void testSerializedNamesMustHaveCorrectCountOfNames() { parameterizedCtorFactory.create(gson, TypeToken.get(ValueTypeWithFactoryMissingSerializedNames.class)); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "duplicate key: foo") public void testNoDuplicateSerializedNamesRequiredOnAllParameters() { parameterizedCtorFactory.create(gson, TypeToken.get(DuplicateSerializedNames.class)); }
public void testRejectsIfNoConstuctorMarked() throws IOException { TypeAdapter<DefaultConstructor> adapter = parameterizedCtorFactory.create(gson, TypeToken.get(DefaultConstructor.class)); assertNull(adapter); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = ".* parameter 0 failed to be named by AnnotationBasedNamingStrategy requiring one of javax.inject.Named") public void testSerializedNameRequiredOnAllParameters() { parameterizedCtorFactory .create(gson, TypeToken.get(WithDeserializationConstructorButWithoutSerializedName.class)); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = ".* parameter 0 failed to be named by AnnotationBasedNamingStrategy requiring one of javax.inject.Named") public void testSerializedNameRequiredOnAllParameters() { parameterizedCtorFactory .create(gson, TypeToken.get(WithDeserializationConstructorButWithoutSerializedName.class)); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Multiple entries with same key: foo.*") public void testNoDuplicateSerializedNamesRequiredOnAllParameters() { parameterizedCtorFactory.create(gson, TypeToken.get(DuplicateSerializedNames.class)); }
public void testNullWhenPrimitive() { assertNull(parameterizedCtorFactory.create(gson, TypeToken.get(int.class))); }
public void testNullWhenPrimitive() { assertNull(parameterizedCtorFactory.create(gson, TypeToken.get(int.class))); }
public void testGenericParamsCopiedIn() throws IOException { TypeAdapter<GenericParamsCopiedIn> adapter = parameterizedCtorFactory.create(gson, TypeToken.get(GenericParamsCopiedIn.class)); List<String> inputFoo = Lists.newArrayList(); inputFoo.add("one"); Map<String, String> inputBar = Maps.newHashMap(); inputBar.put("2", "two"); GenericParamsCopiedIn toTest = adapter.fromJson("{ \"foo\":[\"one\"], \"bar\":{ \"2\":\"two\"}}"); assertEquals(inputFoo, toTest.foo); assertNotSame(inputFoo, toTest.foo); assertEquals(inputBar, toTest.bar); }
@Test(expectedExceptions = NullPointerException.class) public void testPartialObjectStillThrows() throws IOException { TypeAdapter<ComposedObjects> adapter = parameterizedCtorFactory .create(gson, TypeToken.get(ComposedObjects.class)); assertNull(adapter.fromJson("{\"x\":{\"foo\":0,\"bar\":1}}")); }
public void testGenericParamsCopiedIn() throws IOException { TypeAdapter<GenericParamsCopiedIn> adapter = parameterizedCtorFactory.create(gson, TypeToken.get(GenericParamsCopiedIn.class)); List<String> inputFoo = Lists.newArrayList(); inputFoo.add("one"); Map<String, String> inputBar = Maps.newHashMap(); inputBar.put("2", "two"); GenericParamsCopiedIn toTest = adapter.fromJson("{ \"foo\":[\"one\"], \"bar\":{ \"2\":\"two\"}}"); assertEquals(inputFoo, toTest.foo); assertNotSame(inputFoo, toTest.foo); assertEquals(inputBar, toTest.bar); }
@Test(expectedExceptions = NullPointerException.class) public void testPartialObjectStillThrows() throws IOException { TypeAdapter<ComposedObjects> adapter = parameterizedCtorFactory .create(gson, TypeToken.get(ComposedObjects.class)); assertNull(adapter.fromJson("{\"x\":{\"foo\":0,\"bar\":1}}")); } }
public void testEmptyObjectIsNull() throws IOException { TypeAdapter<ComposedObjects> adapter = parameterizedCtorFactory .create(gson, TypeToken.get(ComposedObjects.class)); assertNull(adapter.fromJson("{}")); }
public void testEmptyObjectIsNull() throws IOException { TypeAdapter<ComposedObjects> adapter = parameterizedCtorFactory .create(gson, TypeToken.get(ComposedObjects.class)); assertNull(adapter.fromJson("{}")); }
public void checkSimpleComposedObject() throws IOException { ValidatedConstructor x = new ValidatedConstructor(Optional.of(0), 1); ValidatedConstructor y = new ValidatedConstructor(Optional.of(1), 2); TypeAdapter<ComposedObjects> adapter = parameterizedCtorFactory .create(gson, TypeToken.get(ComposedObjects.class)); assertEquals(new ComposedObjects(x, y), adapter.fromJson("{\"x\":{\"foo\":0,\"bar\":1},\"y\":{\"foo\":1,\"bar\":2}}")); }
public void testBuilderOnAbstractValueType() throws IOException { TypeAdapter<ValueTypeWithFactory> adapter = parameterizedCtorFactory.create(gson, TypeToken.get(ValueTypeWithFactory.class)); List<String> inputFoo = Lists.newArrayList(); inputFoo.add("one"); Map<String, String> inputBar = Maps.newHashMap(); inputBar.put("2", "two"); ValueTypeWithFactory toTest = adapter.fromJson("{ \"foo\":[\"one\"], \"bar\":{ \"2\":\"two\"}}"); assertEquals(inputFoo, toTest.foo()); assertNotSame(inputFoo, toTest.foo()); assertEquals(inputBar, toTest.bar()); }
public void checkSimpleComposedObject() throws IOException { ValidatedConstructor x = new ValidatedConstructor(Optional.of(0), 1); ValidatedConstructor y = new ValidatedConstructor(Optional.of(1), 2); TypeAdapter<ComposedObjects> adapter = parameterizedCtorFactory .create(gson, TypeToken.get(ComposedObjects.class)); assertEquals(new ComposedObjects(x, y), adapter.fromJson("{\"x\":{\"foo\":0,\"bar\":1},\"y\":{\"foo\":1,\"bar\":2}}")); }
public void testRenamedFields() throws IOException { TypeAdapter<RenamedFields> adapter = parameterizedCtorFactory.create(gson, TypeToken.get(RenamedFields.class)); assertEquals(new RenamedFields(0, 1), adapter.fromJson("{\"foo\":0,\"_bar\":1}")); assertEquals(adapter.toJson(new RenamedFields(0, 1)), "{\"foo\":0,\"_bar\":1}"); }
public void testRenamedFields() throws IOException { TypeAdapter<RenamedFields> adapter = parameterizedCtorFactory.create(gson, TypeToken.get(RenamedFields.class)); assertEquals(new RenamedFields(0, 1), adapter.fromJson("{\"foo\":0,\"_bar\":1}")); assertEquals(adapter.toJson(new RenamedFields(0, 1)), "{\"foo\":0,\"_bar\":1}"); }