Merge pull request #659 from square/eric.exception-cause

Add exception cause for method adapter creation.
This commit is contained in:
Jesse Wilson
2018-09-12 22:24:22 -04:00
committed by GitHub
3 changed files with 13 additions and 1 deletions

View File

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

View File

@@ -463,6 +463,9 @@ public final class AdapterMethodsTest {
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
assertThat(e).hasMessage("No @FromJson adapter for interface " assertThat(e).hasMessage("No @FromJson adapter for interface "
+ "com.squareup.moshi.AdapterMethodsTest$Shape (with no annotations)"); + "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) { } catch (IllegalArgumentException e) {
assertThat(e).hasMessage("No @ToJson adapter for interface " assertThat(e).hasMessage("No @ToJson adapter for interface "
+ "com.squareup.moshi.AdapterMethodsTest$Shape (with no annotations)"); + "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) { } catch (IllegalArgumentException expected) {
assertThat(expected).hasMessage("No @FromJson adapter for class java.lang.String " assertThat(expected).hasMessage("No @FromJson adapter for class java.lang.String "
+ "annotated [@com.squareup.moshi.JsonQualifiersTest$FooPrefix()]"); + "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) { } catch (IllegalArgumentException expected) {
assertThat(expected).hasMessage("No @ToJson adapter for class java.lang.String " assertThat(expected).hasMessage("No @ToJson adapter for class java.lang.String "
+ "annotated [@com.squareup.moshi.JsonQualifiersTest$FooPrefix()]"); + "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()]");
} }
} }