@Test public void rawResultTypeThrows() { Type type = new TypeToken<Observable<Result>>() {}.getType(); CallAdapter.Factory factory = ObservableCallAdapterFactory.create(); try { factory.get(type); fail(); } catch (IllegalStateException e) { assertThat(e) .hasMessage("Result must be parameterized as Result<Foo> or Result<? extends Foo>"); } }
@Test public void responseType() { CallAdapter.Factory factory = ObservableCallAdapterFactory.create(); Type classType = new TypeToken<Observable<String>>() {}.getType(); assertThat(factory.get(classType).responseType()).isEqualTo(String.class); Type wilcardType = new TypeToken<Observable<? extends String>>() {}.getType(); assertThat(factory.get(wilcardType).responseType()).isEqualTo(String.class); Type genericType = new TypeToken<Observable<List<String>>>() {}.getType(); assertThat(factory.get(genericType).responseType()) // .isEqualTo(new TypeToken<List<String>>() {}.getType()); Type responseType = new TypeToken<Observable<Response<String>>>() {}.getType(); assertThat(factory.get(responseType).responseType()).isEqualTo(String.class); Type resultType = new TypeToken<Observable<Response<String>>>() {}.getType(); assertThat(factory.get(resultType).responseType()).isEqualTo(String.class); }
@Test public void nonObservableTypeReturnsNull() { CallAdapter.Factory factory = ObservableCallAdapterFactory.create(); CallAdapter<?> adapter = factory.get(String.class); assertThat(adapter).isNull(); }