summaryrefslogtreecommitdiff
path: root/app/src/test/java/se/leap/bitmaskclient/testutils/BackendMockResponses/UpdatedCertificateBackendResponse.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/test/java/se/leap/bitmaskclient/testutils/BackendMockResponses/UpdatedCertificateBackendResponse.java')
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/testutils/BackendMockResponses/UpdatedCertificateBackendResponse.java95
1 files changed, 38 insertions, 57 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/testutils/BackendMockResponses/UpdatedCertificateBackendResponse.java b/app/src/test/java/se/leap/bitmaskclient/testutils/BackendMockResponses/UpdatedCertificateBackendResponse.java
index 232649a1..1da18f76 100644
--- a/app/src/test/java/se/leap/bitmaskclient/testutils/BackendMockResponses/UpdatedCertificateBackendResponse.java
+++ b/app/src/test/java/se/leap/bitmaskclient/testutils/BackendMockResponses/UpdatedCertificateBackendResponse.java
@@ -16,82 +16,63 @@
*/
package se.leap.bitmaskclient.testutils.BackendMockResponses;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
+import static se.leap.bitmaskclient.testutils.TestSetupHelper.getInputAsString;
+
+import android.util.Pair;
+
+import androidx.annotation.NonNull;
import java.io.IOException;
+import java.util.List;
import javax.net.ssl.SSLHandshakeException;
-import static se.leap.bitmaskclient.testutils.TestSetupHelper.getInputAsString;
+import okhttp3.OkHttpClient;
+import se.leap.bitmaskclient.providersetup.ProviderApiConnector;
/**
* Created by cyberta on 10.01.18.
*/
-public class UpdatedCertificateBackendResponse extends BaseBackendResponse {
+public class UpdatedCertificateBackendResponse implements ProviderApiConnector.ProviderApiConnectorInterface {
static volatile boolean wasCACertCalled = false;
-
- public UpdatedCertificateBackendResponse() throws IOException {
- super();
- }
-
@Override
- public Answer<String> getAnswerForRequestStringFromServer() {
- return new Answer<String>() {
-
- @Override
- public String answer(InvocationOnMock invocation) throws Throwable {
- String url = (String) invocation.getArguments()[0];
-
- if (url.contains("/provider.json")) {
- if (!wasCACertCalled) {
- throw new SSLHandshakeException("Updated certificate on server side");
- }
- //download provider json
- return getInputAsString(getClass().getClassLoader().getResourceAsStream("riseup.net.json"));
- } else if (url.contains("/ca.crt")) {
- //download provider ca cert
- wasCACertCalled = true;
- return getInputAsString(getClass().getClassLoader().getResourceAsStream("updated_cert.pem"));
- } else if (url.contains("config/eip-service.json")) {
- // download provider service json containing gateways, locations and openvpn settings
- if (!wasCACertCalled) {
- throw new SSLHandshakeException("Updated certificate on server side");
- }
- return getInputAsString(getClass().getClassLoader().getResourceAsStream("riseup.service.json"));
- }
-
- return null;
- }
- };
+ public boolean delete(OkHttpClient okHttpClient, String deleteUrl) throws RuntimeException, IOException {
+ if (!wasCACertCalled) {
+ throw new SSLHandshakeException("Updated certificate on server side");
+ }
+ return true;
}
@Override
- public Answer<Boolean> getAnswerForCanConnect() {
- return new Answer<Boolean>() {
- @Override
- public Boolean answer(InvocationOnMock invocation) throws Throwable {
- if (!wasCACertCalled) {
- throw new SSLHandshakeException("Updated certificate on server side");
- }
- return true;
- }
- };
+ public boolean canConnect(@NonNull OkHttpClient okHttpClient, String url) throws RuntimeException, IOException {
+ if (!wasCACertCalled) {
+ throw new SSLHandshakeException("Updated certificate on server side");
+ }
+ return true;
}
@Override
- public Answer<Boolean> getAnswerForDelete() {
- return new Answer<Boolean>() {
- @Override
- public Boolean answer(InvocationOnMock invocation) throws Throwable {
- if (!wasCACertCalled) {
- throw new SSLHandshakeException("Updated certificate on server side");
- }
- return true;
+ public String requestStringFromServer(@NonNull String url, @NonNull String requestMethod, String jsonString, @NonNull List<Pair<String, String>> headerArgs, @NonNull OkHttpClient okHttpClient) throws RuntimeException, IOException {
+ if (url.contains("/provider.json")) {
+ if (!wasCACertCalled) {
+ throw new SSLHandshakeException("Updated certificate on server side");
}
- };
- }
+ //download provider json
+ return getInputAsString(getClass().getClassLoader().getResourceAsStream("riseup.net.json"));
+ } else if (url.contains("/ca.crt")) {
+ //download provider ca cert
+ wasCACertCalled = true;
+ return getInputAsString(getClass().getClassLoader().getResourceAsStream("updated_cert.pem"));
+ } else if (url.contains("config/eip-service.json")) {
+ // download provider service json containing gateways, locations and openvpn settings
+ if (!wasCACertCalled) {
+ throw new SSLHandshakeException("Updated certificate on server side");
+ }
+ return getInputAsString(getClass().getClassLoader().getResourceAsStream("riseup.service.json"));
+ }
+ return null;
+ }
}