From 6a2981108feade236171b4778291ef68533bdace Mon Sep 17 00:00:00 2001 From: Eric Cochran Date: Mon, 30 Jan 2017 23:03:20 -0800 Subject: [PATCH] Add arrayOf, subtypeOf, supertypeOf tests --- .../java/com/squareup/moshi/TypesTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/moshi/src/test/java/com/squareup/moshi/TypesTest.java b/moshi/src/test/java/com/squareup/moshi/TypesTest.java index 5b91809..6abc281 100644 --- a/moshi/src/test/java/com/squareup/moshi/TypesTest.java +++ b/moshi/src/test/java/com/squareup/moshi/TypesTest.java @@ -58,6 +58,27 @@ public final class TypesTest { } } + @Test public void arrayOf() { + assertThat(Types.getRawType(Types.arrayOf(int.class))).isEqualTo(int[].class); + assertThat(Types.getRawType(Types.arrayOf(List.class))).isEqualTo(List[].class); + assertThat(Types.getRawType(Types.arrayOf(String[].class))).isEqualTo(String[][].class); + } + + List listSubtype; + List listSupertype; + + @Test public void subtypeOf() throws Exception { + Type listOfWildcardType = TypesTest.class.getDeclaredField("listSubtype").getGenericType(); + Type expected = Types.collectionElementType(listOfWildcardType, List.class); + assertThat(Types.subtypeOf(CharSequence.class)).isEqualTo(expected); + } + + @Test public void supertypeOf() throws Exception { + Type listOfWildcardType = TypesTest.class.getDeclaredField("listSupertype").getGenericType(); + Type expected = Types.collectionElementType(listOfWildcardType, List.class); + assertThat(Types.supertypeOf(String.class)).isEqualTo(expected); + } + @Test public void getFirstTypeArgument() throws Exception { assertThat(getFirstTypeArgument(A.class)).isNull();