Minor: CallSubject.hasHttpStatus() throws unchecked CallFailedRuntimeException

This commit is contained in:
Michael Vorburger
2020-10-24 23:36:03 +02:00
committed by Aleksandar Vidakovic
parent 43ef6e1983
commit 420d26a679
4 changed files with 16 additions and 13 deletions
@@ -42,15 +42,18 @@ public final class Calls {
* [200..300) successful
*/
public static <T> T ok(Call<T> call) throws CallFailedRuntimeException {
Response<T> response;
try {
response = call.execute();
} catch (IOException e) {
throw new CallFailedRuntimeException(call, e);
}
Response<T> response = executeU(call);
if (response.isSuccessful()) {
return response.body();
}
throw new CallFailedRuntimeException(call, response);
}
public static <T> Response<T> executeU(Call<T> call) throws CallFailedRuntimeException {
try {
return call.execute();
} catch (IOException e) {
throw new CallFailedRuntimeException(call, e);
}
}
}
@@ -37,7 +37,7 @@ public final class Parts {
return Part.createFormData("file", file.getName(), rb);
}
public static Part fromFile(String fileName, byte[] bytes) {
public static Part fromBytes(String fileName, byte[] bytes) {
RequestBody rb = RequestBody.create(bytes, mediaType(fileName));
return Part.createFormData("file", fileName, rb);
}
@@ -21,8 +21,8 @@ package org.apache.fineract.client.testutil;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject;
import com.google.common.truth.Truth;
import java.io.IOException;
import javax.annotation.Nullable;
import org.apache.fineract.client.util.Calls;
import retrofit2.Call;
/**
@@ -49,7 +49,7 @@ public class CallSubject extends Subject {
this.actual = actual;
}
public void hasHttpStatus(int expectedHttpStatus) throws IOException {
check("httpStatus").that(actual.execute().code()).isEqualTo(expectedHttpStatus);
public void hasHttpStatus(int expectedHttpStatus) {
check("httpStatus").that(Calls.executeU(actual).code()).isEqualTo(expectedHttpStatus);
}
}
@@ -43,7 +43,7 @@ public class DocumentTest extends IntegrationTest {
@Test
@Order(1)
void retrieveAllDocuments() throws IOException {
void retrieveAllDocuments() {
assertThat(ok(fineract().documents.retrieveAllDocuments("clients", clientId))).isNotNull();
}
@@ -100,14 +100,14 @@ public class DocumentTest extends IntegrationTest {
@Test
@Order(99)
void deleteDocument() throws IOException {
void deleteDocument() {
ok(fineract().documents.deleteDocument("clients", clientId, documentId));
assertThat(fineract().documents.getDocument("clients", clientId, documentId)).hasHttpStatus(404);
}
@Order(9999)
@Test // FINERACT-1036
void createDocumentBadArgs() throws IOException {
void createDocumentBadArgs() {
assertThat(fineract().documents.createDocument("clients", 123L, null, "test.pdf", null)).hasHttpStatus(400);
}
}