Search in sources :

Example 1 with DelegatingCallAdapterFactory

use of retrofit2.helpers.DelegatingCallAdapterFactory in project retrofit by square.

the class RetrofitTest method callAdapterFactoryDelegateNoMatchThrows.

@Test
public void callAdapterFactoryDelegateNoMatchThrows() {
    Type type = String.class;
    Annotation[] annotations = new Annotation[0];
    DelegatingCallAdapterFactory delegatingFactory1 = new DelegatingCallAdapterFactory();
    DelegatingCallAdapterFactory delegatingFactory2 = new DelegatingCallAdapterFactory();
    NonMatchingCallAdapterFactory nonMatchingFactory = new NonMatchingCallAdapterFactory();
    Retrofit retrofit = new Retrofit.Builder().baseUrl("http://example.com/").addCallAdapterFactory(delegatingFactory1).addCallAdapterFactory(delegatingFactory2).addCallAdapterFactory(nonMatchingFactory).build();
    try {
        retrofit.callAdapter(type, annotations);
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e).hasMessage("" + "Could not locate call adapter for class java.lang.String.\n" + "  Skipped:\n" + "   * retrofit2.helpers.DelegatingCallAdapterFactory\n" + "   * retrofit2.helpers.DelegatingCallAdapterFactory\n" + "  Tried:\n" + "   * retrofit2.helpers.NonMatchingCallAdapterFactory\n" + "   * retrofit2.DefaultCallAdapterFactory");
    }
    assertThat(delegatingFactory1.called).isTrue();
    assertThat(delegatingFactory2.called).isTrue();
    assertThat(nonMatchingFactory.called).isTrue();
}
Also used : DelegatingCallAdapterFactory(retrofit2.helpers.DelegatingCallAdapterFactory) MediaType(okhttp3.MediaType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) NonMatchingCallAdapterFactory(retrofit2.helpers.NonMatchingCallAdapterFactory) Annotation(java.lang.annotation.Annotation) Test(org.junit.Test)

Aggregations

Annotation (java.lang.annotation.Annotation)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 MediaType (okhttp3.MediaType)1 Test (org.junit.Test)1 DelegatingCallAdapterFactory (retrofit2.helpers.DelegatingCallAdapterFactory)1 NonMatchingCallAdapterFactory (retrofit2.helpers.NonMatchingCallAdapterFactory)1