Search in sources :

Example 1 with NonMatchingConverterFactory

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

the class RetrofitTest method requestConverterFactoryNoMatchThrows.

@Test
public void requestConverterFactoryNoMatchThrows() {
    Type type = String.class;
    Annotation[] annotations = new Annotation[0];
    NonMatchingConverterFactory nonMatchingFactory = new NonMatchingConverterFactory();
    Retrofit retrofit = new Retrofit.Builder().baseUrl("http://example.com/").addConverterFactory(nonMatchingFactory).build();
    try {
        retrofit.requestBodyConverter(type, annotations, annotations);
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e).hasMessage("" + "Could not locate RequestBody converter for class java.lang.String.\n" + "  Tried:\n" + "   * retrofit2.BuiltInConverters\n" + "   * retrofit2.helpers.NonMatchingConverterFactory");
    }
    assertThat(nonMatchingFactory.called).isTrue();
}
Also used : MediaType(okhttp3.MediaType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Annotation(java.lang.annotation.Annotation) NonMatchingConverterFactory(retrofit2.helpers.NonMatchingConverterFactory) Test(org.junit.Test)

Example 2 with NonMatchingConverterFactory

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

the class RetrofitTest method requestConverterFactorySkippedNoMatchThrows.

@Test
public void requestConverterFactorySkippedNoMatchThrows() {
    Type type = String.class;
    Annotation[] annotations = new Annotation[0];
    NonMatchingConverterFactory nonMatchingFactory1 = new NonMatchingConverterFactory();
    NonMatchingConverterFactory nonMatchingFactory2 = new NonMatchingConverterFactory();
    Retrofit retrofit = new Retrofit.Builder().baseUrl("http://example.com/").addConverterFactory(nonMatchingFactory1).addConverterFactory(nonMatchingFactory2).build();
    try {
        retrofit.nextRequestBodyConverter(nonMatchingFactory1, type, annotations, annotations);
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e).hasMessage("" + "Could not locate RequestBody converter for class java.lang.String.\n" + "  Skipped:\n" + "   * retrofit2.BuiltInConverters\n" + "   * retrofit2.helpers.NonMatchingConverterFactory\n" + "  Tried:\n" + "   * retrofit2.helpers.NonMatchingConverterFactory");
    }
    assertThat(nonMatchingFactory1.called).isFalse();
    assertThat(nonMatchingFactory2.called).isTrue();
}
Also used : MediaType(okhttp3.MediaType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Annotation(java.lang.annotation.Annotation) NonMatchingConverterFactory(retrofit2.helpers.NonMatchingConverterFactory) Test(org.junit.Test)

Example 3 with NonMatchingConverterFactory

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

the class RetrofitTest method responseConverterFactoryNoMatchThrows.

@Test
public void responseConverterFactoryNoMatchThrows() {
    Type type = String.class;
    Annotation[] annotations = new Annotation[0];
    NonMatchingConverterFactory nonMatchingFactory = new NonMatchingConverterFactory();
    Retrofit retrofit = new Retrofit.Builder().baseUrl("http://example.com/").addConverterFactory(nonMatchingFactory).build();
    try {
        retrofit.responseBodyConverter(type, annotations);
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e).hasMessage("" + "Could not locate ResponseBody converter for class java.lang.String.\n" + "  Tried:\n" + "   * retrofit2.BuiltInConverters\n" + "   * retrofit2.helpers.NonMatchingConverterFactory");
    }
    assertThat(nonMatchingFactory.called).isTrue();
}
Also used : MediaType(okhttp3.MediaType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Annotation(java.lang.annotation.Annotation) NonMatchingConverterFactory(retrofit2.helpers.NonMatchingConverterFactory) Test(org.junit.Test)

Example 4 with NonMatchingConverterFactory

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

the class RetrofitTest method responseConverterFactorySkippedNoMatchThrows.

@Test
public void responseConverterFactorySkippedNoMatchThrows() {
    Type type = String.class;
    Annotation[] annotations = new Annotation[0];
    NonMatchingConverterFactory nonMatchingFactory1 = new NonMatchingConverterFactory();
    NonMatchingConverterFactory nonMatchingFactory2 = new NonMatchingConverterFactory();
    Retrofit retrofit = new Retrofit.Builder().baseUrl("http://example.com/").addConverterFactory(nonMatchingFactory1).addConverterFactory(nonMatchingFactory2).build();
    try {
        retrofit.nextResponseBodyConverter(nonMatchingFactory1, type, annotations);
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e).hasMessage("" + "Could not locate ResponseBody converter for class java.lang.String.\n" + "  Skipped:\n" + "   * retrofit2.BuiltInConverters\n" + "   * retrofit2.helpers.NonMatchingConverterFactory\n" + "  Tried:\n" + "   * retrofit2.helpers.NonMatchingConverterFactory");
    }
    assertThat(nonMatchingFactory1.called).isFalse();
    assertThat(nonMatchingFactory2.called).isTrue();
}
Also used : MediaType(okhttp3.MediaType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Annotation(java.lang.annotation.Annotation) NonMatchingConverterFactory(retrofit2.helpers.NonMatchingConverterFactory) Test(org.junit.Test)

Aggregations

Annotation (java.lang.annotation.Annotation)4 ParameterizedType (java.lang.reflect.ParameterizedType)4 Type (java.lang.reflect.Type)4 MediaType (okhttp3.MediaType)4 Test (org.junit.Test)4 NonMatchingConverterFactory (retrofit2.helpers.NonMatchingConverterFactory)4