Add exception cause for method adapter creation.

This commit is contained in:
Eric Cochran
2018-09-11 00:10:15 -07:00
parent 9050e42038
commit 46a42bc7ed
3 changed files with 13 additions and 1 deletions

View File

@@ -53,7 +53,7 @@ final class AdapterMethodsFactory implements JsonAdapter.Factory {
} catch (IllegalArgumentException e) {
String missingAnnotation = toAdapter == null ? "@ToJson" : "@FromJson";
throw new IllegalArgumentException("No " + missingAnnotation + " adapter for "
+ typeAnnotatedWithAnnotations(type, annotations));
+ typeAnnotatedWithAnnotations(type, annotations), e);
}
} else {
delegate = null;

View File

@@ -463,6 +463,9 @@ public final class AdapterMethodsTest {
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage("No @FromJson adapter for interface "
+ "com.squareup.moshi.AdapterMethodsTest$Shape (with no annotations)");
assertThat(e).hasCauseExactlyInstanceOf(IllegalArgumentException.class);
assertThat(e.getCause()).hasMessage("No next JsonAdapter for interface "
+ "com.squareup.moshi.AdapterMethodsTest$Shape (with no annotations)");
}
}
@@ -482,6 +485,9 @@ public final class AdapterMethodsTest {
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage("No @ToJson adapter for interface "
+ "com.squareup.moshi.AdapterMethodsTest$Shape (with no annotations)");
assertThat(e).hasCauseExactlyInstanceOf(IllegalArgumentException.class);
assertThat(e.getCause()).hasMessage("No next JsonAdapter for interface "
+ "com.squareup.moshi.AdapterMethodsTest$Shape (with no annotations)");
}
}

View File

@@ -334,6 +334,9 @@ public final class JsonQualifiersTest {
} catch (IllegalArgumentException expected) {
assertThat(expected).hasMessage("No @FromJson adapter for class java.lang.String "
+ "annotated [@com.squareup.moshi.JsonQualifiersTest$FooPrefix()]");
assertThat(expected).hasCauseExactlyInstanceOf(IllegalArgumentException.class);
assertThat(expected.getCause()).hasMessage("No next JsonAdapter for class "
+ "java.lang.String annotated [@com.squareup.moshi.JsonQualifiersTest$FooPrefix()]");
}
}
@@ -355,6 +358,9 @@ public final class JsonQualifiersTest {
} catch (IllegalArgumentException expected) {
assertThat(expected).hasMessage("No @ToJson adapter for class java.lang.String "
+ "annotated [@com.squareup.moshi.JsonQualifiersTest$FooPrefix()]");
assertThat(expected).hasCauseExactlyInstanceOf(IllegalArgumentException.class);
assertThat(expected.getCause()).hasMessage("No next JsonAdapter for class "
+ "java.lang.String annotated [@com.squareup.moshi.JsonQualifiersTest$FooPrefix()]");
}
}