@Test public void noUseResultAsFirstInnerTypeThrows() { Type reservoirType = new TypeToken<Supplier<String>>() {}.getType(); try { factory.get(reservoirType, NO_ANNOTATIONS, retrofit); fail(); } catch (IllegalStateException e) { assertThat(e, hasMessage(containsString( "Supplier return type must be parameterized as Supplier<Result<Foo>> or Supplier<Result<? extends Foo>>"))); } }
@Override public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) { if (getRawType(returnType) != Supplier.class) { return null; } if (!(returnType instanceof ParameterizedType)) { throw new IllegalStateException("Supplier return type must be parameterized" + " as Supplier<Result<Foo>> or Supplier<Result<? extends Foo>>"); } Type innerType = getParameterUpperBound(0, (ParameterizedType) returnType); if (getRawType(innerType) != Result.class) { throw new IllegalStateException("Supplier return type must be parameterized" + " as Supplier<Result<Foo>> or Supplier<Result<? extends Foo>>"); } Type innerTypeOfInnerType = getParameterUpperBound(0, (ParameterizedType) innerType); if (getRawType(innerTypeOfInnerType) != Response.class) { return new BodyCallAdapter(innerTypeOfInnerType); } if (!(innerTypeOfInnerType instanceof ParameterizedType)) { throw new IllegalStateException("Response must be parameterized" + " as Response<Foo> or Response<? extends Foo>"); } Type responseType = getParameterUpperBound(0, (ParameterizedType) innerTypeOfInnerType); return new ResponseCallAdapter(responseType); }
AgeraCallAdapterFactory extends CallAdapter.Factory { @Override public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) { if (getRawType(returnType) != Supplier.class) { return null; } if (!(returnType instanceof ParameterizedType)) { throw new IllegalStateException("Supplier return type must be parameterized" + " as Supplier<Result<Foo>> or Supplier<Result<? extends Foo>>"); } Type innerType = getParameterUpperBound(0, (ParameterizedType) returnType); if (getRawType(innerType) != Result.class) { throw new IllegalStateException("Supplier return type must be parameterized" + " as Supplier<Result<Foo>> or Supplier<Result<? extends Foo>>"); } Type innerTypeOfInnerType = getParameterUpperBound(0, (ParameterizedType) innerType); if (getRawType(innerTypeOfInnerType) != Response.class) { return new BodyCallAdapter(innerTypeOfInnerType); } if (!(innerTypeOfInnerType instanceof ParameterizedType)) { throw new IllegalStateException("Response must be parameterized" + " as Response<Foo> or Response<? extends Foo>"); } Type responseType = getParameterUpperBound(0, (ParameterizedType) innerTypeOfInnerType); return new ResponseCallAdapter(responseType); } }
AgeraCallAdapterFactory extends CallAdapter.Factory { @Override public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) { if (getRawType(returnType) != Supplier.class) { return null; } if (!(returnType instanceof ParameterizedType)) { throw new IllegalStateException("Supplier return type must be parameterized" + " as Supplier<Result<Foo>> or Supplier<Result<? extends Foo>>"); } Type innerType = getParameterUpperBound(0, (ParameterizedType) returnType); if (getRawType(innerType) != Result.class) { throw new IllegalStateException("Supplier return type must be parameterized" + " as Supplier<Result<Foo>> or Supplier<Result<? extends Foo>>"); } Type innerTypeOfInnerType = getParameterUpperBound(0, (ParameterizedType) innerType); if (getRawType(innerTypeOfInnerType) != Response.class) { return new BodyCallAdapter(innerTypeOfInnerType); } if (!(innerTypeOfInnerType instanceof ParameterizedType)) { throw new IllegalStateException("Response must be parameterized" + " as Response<Foo> or Response<? extends Foo>"); } Type responseType = getParameterUpperBound(0, (ParameterizedType) innerTypeOfInnerType); return new ResponseCallAdapter(responseType); } private  AgeraCallAdapterFactory(); }
AgeraCallAdapterFactory extends CallAdapter.Factory { @Override public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) { if (getRawType(returnType) != Supplier.class) { return null; } if (!(returnType instanceof ParameterizedType)) { throw new IllegalStateException("Supplier return type must be parameterized" + " as Supplier<Result<Foo>> or Supplier<Result<? extends Foo>>"); } Type innerType = getParameterUpperBound(0, (ParameterizedType) returnType); if (getRawType(innerType) != Result.class) { throw new IllegalStateException("Supplier return type must be parameterized" + " as Supplier<Result<Foo>> or Supplier<Result<? extends Foo>>"); } Type innerTypeOfInnerType = getParameterUpperBound(0, (ParameterizedType) innerType); if (getRawType(innerTypeOfInnerType) != Response.class) { return new BodyCallAdapter(innerTypeOfInnerType); } if (!(innerTypeOfInnerType instanceof ParameterizedType)) { throw new IllegalStateException("Response must be parameterized" + " as Response<Foo> or Response<? extends Foo>"); } Type responseType = getParameterUpperBound(0, (ParameterizedType) innerTypeOfInnerType); return new ResponseCallAdapter(responseType); } private  AgeraCallAdapterFactory(); static AgeraCallAdapterFactory create(); @Override CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit); }
AgeraCallAdapterFactory extends CallAdapter.Factory { @Override public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) { if (getRawType(returnType) != Supplier.class) { return null; } if (!(returnType instanceof ParameterizedType)) { throw new IllegalStateException("Supplier return type must be parameterized" + " as Supplier<Result<Foo>> or Supplier<Result<? extends Foo>>"); } Type innerType = getParameterUpperBound(0, (ParameterizedType) returnType); if (getRawType(innerType) != Result.class) { throw new IllegalStateException("Supplier return type must be parameterized" + " as Supplier<Result<Foo>> or Supplier<Result<? extends Foo>>"); } Type innerTypeOfInnerType = getParameterUpperBound(0, (ParameterizedType) innerType); if (getRawType(innerTypeOfInnerType) != Response.class) { return new BodyCallAdapter(innerTypeOfInnerType); } if (!(innerTypeOfInnerType instanceof ParameterizedType)) { throw new IllegalStateException("Response must be parameterized" + " as Response<Foo> or Response<? extends Foo>"); } Type responseType = getParameterUpperBound(0, (ParameterizedType) innerTypeOfInnerType); return new ResponseCallAdapter(responseType); } private  AgeraCallAdapterFactory(); static AgeraCallAdapterFactory create(); @Override CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit);  }