### Question:
LiveDataCallAdapterFactory extends CallAdapter.Factory { @Nullable @Override public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) { if (getRawType(returnType) != LiveData.class) { return null; } if (!(returnType instanceof ParameterizedType)) { throw new IllegalStateException("Response must be parametrized as " + "LiveData<Resource> or LiveData<? extends Resource>"); } Type responseType = getParameterUpperBound(0, (ParameterizedType) returnType); if (getRawType(responseType) == Response.class) { if (!(responseType instanceof ParameterizedType)) { throw new IllegalStateException("Response must be parametrized as " + "LiveData<Response<Resource>> or LiveData<Response<? extends Resource>>"); } return new LiveDataResponseCallAdapter<>(responseType); } return new LiveDataBodyCallAdapter<>(getParameterUpperBound(0, (ParameterizedType) returnType)); } private  LiveDataCallAdapterFactory(); static LiveDataCallAdapterFactory create(); @Nullable @Override CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit);  }### Answer:
@Test public void responseType() { Type bodyClass = new TypeToken<LiveData<Resource<String>>>() {}.getType(); assertThat(factory.get(bodyClass, NO_ANNOTATIONS, retrofit).responseType()) .isEqualTo(new TypeToken<Resource<String>>() {}.getType()); Type bodyWildcard = new TypeToken<LiveData<Resource<? extends String>>>() {}.getType(); assertThat(factory.get(bodyWildcard, NO_ANNOTATIONS, retrofit).responseType()) .isEqualTo(new TypeToken<Resource<? extends String>>() {}.getType()); Type responseType = new TypeToken<LiveData<Response<Resource<String>>>>() {}.getType(); assertThat(factory.get(responseType, NO_ANNOTATIONS, retrofit).responseType()) .isEqualTo(new TypeToken<Response<Resource<String>>>() {}.getType()); Type responseTypeWildcard = new TypeToken<LiveData<Response<Resource<? extends String>>>>() {}.getType(); assertThat(factory.get(responseTypeWildcard, NO_ANNOTATIONS, retrofit).responseType()) .isEqualTo(new TypeToken<Response<Resource<? extends String>>>() {}.getType()); }
@Test public void nonListenableFutureReturnsNull() { CallAdapter<?, ?> adapter = factory.get(String.class, NO_ANNOTATIONS, retrofit); assertThat(adapter).isNull(); }
@Test public void rawTypesThrows() { Type liveDataType = new TypeToken<LiveData>() {}.getType(); try { CallAdapter callAdapter = factory.get(liveDataType, NO_ANNOTATIONS, retrofit); fail("Unespected callAdapter = " + callAdapter.getClass().getName()); } catch (IllegalStateException e) { assertThat(e).hasMessageThat().isEqualTo("Response must be parametrized as " + "LiveData<Resource> or LiveData<? extends Resource>"); } }
@Test public void rawResponseTypesThrows() { Type liveDataType = new TypeToken<LiveData<Response>>() {}.getType(); try { CallAdapter callAdapter = factory.get(liveDataType, NO_ANNOTATIONS, retrofit); fail("Unespected callAdapter = " + callAdapter.getClass().getName()); } catch (IllegalStateException e) { assertThat(e).hasMessageThat().isEqualTo("Response must be parametrized as " + "LiveData<Response<Resource>> or LiveData<Response<? extends Resource>>"); } }