diff --git a/pom.xml b/pom.xml
index 14f47cca..c95f46ac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -126,9 +126,15 @@
- org.mockito
- mockito-core
- 4.11.0
+ org.powermock
+ powermock-module-junit4
+ 2.0.9
+ test
+
+
+ org.powermock
+ powermock-api-mockito2
+ 2.0.9
test
@@ -209,7 +215,7 @@
org.jacoco
jacoco-maven-plugin
- 0.8.14
+ 0.8.7
prepare-agent
@@ -295,7 +301,7 @@
org.sonatype.central
central-publishing-maven-plugin
- 0.10.0
+ 0.4.0
true
central
diff --git a/src/test/java/com/skyflow/utils/HttpUtilityTests.java b/src/test/java/com/skyflow/utils/HttpUtilityTests.java
index c9595bb7..f7214690 100644
--- a/src/test/java/com/skyflow/utils/HttpUtilityTests.java
+++ b/src/test/java/com/skyflow/utils/HttpUtilityTests.java
@@ -6,9 +6,11 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -24,10 +26,13 @@
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
-@RunWith(MockitoJUnitRunner.class)
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({URL.class, HttpURLConnection.class})
public class HttpUtilityTests {
private static String INVALID_EXCEPTION_THROWN = "Should not have thrown any exception";
+ @InjectMocks
+ HttpUtility httpUtility;
@Mock
OutputStream outputStream;
private String expected;
@@ -55,6 +60,7 @@ protected URLConnection openConnection(final URL arg0) throws IOException {
}
@Test
+ @PrepareForTest({URL.class, HttpURLConnection.class})
public void testSendRequest() {
try {
given(mockConnection.getRequestProperty("content-type")).willReturn("application/json");
@@ -62,7 +68,7 @@ public void testSendRequest() {
headers.put("content-type", "application/json");
JsonObject params = new JsonObject();
params.addProperty("key", "value");
- String response = HttpUtility.sendRequest("GET", url, params, headers);
+ String response = httpUtility.sendRequest("GET", url, params, headers);
Assert.assertEquals(expected, response);
} catch (Exception e) {
fail(INVALID_EXCEPTION_THROWN);
@@ -71,6 +77,7 @@ public void testSendRequest() {
@Test
+ @PrepareForTest({URL.class, HttpURLConnection.class})
public void testSendRequestFormData() {
try {
given(mockConnection.getRequestProperty("content-type")).willReturn("multipart/form-data");
@@ -78,7 +85,7 @@ public void testSendRequestFormData() {
headers.put("content-type", "multipart/form-data");
JsonObject params = new JsonObject();
params.addProperty("key", "value");
- String response = HttpUtility.sendRequest("GET", url, params, headers);
+ String response = httpUtility.sendRequest("GET", url, params, headers);
Assert.assertEquals(expected, response);
} catch (Exception e) {
fail(INVALID_EXCEPTION_THROWN);
@@ -86,6 +93,7 @@ public void testSendRequestFormData() {
}
@Test
+ @PrepareForTest({URL.class, HttpURLConnection.class})
public void testSendRequestFormURLEncoded() {
try {
given(mockConnection.getRequestProperty("content-type")).willReturn("application/x-www-form-urlencoded");
@@ -93,7 +101,7 @@ public void testSendRequestFormURLEncoded() {
headers.put("content-type", "application/x-www-form-urlencoded");
JsonObject params = new JsonObject();
params.addProperty("key", "value");
- String response = HttpUtility.sendRequest("GET", url, params, headers);
+ String response = httpUtility.sendRequest("GET", url, params, headers);
Assert.assertEquals(expected, response);
} catch (Exception e) {
fail(INVALID_EXCEPTION_THROWN);
@@ -101,10 +109,11 @@ public void testSendRequestFormURLEncoded() {
}
@Test
+ @PrepareForTest({URL.class, HttpURLConnection.class})
public void testSendRequestError() {
try {
given(mockConnection.getResponseCode()).willReturn(500);
- String response = HttpUtility.sendRequest("GET", url, null, null);
+ String response = httpUtility.sendRequest("GET", url, null, null);
} catch (SkyflowException e) {
Assert.assertEquals(500, e.getHttpCode());
Assert.assertEquals(new Integer(123), e.getGrpcCode());