<https://github.com/square/retrofit/pull/2859>
# squarelibraries
j
j
@jw about that pr, if in your test you set the response code to 204, it will return null, right? so if instead enqueuing this one
server.enqueue(new MockResponse().setBody("Hi"));
you do
server.enqueue(new MockResponse().setResponseCode(204));
the test will fail, won't it? It'd be interesting to have it working for when you expect a 204
j
It always returns
Unit.INSTANCE
It never even looks at the body
j
then must be just usint the conversion factory, it works when the response code is a 200, but in my tests when I don't set a body and use a 204, if returns null
Copy code
@Test
    fun returnsUnitNotNull() {
        val retrofit = Retrofit.Builder()
                .baseUrl(server.url("/"))
                .addConverterFactory(UnitConverterFactory)
                .addConverterFactory(GsonConverterFactory.create())
                .build()
        val example = retrofit.create(Service::class.java)

        server.enqueue(MockResponse().setResponseCode(204))
        val response = example.empty().execute()

        assertNull(response.body())
    }
might be something I'm missing
when I set the code to 204, the converter doesn't even get called
j
Oh I missed 204. I just saw you weren't setting a body. Yeah we don't even call a converter then
j
🤔 so no way I can get a Unit if the code is a 204, then
sad days...
well, not using a converter i guess
thanks! I'll find work around 🙂
j
I really don't want to bake in support for something like this so deep inside of Retrofit. Not sure how to resolve it.
j
understandable, thanks!