diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/AtomTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/AtomTest.java index fe6855bc9..84f4bac91 100644 --- a/google-http-client-xml/src/test/java/com/google/api/client/xml/AtomTest.java +++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/AtomTest.java @@ -17,12 +17,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import java.io.BufferedReader; import java.io.ByteArrayInputStream; -import java.io.FileInputStream; -import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.io.StringReader; import java.net.URL; import java.util.List; @@ -61,7 +57,6 @@ public class AtomTest { /** * Test for checking the Slug Header */ - @SuppressWarnings("unchecked") @Test public void testSetSlugHeader() { HttpHeaders headers = new HttpHeaders(); @@ -92,7 +87,6 @@ public void subtestSetSlugHeader(HttpHeaders headers, String expectedValue, Stri * AtomFeedParser#parseNextEntry} and see if the mapping of the XML element to the entity classes * is done correctly. */ - @SuppressWarnings("unchecked") @Test public void testAtomFeedUsingCustomizedParser() throws Exception { XmlPullParser parser = Xml.createParser(); @@ -138,7 +132,6 @@ public void testAtomFeedUsingCustomizedParser() throws Exception { * The purpose of this test is to assert, if the parsed elements are correctly parsed using a * {@link AtomFeedParser}. */ - @SuppressWarnings("unchecked") @Test public void testAtomFeedUsingStandardParser() throws Exception { Feed feed = new Feed(); @@ -179,7 +172,6 @@ public void testAtomFeedUsingStandardParser() throws Exception { * (HTML in this case), that are not part of the {@link FeedEntry} and to see if there is an issue * if we parse some more entries. */ - @SuppressWarnings("unchecked") @Test public void testSampleFeedParser() throws Exception { XmlPullParser parser = Xml.createParser(); diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlListTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlListTest.java index e6d607c27..6d2ec0769 100644 --- a/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlListTest.java +++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlListTest.java @@ -60,6 +60,7 @@ public class GenericXmlListTest { /** * The purpose of this test is to map an XML with an Array of {@link XmlTest.AnyType} objects. */ + @SuppressWarnings("unchecked") @Test public void testParseArrayTypeWithClassType() throws Exception { ArrayWithClassTypeGeneric xml = new ArrayWithClassTypeGeneric(); @@ -68,7 +69,7 @@ public void testParseArrayTypeWithClassType() throws Exception { XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary(); Xml.parseElement(parser, xml, namespaceDictionary, null); // check type - assertTrue(xml.rep instanceof XmlTest.AnyType[]); + assertNotNull(xml.rep); XmlTest.AnyType[] rep = xml.rep; assertNotNull(rep); assertEquals(3, rep.length); @@ -105,7 +106,7 @@ public void testParseCollectionWithClassType() throws Exception { XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary(); Xml.parseElement(parser, xml, namespaceDictionary, null); // check type - assertTrue(xml.rep instanceof Collection); + assertNotNull(xml.rep); Collection rep = xml.rep; assertNotNull(rep); assertEquals(3, rep.size()); @@ -120,6 +121,7 @@ public void testParseCollectionWithClassType() throws Exception { /** * The purpose of this test is to map an XML with an Array of {@link XmlTest.AnyType} objects. */ + @SuppressWarnings("unchecked") @Test public void testParseMultiGenericWithClassType() throws Exception { MultiGenericWithClassType xml = new MultiGenericWithClassType(); @@ -154,6 +156,7 @@ public void testParseMultiGenericWithClassType() throws Exception { /** * The purpose of this test is to map an XML with an Array of {@link XmlTest.AnyType} objects. */ + @SuppressWarnings("unchecked") @Test public void testParseMultiGenericWithClassTypeGeneric() throws Exception { MultiGenericWithClassTypeGeneric xml = new MultiGenericWithClassTypeGeneric(); @@ -162,7 +165,6 @@ public void testParseMultiGenericWithClassTypeGeneric() throws Exception { XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary(); Xml.parseElement(parser, xml, namespaceDictionary, null); // check type - GenericXml[] rep = xml.rep; assertNotNull(rep); assertEquals(3, rep.length); diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlTest.java index a9ef1c361..0c98646b3 100644 --- a/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlTest.java +++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlTest.java @@ -18,6 +18,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.StringReader; import java.util.ArrayList; import java.util.Collection; @@ -25,6 +26,7 @@ import java.util.Map; import org.junit.Test; import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlSerializer; import com.google.api.client.util.ArrayMap; import com.google.api.client.util.Key; @@ -72,7 +74,6 @@ public GenericXmlTest() { * The purpose of this test is to parse the given XML into a {@link GenericXml} Object that has no * fixed structure. */ - @SuppressWarnings("unchecked") @Test public void testParseToGenericXml() throws Exception { @@ -105,7 +106,7 @@ public void testParseToGenericXml() throws Exception { /** * The purpose of this test is map a generic XML to an element inside a dedicated element. */ - @SuppressWarnings("cast") + @SuppressWarnings("unchecked") @Test public void testParseAnyGenericType() throws Exception { AnyGenericType xml = new AnyGenericType(); @@ -197,29 +198,15 @@ public void testParseSimpleTypeAsValueInteger() throws Exception { * The purpose of this test is to map a {@link GenericXml} to the String element in the * object. */ - @SuppressWarnings("cast") @Test public void testParseToAnyType() throws Exception { - AnyTypeGeneric xml = new AnyTypeGeneric(); - XmlPullParser parser = Xml.createParser(); - parser.setInput(new StringReader(ANY_TYPE_XML)); - XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary(); - Xml.parseElement(parser, xml, namespaceDictionary, null); - assertNotNull(xml); - assertEquals(4, xml.values().size()); - // serialize - XmlSerializer serializer = Xml.createSerializer(); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - serializer.setOutput(out, "UTF-8"); - namespaceDictionary.serialize(serializer, "any", xml); - assertEquals(ANY_TYPE_XML, out.toString()); + processAnyTypeGeneric(ANY_TYPE_XML); } /** * The purpose of this test is to map a {@link GenericXml} to the String element in the * object. */ - @SuppressWarnings("cast") @Test public void testParseToAnyTypeMissingField() throws Exception { AnyTypeMissingFieldGeneric xml = new AnyTypeMissingFieldGeneric(); @@ -243,7 +230,6 @@ public void testParseToAnyTypeMissingField() throws Exception { * The purpose of this test isto map a {@link GenericXml} to the String element in the * object. */ - @SuppressWarnings("cast") @Test public void testParseToAnyTypeAdditionalField() throws Exception { AnyTypeAdditionalFieldGeneric xml = new AnyTypeAdditionalFieldGeneric(); @@ -329,22 +315,26 @@ public void testParseIncorrectMapping() throws Exception { * The purpose of this test is to map a {@link GenericXml} to the String element in the * object. */ - @SuppressWarnings("cast") @Test public void testParseAnyTypeWithNestedElementArrayMap() throws Exception { + processAnyTypeGeneric(ANY_TYPE_XML_NESTED_ARRAY); + } + + private void processAnyTypeGeneric(final String anyTypeXmlNestedArray) throws XmlPullParserException, IOException { AnyTypeGeneric xml = new AnyTypeGeneric(); XmlPullParser parser = Xml.createParser(); - parser.setInput(new StringReader(ANY_TYPE_XML_NESTED_ARRAY)); + parser.setInput(new StringReader(anyTypeXmlNestedArray)); XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary(); Xml.parseElement(parser, xml, namespaceDictionary, null); assertNotNull(xml); - assertEquals(4, xml.values().size()); + assertEquals(4, xml.values() + .size()); // serialize XmlSerializer serializer = Xml.createSerializer(); ByteArrayOutputStream out = new ByteArrayOutputStream(); serializer.setOutput(out, "UTF-8"); namespaceDictionary.serialize(serializer, "any", xml); - assertEquals(ANY_TYPE_XML_NESTED_ARRAY, out.toString()); + assertEquals(anyTypeXmlNestedArray, out.toString()); } private static class AnyGenericType { @@ -408,7 +398,7 @@ private static class AnyTypePrimitiveIntGeneric extends GenericXml { @Key("@attr") public int attr; @Key - public int intArray[]; + public int[] intArray; } private static class AnyTypePrimitiveStringGeneric extends GenericXml { @@ -417,7 +407,7 @@ private static class AnyTypePrimitiveStringGeneric extends GenericXml { @Key("@attr") public String attr; @Key - public String strArray[]; + public String[] strArray; } diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlEnumTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlEnumTest.java index 9b0fb58e3..2d250a11d 100644 --- a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlEnumTest.java +++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlEnumTest.java @@ -103,8 +103,8 @@ private String testStandardXml(final String xmlString) throws Exception { parser.setInput(new StringReader(xmlString)); XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary(); Xml.parseElement(parser, xml, namespaceDictionary, null); - assertTrue(xml.elementEnum instanceof XmlEnumTest.AnyEnum); - assertTrue(xml.elementEnum.equals(AnyEnum.ENUM_2)); + assertNotNull(xml.elementEnum); + assertEquals(xml.elementEnum, AnyEnum.ENUM_2); // serialize XmlSerializer serializer = Xml.createSerializer(); ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -124,8 +124,8 @@ public void testParse_enumAttributeType() throws Exception { parser.setInput(new StringReader(XML_ENUM_ATTRIBUTE_ONLY)); XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary(); Xml.parseElement(parser, xml, namespaceDictionary, null); - assertTrue(xml.attributeEnum instanceof XmlEnumTest.AnyEnum); - assertTrue(xml.attributeEnum.equals(AnyEnum.ENUM_1)); + assertNotNull(xml.attributeEnum); + assertEquals(xml.attributeEnum, AnyEnum.ENUM_1); // serialize XmlSerializer serializer = Xml.createSerializer(); ByteArrayOutputStream out = new ByteArrayOutputStream(); diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlListTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlListTest.java index fc45cbb6b..a53c4df12 100644 --- a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlListTest.java +++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlListTest.java @@ -55,6 +55,7 @@ public class XmlListTest { /** * The purpose of this test is to map an XML with an Array of {@link XmlTest.AnyType} objects. */ + @SuppressWarnings("unchecked") @Test public void testParseArrayTypeWithClassType() throws Exception { ArrayWithClassType xml = new ArrayWithClassType(); @@ -63,7 +64,7 @@ public void testParseArrayTypeWithClassType() throws Exception { XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary(); Xml.parseElement(parser, xml, namespaceDictionary, null); // check type - assertTrue(xml.rep instanceof XmlTest.AnyType[]); + assertNotNull(xml.rep); XmlTest.AnyType[] rep = xml.rep; assertNotNull(rep); assertEquals(3, rep.length); @@ -100,12 +101,11 @@ public void testParseCollectionWithClassType() throws Exception { XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary(); Xml.parseElement(parser, xml, namespaceDictionary, null); // check type - assertTrue(xml.rep instanceof Collection); + assertNotNull(xml.rep); Collection rep = xml.rep; assertNotNull(rep); assertEquals(3, rep.size()); - // serialize XmlSerializer serializer = Xml.createSerializer(); ByteArrayOutputStream out = new ByteArrayOutputStream(); diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlTest.java index f59284d4d..0462a2c3b 100644 --- a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlTest.java +++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlTest.java @@ -22,6 +22,7 @@ import java.io.ByteArrayOutputStream; import java.io.StringReader; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import org.junit.Test; import org.xmlpull.v1.XmlPullParser; @@ -221,7 +222,6 @@ public void testFailMappingOfDataType() throws Exception { * The purpose of this tests it to test the {@link Key} Annotation for mapping of elements and * attributes. All elements/attributes are matched. */ - @SuppressWarnings("cast") @Test public void testParseToAnyType() throws Exception { AnyType xml = new AnyType(); @@ -232,7 +232,7 @@ public void testParseToAnyType() throws Exception { assertTrue(xml.attr instanceof String); assertTrue(xml.elem.toString(), xml.elem instanceof ArrayList); assertTrue(xml.rep.toString(), xml.rep instanceof ArrayList); - assertTrue(xml.value instanceof ValueType); + assertNotNull(xml.value); assertTrue(xml.value.content instanceof String); // serialize XmlSerializer serializer = Xml.createSerializer(); @@ -247,7 +247,6 @@ public void testParseToAnyType() throws Exception { * attributes. The matched object misses some field that are present int the XML ('elem' is * missing and therefore ignored). */ - @SuppressWarnings("cast") @Test public void testParseToAnyTypeMissingField() throws Exception { AnyTypeMissingField xml = new AnyTypeMissingField(); @@ -257,7 +256,7 @@ public void testParseToAnyTypeMissingField() throws Exception { Xml.parseElement(parser, xml, namespaceDictionary, null); assertTrue(xml.attr instanceof String); assertTrue(xml.elem.toString(), xml.elem instanceof ArrayList); - assertTrue(xml.value instanceof ValueType); + assertNotNull(xml.value); assertTrue(xml.value.content instanceof String); // serialize XmlSerializer serializer = Xml.createSerializer(); @@ -272,7 +271,6 @@ public void testParseToAnyTypeMissingField() throws Exception { * attributes. The matched object has an additional field, that will not be used and stays {@code * null}. */ - @SuppressWarnings("cast") @Test public void testParseToAnyTypeAdditionalField() throws Exception { AnyTypeAdditionalField xml = new AnyTypeAdditionalField(); @@ -282,7 +280,7 @@ public void testParseToAnyTypeAdditionalField() throws Exception { Xml.parseElement(parser, xml, namespaceDictionary, null); assertTrue(xml.attr instanceof String); assertTrue(xml.elem.toString(), xml.elem instanceof ArrayList); - assertTrue(xml.value instanceof ValueType); + assertNotNull(xml.value); assertNull(xml.additionalField); assertTrue(xml.rep.toString(), xml.rep instanceof ArrayList); assertTrue(xml.value.content instanceof String); @@ -321,7 +319,7 @@ public void testParseAnyTypeWithCustomParser() throws Exception { assertTrue(xml.attr instanceof String); assertTrue(xml.elem.toString(), xml.elem instanceof ArrayList); assertTrue(xml.rep.toString(), xml.rep instanceof ArrayList); - assertTrue(xml.value instanceof ValueType); + assertNotNull(xml.value); assertTrue(xml.value.content instanceof String); // serialize XmlSerializer serializer = Xml.createSerializer(); @@ -489,7 +487,6 @@ public void testParseIncorrectMapping() throws Exception { assertNull(xml.value); assertNull(xml.rep); assertNull(xml.rep); - // serialize XmlSerializer serializer = Xml.createSerializer(); ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -502,7 +499,6 @@ public void testParseIncorrectMapping() throws Exception { * The purpose of this test is to map the sub elements of an {@link ArrayMap} again to an {@link * ArrayMap}. */ - @SuppressWarnings("cast") @Test public void testParseAnyTypeWithNestedElementArrayMap() throws Exception { AnyType xml = new AnyType(); @@ -513,14 +509,12 @@ public void testParseAnyTypeWithNestedElementArrayMap() throws Exception { assertTrue(xml.attr instanceof String); assertTrue(xml.elem.toString(), xml.elem instanceof ArrayList); assertTrue(xml.rep.toString(), xml.rep instanceof ArrayList); - assertTrue(xml.value instanceof ValueType); + assertNotNull(xml.value); assertTrue(xml.value.content instanceof String); - assertEquals(1, ((ArrayList) xml.elem).size()); - assertEquals(2, ((ArrayList) xml.rep).size()); - assertEquals(1, ((ArrayList) xml.rep).toArray(new ArrayMap[]{})[0].size()); - assertEquals(1, ((ArrayList) xml.rep).toArray(new ArrayMap[]{})[1].size()); - - + assertEquals(1, ((Collection) xml.elem).size()); + assertEquals(2, ((Collection) xml.rep).size()); + assertEquals(1, ((Collection) xml.rep).toArray(new ArrayMap[]{})[0].size()); + assertEquals(1, ((Collection) xml.rep).toArray(new ArrayMap[]{})[1].size()); assertEquals("rep1", ((ArrayList) ((ArrayList) xml.rep).toArray(new ArrayMap[]{})[0].get("p")).toArray(new ArrayMap[]{})[0].getValue(0)); assertEquals("rep2", @@ -592,7 +586,7 @@ public static class AnyTypePrimitiveInt { @Key("@attr") public int attr; @Key - public int intArray[]; + public int[] intArray; } public static class AnyTypePrimitiveString { @@ -601,7 +595,7 @@ public static class AnyTypePrimitiveString { @Key("@attr") public String attr; @Key - public String strArray[]; + public String[] strArray; } private static class AnyTypeInf { @@ -629,6 +623,5 @@ private static class AllType { @Key public List integerCollection; } - }