@Test public void rawResultTypeThrows() { Type observableType = new TypeToken<Observable<Result>>() { }.getType(); try { factory.get(observableType, NO_ANNOTATIONS, retrofit); fail(); } catch (IllegalStateException e) { assertThat(e).hasMessage( "Result must be parameterized as Result<Foo> or Result<? extends Foo>"); } Type singleType = new TypeToken<Single<Result>>() { }.getType(); try { factory.get(singleType, NO_ANNOTATIONS, retrofit); fail(); } catch (IllegalStateException e) { assertThat(e).hasMessage( "Result must be parameterized as Result<Foo> or Result<? extends Foo>"); } Type maybeType = new TypeToken<Maybe<Result>>() { }.getType(); try { factory.get(maybeType, NO_ANNOTATIONS, retrofit); fail(); } catch (IllegalStateException e) { assertThat(e).hasMessage( "Result must be parameterized as Result<Foo> or Result<? extends Foo>"); } Type flowableType = new TypeToken<Flowable<Result>>() { }.getType(); try { factory.get(flowableType, NO_ANNOTATIONS, retrofit); fail(); } catch (IllegalStateException e) { assertThat(e).hasMessage( "Result must be parameterized as Result<Foo> or Result<? extends Foo>"); } }
@Override public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) { Class<?> rawType = getRawType(returnType); if (rawType == Completable.class) { return new RxJava2CachedCallAdapter( mCachingSystem, Void.class, mScheduler, retrofit, annotations, mAsync, false, true, false, false, false, true); } boolean isFlowable = rawType == Flowable.class; boolean isSingle = rawType == Single.class; boolean isMaybe = rawType == Maybe.class; if (rawType != Observable.class && !isFlowable && !isSingle && !isMaybe) { return null; } boolean isResult = false; boolean isBody = false; Type responseType; if (!(returnType instanceof ParameterizedType)) { String name = isFlowable ? "Flowable" : isSingle ? "Single" : isMaybe ? "Maybe" : "Observable"; throw new IllegalStateException(name + " return type must be parameterized" + " as " + name + "<Foo> or " + name + "<? extends Foo>"); } Type observableType = getParameterUpperBound(0, (ParameterizedType) returnType); Class<?> rawObservableType = getRawType(observableType); if (rawObservableType == Response.class) { if (!(observableType instanceof ParameterizedType)) { throw new IllegalStateException("Response must be parameterized" + " as Response<Foo> or Response<? extends Foo>"); } responseType = getParameterUpperBound(0, (ParameterizedType) observableType); } else if (rawObservableType == Result.class) { if (!(observableType instanceof ParameterizedType)) { throw new IllegalStateException("Result must be parameterized" + " as Result<Foo> or Result<? extends Foo>"); } responseType = getParameterUpperBound(0, (ParameterizedType) observableType); isResult = true; } else { responseType = observableType; isBody = true; } return new RxJava2CachedCallAdapter( mCachingSystem, responseType, mScheduler, retrofit, annotations, mAsync, isResult, isBody, isFlowable, isSingle, isMaybe, false); }
RxJava2CachedCallAdapterFactory extends CallAdapter.Factory { @Override public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) { Class<?> rawType = getRawType(returnType); if (rawType == Completable.class) { return new RxJava2CachedCallAdapter( mCachingSystem, Void.class, mScheduler, retrofit, annotations, mAsync, false, true, false, false, false, true); } boolean isFlowable = rawType == Flowable.class; boolean isSingle = rawType == Single.class; boolean isMaybe = rawType == Maybe.class; if (rawType != Observable.class && !isFlowable && !isSingle && !isMaybe) { return null; } boolean isResult = false; boolean isBody = false; Type responseType; if (!(returnType instanceof ParameterizedType)) { String name = isFlowable ? "Flowable" : isSingle ? "Single" : isMaybe ? "Maybe" : "Observable"; throw new IllegalStateException(name + " return type must be parameterized" + " as " + name + "<Foo> or " + name + "<? extends Foo>"); } Type observableType = getParameterUpperBound(0, (ParameterizedType) returnType); Class<?> rawObservableType = getRawType(observableType); if (rawObservableType == Response.class) { if (!(observableType instanceof ParameterizedType)) { throw new IllegalStateException("Response must be parameterized" + " as Response<Foo> or Response<? extends Foo>"); } responseType = getParameterUpperBound(0, (ParameterizedType) observableType); } else if (rawObservableType == Result.class) { if (!(observableType instanceof ParameterizedType)) { throw new IllegalStateException("Result must be parameterized" + " as Result<Foo> or Result<? extends Foo>"); } responseType = getParameterUpperBound(0, (ParameterizedType) observableType); isResult = true; } else { responseType = observableType; isBody = true; } return new RxJava2CachedCallAdapter( mCachingSystem, responseType, mScheduler, retrofit, annotations, mAsync, isResult, isBody, isFlowable, isSingle, isMaybe, false); } }
RxJava2CachedCallAdapterFactory extends CallAdapter.Factory { @Override public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) { Class<?> rawType = getRawType(returnType); if (rawType == Completable.class) { return new RxJava2CachedCallAdapter( mCachingSystem, Void.class, mScheduler, retrofit, annotations, mAsync, false, true, false, false, false, true); } boolean isFlowable = rawType == Flowable.class; boolean isSingle = rawType == Single.class; boolean isMaybe = rawType == Maybe.class; if (rawType != Observable.class && !isFlowable && !isSingle && !isMaybe) { return null; } boolean isResult = false; boolean isBody = false; Type responseType; if (!(returnType instanceof ParameterizedType)) { String name = isFlowable ? "Flowable" : isSingle ? "Single" : isMaybe ? "Maybe" : "Observable"; throw new IllegalStateException(name + " return type must be parameterized" + " as " + name + "<Foo> or " + name + "<? extends Foo>"); } Type observableType = getParameterUpperBound(0, (ParameterizedType) returnType); Class<?> rawObservableType = getRawType(observableType); if (rawObservableType == Response.class) { if (!(observableType instanceof ParameterizedType)) { throw new IllegalStateException("Response must be parameterized" + " as Response<Foo> or Response<? extends Foo>"); } responseType = getParameterUpperBound(0, (ParameterizedType) observableType); } else if (rawObservableType == Result.class) { if (!(observableType instanceof ParameterizedType)) { throw new IllegalStateException("Result must be parameterized" + " as Result<Foo> or Result<? extends Foo>"); } responseType = getParameterUpperBound(0, (ParameterizedType) observableType); isResult = true; } else { responseType = observableType; isBody = true; } return new RxJava2CachedCallAdapter( mCachingSystem, responseType, mScheduler, retrofit, annotations, mAsync, isResult, isBody, isFlowable, isSingle, isMaybe, false); } private  RxJava2CachedCallAdapterFactory(@NonNull Cache<String, byte[]> cachingSystem, @Nullable Scheduler scheduler, boolean async); }
RxJava2CachedCallAdapterFactory extends CallAdapter.Factory { @Override public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) { Class<?> rawType = getRawType(returnType); if (rawType == Completable.class) { return new RxJava2CachedCallAdapter( mCachingSystem, Void.class, mScheduler, retrofit, annotations, mAsync, false, true, false, false, false, true); } boolean isFlowable = rawType == Flowable.class; boolean isSingle = rawType == Single.class; boolean isMaybe = rawType == Maybe.class; if (rawType != Observable.class && !isFlowable && !isSingle && !isMaybe) { return null; } boolean isResult = false; boolean isBody = false; Type responseType; if (!(returnType instanceof ParameterizedType)) { String name = isFlowable ? "Flowable" : isSingle ? "Single" : isMaybe ? "Maybe" : "Observable"; throw new IllegalStateException(name + " return type must be parameterized" + " as " + name + "<Foo> or " + name + "<? extends Foo>"); } Type observableType = getParameterUpperBound(0, (ParameterizedType) returnType); Class<?> rawObservableType = getRawType(observableType); if (rawObservableType == Response.class) { if (!(observableType instanceof ParameterizedType)) { throw new IllegalStateException("Response must be parameterized" + " as Response<Foo> or Response<? extends Foo>"); } responseType = getParameterUpperBound(0, (ParameterizedType) observableType); } else if (rawObservableType == Result.class) { if (!(observableType instanceof ParameterizedType)) { throw new IllegalStateException("Result must be parameterized" + " as Result<Foo> or Result<? extends Foo>"); } responseType = getParameterUpperBound(0, (ParameterizedType) observableType); isResult = true; } else { responseType = observableType; isBody = true; } return new RxJava2CachedCallAdapter( mCachingSystem, responseType, mScheduler, retrofit, annotations, mAsync, isResult, isBody, isFlowable, isSingle, isMaybe, false); } private  RxJava2CachedCallAdapterFactory(@NonNull Cache<String, byte[]> cachingSystem, @Nullable Scheduler scheduler, boolean async); static RxJava2CachedCallAdapterFactory create(@NonNull Context context, int appVersion); static RxJava2CachedCallAdapterFactory createAsync(@NonNull Context context, int appVersion); static RxJava2CachedCallAdapterFactory createWithScheduler(@NonNull Context context, int appVersion, Scheduler scheduler); static RxJava2CachedCallAdapterFactory create(@NonNull Cache<String, byte[]> cachingSystem); static RxJava2CachedCallAdapterFactory createAsync(@NonNull Cache<String, byte[]> cachingSystem); static RxJava2CachedCallAdapterFactory createWithScheduler(@NonNull Cache<String, byte[]> cachingSystem, Scheduler scheduler); @Override CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit); }
RxJava2CachedCallAdapterFactory extends CallAdapter.Factory { @Override public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) { Class<?> rawType = getRawType(returnType); if (rawType == Completable.class) { return new RxJava2CachedCallAdapter( mCachingSystem, Void.class, mScheduler, retrofit, annotations, mAsync, false, true, false, false, false, true); } boolean isFlowable = rawType == Flowable.class; boolean isSingle = rawType == Single.class; boolean isMaybe = rawType == Maybe.class; if (rawType != Observable.class && !isFlowable && !isSingle && !isMaybe) { return null; } boolean isResult = false; boolean isBody = false; Type responseType; if (!(returnType instanceof ParameterizedType)) { String name = isFlowable ? "Flowable" : isSingle ? "Single" : isMaybe ? "Maybe" : "Observable"; throw new IllegalStateException(name + " return type must be parameterized" + " as " + name + "<Foo> or " + name + "<? extends Foo>"); } Type observableType = getParameterUpperBound(0, (ParameterizedType) returnType); Class<?> rawObservableType = getRawType(observableType); if (rawObservableType == Response.class) { if (!(observableType instanceof ParameterizedType)) { throw new IllegalStateException("Response must be parameterized" + " as Response<Foo> or Response<? extends Foo>"); } responseType = getParameterUpperBound(0, (ParameterizedType) observableType); } else if (rawObservableType == Result.class) { if (!(observableType instanceof ParameterizedType)) { throw new IllegalStateException("Result must be parameterized" + " as Result<Foo> or Result<? extends Foo>"); } responseType = getParameterUpperBound(0, (ParameterizedType) observableType); isResult = true; } else { responseType = observableType; isBody = true; } return new RxJava2CachedCallAdapter( mCachingSystem, responseType, mScheduler, retrofit, annotations, mAsync, isResult, isBody, isFlowable, isSingle, isMaybe, false); } private  RxJava2CachedCallAdapterFactory(@NonNull Cache<String, byte[]> cachingSystem, @Nullable Scheduler scheduler, boolean async); static RxJava2CachedCallAdapterFactory create(@NonNull Context context, int appVersion); static RxJava2CachedCallAdapterFactory createAsync(@NonNull Context context, int appVersion); static RxJava2CachedCallAdapterFactory createWithScheduler(@NonNull Context context, int appVersion, Scheduler scheduler); static RxJava2CachedCallAdapterFactory create(@NonNull Cache<String, byte[]> cachingSystem); static RxJava2CachedCallAdapterFactory createAsync(@NonNull Cache<String, byte[]> cachingSystem); static RxJava2CachedCallAdapterFactory createWithScheduler(@NonNull Cache<String, byte[]> cachingSystem, Scheduler scheduler); @Override CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit);  }