From 46a42bc7ed6d8f5be6e777f9f4a9224d1ae5d93b Mon Sep 17 00:00:00 2001 From: Eric Cochran Date: Tue, 11 Sep 2018 00:10:15 -0700 Subject: [PATCH] Add exception cause for method adapter creation. --- .../main/java/com/squareup/moshi/AdapterMethodsFactory.java | 2 +- .../test/java/com/squareup/moshi/AdapterMethodsTest.java | 6 ++++++ .../test/java/com/squareup/moshi/JsonQualifiersTest.java | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/moshi/src/main/java/com/squareup/moshi/AdapterMethodsFactory.java b/moshi/src/main/java/com/squareup/moshi/AdapterMethodsFactory.java index 8a03096..f26230a 100644 --- a/moshi/src/main/java/com/squareup/moshi/AdapterMethodsFactory.java +++ b/moshi/src/main/java/com/squareup/moshi/AdapterMethodsFactory.java @@ -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; diff --git a/moshi/src/test/java/com/squareup/moshi/AdapterMethodsTest.java b/moshi/src/test/java/com/squareup/moshi/AdapterMethodsTest.java index 8bdc523..afd2469 100644 --- a/moshi/src/test/java/com/squareup/moshi/AdapterMethodsTest.java +++ b/moshi/src/test/java/com/squareup/moshi/AdapterMethodsTest.java @@ -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)"); } } diff --git a/moshi/src/test/java/com/squareup/moshi/JsonQualifiersTest.java b/moshi/src/test/java/com/squareup/moshi/JsonQualifiersTest.java index 0dfe77e..647df10 100644 --- a/moshi/src/test/java/com/squareup/moshi/JsonQualifiersTest.java +++ b/moshi/src/test/java/com/squareup/moshi/JsonQualifiersTest.java @@ -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()]"); } }