Minor: CallSubject.hasHttpStatus() throws unchecked CallFailedRuntimeException
diff --git a/fineract-client/src/main/java/org/apache/fineract/client/util/Calls.java b/fineract-client/src/main/java/org/apache/fineract/client/util/Calls.java
index c07cddd..50f82ef 100644
--- a/fineract-client/src/main/java/org/apache/fineract/client/util/Calls.java
+++ b/fineract-client/src/main/java/org/apache/fineract/client/util/Calls.java
@@ -42,15 +42,18 @@
* [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);
+ }
+ }
}
diff --git a/fineract-client/src/main/java/org/apache/fineract/client/util/Parts.java b/fineract-client/src/main/java/org/apache/fineract/client/util/Parts.java
index 486842f..40e4ffe 100644
--- a/fineract-client/src/main/java/org/apache/fineract/client/util/Parts.java
+++ b/fineract-client/src/main/java/org/apache/fineract/client/util/Parts.java
@@ -37,7 +37,7 @@
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);
}
diff --git a/fineract-client/src/test/java/org/apache/fineract/client/testutil/CallSubject.java b/fineract-client/src/test/java/org/apache/fineract/client/testutil/CallSubject.java
index edd4fae..f2e6c7b 100644
--- a/fineract-client/src/test/java/org/apache/fineract/client/testutil/CallSubject.java
+++ b/fineract-client/src/test/java/org/apache/fineract/client/testutil/CallSubject.java
@@ -21,8 +21,8 @@
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 @@
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);
}
}
diff --git a/fineract-client/src/test/java/org/apache/fineract/integrationtests/newstyle/DocumentTest.java b/fineract-client/src/test/java/org/apache/fineract/integrationtests/newstyle/DocumentTest.java
index c1d5d5d..aa690ea 100644
--- a/fineract-client/src/test/java/org/apache/fineract/integrationtests/newstyle/DocumentTest.java
+++ b/fineract-client/src/test/java/org/apache/fineract/integrationtests/newstyle/DocumentTest.java
@@ -43,7 +43,7 @@
@Test
@Order(1)
- void retrieveAllDocuments() throws IOException {
+ void retrieveAllDocuments() {
assertThat(ok(fineract().documents.retrieveAllDocuments("clients", clientId))).isNotNull();
}
@@ -100,14 +100,14 @@
@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);
}
}