use of retrofit2.http 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();
}
use of retrofit2.http in project retrofit by square.
the class RetrofitTest method callFactoryThrowingPropagates.
@Test
public void callFactoryThrowingPropagates() {
final RuntimeException cause = new RuntimeException("Broken!");
okhttp3.Call.Factory callFactory = new okhttp3.Call.Factory() {
@Override
public okhttp3.Call newCall(Request request) {
throw cause;
}
};
Retrofit retrofit = new Retrofit.Builder().baseUrl("http://example.com/").callFactory(callFactory).build();
server.enqueue(new MockResponse());
CallMethod service = retrofit.create(CallMethod.class);
Call<ResponseBody> call = service.getResponseBody();
try {
call.execute();
fail();
} catch (Exception e) {
assertThat(e).isSameAs(cause);
}
}
use of retrofit2.http in project retrofit by square.
the class RetrofitTest method callFactoryReturningNullThrows.
@Test
public void callFactoryReturningNullThrows() throws IOException {
okhttp3.Call.Factory callFactory = new okhttp3.Call.Factory() {
@Override
public okhttp3.Call newCall(Request request) {
return null;
}
};
Retrofit retrofit = new Retrofit.Builder().baseUrl("http://example.com/").callFactory(callFactory).build();
server.enqueue(new MockResponse());
CallMethod service = retrofit.create(CallMethod.class);
Call<ResponseBody> call = service.getResponseBody();
try {
call.execute();
fail();
} catch (NullPointerException e) {
assertThat(e).hasMessage("Call.Factory returned null.");
}
}
use of retrofit2.http 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();
}
use of retrofit2.http in project GitTest by xiaoxige.
the class MainActivity method publicImg.
private void publicImg(final String path) throws Exception {
new Thread(new Runnable() {
@Override
public void run() {
final Retrofit retrofit = new Retrofit.Builder().baseUrl("http://116.196.92.172:4869/").addConverterFactory(new StringConverterFactory()).addConverterFactory(GsonConverterFactory.create()).build();
final File file = new File(path);
final UpImageApi upImageApi = retrofit.create(UpImageApi.class);
RequestBody body = RequestBody.create(MediaType.parse("image/" + "png"), file);
try {
Call<ResponseBody> responseBodyCall = upImageApi.uploadImage(body);
Response<ResponseBody> response = responseBodyCall.execute();
String string = response.body().string();
Log.e("TAG", "string = " + string);
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
Aggregations