Search in sources :

Example 1 with NonMatchingCallAdapterFactory

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

the class RetrofitTest method callAdapterFactoryNoMatchThrows.

@Test
public void callAdapterFactoryNoMatchThrows() {
    Type type = String.class;
    Annotation[] annotations = new Annotation[0];
    NonMatchingCallAdapterFactory nonMatchingFactory = new NonMatchingCallAdapterFactory();
    Retrofit retrofit = new Retrofit.Builder().baseUrl("http://example.com/").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" + "  Tried:\n" + "   * retrofit2.helpers.NonMatchingCallAdapterFactory\n" + "   * retrofit2.DefaultCallAdapterFactory");
    }
    assertThat(nonMatchingFactory.called).isTrue();
}
Also used : 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)

Example 2 with NonMatchingCallAdapterFactory

use of retrofit2.helpers.NonMatchingCallAdapterFactory 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)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 MediaType (okhttp3.MediaType)2 Test (org.junit.Test)2 NonMatchingCallAdapterFactory (retrofit2.helpers.NonMatchingCallAdapterFactory)2 DelegatingCallAdapterFactory (retrofit2.helpers.DelegatingCallAdapterFactory)1