use of com.azure.android.core.test.MyRestException in project azure-sdk-for-android by Azure.
the class RestProxyTests method putRequestWithUnexpectedResponseAndExceptionType.
@Test
public void putRequestWithUnexpectedResponseAndExceptionType() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service9.class).putWithUnexpectedResponseAndExceptionType("I'm the body!", new Callback<Response<HttpBinJSON>>() {
@Override
public void onSuccess(Response<HttpBinJSON> response) {
cbResult.response = response;
latch.countDown();
}
@Override
public void onFailure(Throwable error) {
cbResult.error = error;
latch.countDown();
}
});
awaitOnLatch(latch, "putRequestWithUnexpectedResponseAndExceptionType");
if (cbResult.response != null) {
fail("Expected HttpResponseException would be thrown.");
} else {
Assertions.assertNotNull(cbResult.error);
Assertions.assertTrue(cbResult.error instanceof MyRestException, "Expected MyRestException would be thrown. Instead got " + cbResult.error.getClass().getSimpleName());
MyRestException e = (MyRestException) cbResult.error;
assertNotNull(e.getValue());
assertEquals("I'm the body!", e.getValue().data());
}
}
use of com.azure.android.core.test.MyRestException in project azure-sdk-for-android by Azure.
the class RestProxyTests method putRequestWithUnexpectedResponseAndDeterminedExceptionType.
@Test
public void putRequestWithUnexpectedResponseAndDeterminedExceptionType() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service9.class).putWithUnexpectedResponseAndDeterminedExceptionType("I'm the body!", new Callback<Response<HttpBinJSON>>() {
@Override
public void onSuccess(Response<HttpBinJSON> response) {
cbResult.response = response;
latch.countDown();
}
@Override
public void onFailure(Throwable error) {
cbResult.error = error;
latch.countDown();
}
});
awaitOnLatch(latch, "putRequestWithUnexpectedResponseAndDeterminedExceptionType");
if (cbResult.response != null) {
fail("Expected HttpResponseException would be thrown.");
} else {
Assertions.assertNotNull(cbResult.error);
Assertions.assertTrue(cbResult.error instanceof MyRestException, "Expected MyRestException would be thrown. Instead got " + cbResult.error.getClass().getSimpleName());
MyRestException e = (MyRestException) cbResult.error;
assertNotNull(e.getValue());
assertEquals("I'm the body!", e.getValue().data());
}
}
use of com.azure.android.core.test.MyRestException in project azure-sdk-for-android by Azure.
the class RestProxyTests method putRequestWithUnexpectedResponseAndFallthroughExceptionType.
@Test
public void putRequestWithUnexpectedResponseAndFallthroughExceptionType() {
CountDownLatch latch = new CountDownLatch(1);
CallbackResult<HttpBinJSON> cbResult = new CallbackResult<>();
createService(Service9.class).putWithUnexpectedResponseAndFallthroughExceptionType("I'm the body!", new Callback<Response<HttpBinJSON>>() {
@Override
public void onSuccess(Response<HttpBinJSON> response) {
cbResult.response = response;
latch.countDown();
}
@Override
public void onFailure(Throwable error) {
cbResult.error = error;
latch.countDown();
}
});
awaitOnLatch(latch, "putRequestWithUnexpectedResponseAndFallthroughExceptionType");
if (cbResult.response != null) {
fail("Expected HttpResponseException would be thrown.");
} else {
Assertions.assertNotNull(cbResult.error);
Assertions.assertTrue(cbResult.error instanceof MyRestException, "Expected MyRestException would be thrown. Instead got " + cbResult.error.getClass().getSimpleName());
MyRestException e = (MyRestException) cbResult.error;
assertNotNull(e.getValue());
assertEquals("I'm the body!", e.getValue().data());
}
}
Aggregations