Search in sources :

Example 1 with NullObjectConverterFactory

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

the class RequestBuilderTest method fieldParamMapsConvertedToNullShouldError.

@Test
public void fieldParamMapsConvertedToNullShouldError() throws Exception {
    class Example {

        @FormUrlEncoded
        @POST("/query")
        Call<ResponseBody> queryPath(@FieldMap Map<String, String> a) {
            return null;
        }
    }
    Retrofit.Builder retrofitBuilder = new Retrofit.Builder().baseUrl("http://example.com").addConverterFactory(new NullObjectConverterFactory());
    Map<String, String> queryMap = Collections.singletonMap("kit", "kat");
    try {
        buildRequest(Example.class, retrofitBuilder, queryMap);
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e).hasMessageContaining("Field map value 'kat' converted to null by retrofit2.helpers.NullObjectConverterFactory$1 for key 'kit'.");
    }
}
Also used : NullObjectConverterFactory(retrofit2.helpers.NullObjectConverterFactory) FieldMap(retrofit2.http.FieldMap) PartMap(retrofit2.http.PartMap) HashMap(java.util.HashMap) HeaderMap(retrofit2.http.HeaderMap) FieldMap(retrofit2.http.FieldMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) QueryMap(retrofit2.http.QueryMap) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 2 with NullObjectConverterFactory

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

the class RequestBuilderTest method queryParamsSkippedIfConvertedToNull.

@Test
public void queryParamsSkippedIfConvertedToNull() throws Exception {
    class Example {

        @GET("/query")
        Call<ResponseBody> queryPath(@Query("a") Object a) {
            return null;
        }
    }
    Retrofit.Builder retrofitBuilder = new Retrofit.Builder().baseUrl("http://example.com").addConverterFactory(new NullObjectConverterFactory());
    Request request = buildRequest(Example.class, retrofitBuilder, "Ignored");
    assertThat(request.url().toString()).doesNotContain("Ignored");
}
Also used : NullObjectConverterFactory(retrofit2.helpers.NullObjectConverterFactory) Query(retrofit2.http.Query) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 3 with NullObjectConverterFactory

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

the class RequestBuilderTest method fieldParamsSkippedIfConvertedToNull.

@Test
public void fieldParamsSkippedIfConvertedToNull() throws Exception {
    class Example {

        @FormUrlEncoded
        @POST("/query")
        Call<ResponseBody> queryPath(@Field("a") Object a) {
            return null;
        }
    }
    Retrofit.Builder retrofitBuilder = new Retrofit.Builder().baseUrl("http://example.com").addConverterFactory(new NullObjectConverterFactory());
    Request request = buildRequest(Example.class, retrofitBuilder, "Ignored");
    assertThat(request.url().toString()).doesNotContain("Ignored");
}
Also used : NullObjectConverterFactory(retrofit2.helpers.NullObjectConverterFactory) Field(retrofit2.http.Field) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 4 with NullObjectConverterFactory

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

the class RequestBuilderTest method queryParamMapsConvertedToNullShouldError.

@Test
public void queryParamMapsConvertedToNullShouldError() throws Exception {
    class Example {

        @GET("/query")
        Call<ResponseBody> queryPath(@QueryMap Map<String, String> a) {
            return null;
        }
    }
    Retrofit.Builder retrofitBuilder = new Retrofit.Builder().baseUrl("http://example.com").addConverterFactory(new NullObjectConverterFactory());
    Map<String, String> queryMap = Collections.singletonMap("kit", "kat");
    try {
        buildRequest(Example.class, retrofitBuilder, queryMap);
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e).hasMessageContaining("Query map value 'kat' converted to null by retrofit2.helpers.NullObjectConverterFactory$1 for key 'kit'.");
    }
}
Also used : NullObjectConverterFactory(retrofit2.helpers.NullObjectConverterFactory) QueryMap(retrofit2.http.QueryMap) PartMap(retrofit2.http.PartMap) HashMap(java.util.HashMap) HeaderMap(retrofit2.http.HeaderMap) FieldMap(retrofit2.http.FieldMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) QueryMap(retrofit2.http.QueryMap) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Aggregations

ResponseBody (okhttp3.ResponseBody)4 Test (org.junit.Test)4 NullObjectConverterFactory (retrofit2.helpers.NullObjectConverterFactory)4 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Request (okhttp3.Request)2 FieldMap (retrofit2.http.FieldMap)2 HeaderMap (retrofit2.http.HeaderMap)2 PartMap (retrofit2.http.PartMap)2 QueryMap (retrofit2.http.QueryMap)2 Field (retrofit2.http.Field)1 Query (retrofit2.http.Query)1