diff --git a/app/src/main/java/com/m2049r/xmrwallet/util/NetCipherHelper.java b/app/src/main/java/com/m2049r/xmrwallet/util/NetCipherHelper.java index 95bd61e2..418e97f9 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/util/NetCipherHelper.java +++ b/app/src/main/java/com/m2049r/xmrwallet/util/NetCipherHelper.java @@ -323,6 +323,7 @@ public class NetCipherHelper implements StatusCallback { } private OkHttpClient getClient() { + if (mockClient != null) return mockClient; // Unit-test mode final OkHttpClient client = getInstance().client; if ((username != null) && (!username.isEmpty())) { final DigestAuthenticator authenticator = new DigestAuthenticator(new Credentials(username, password)); @@ -349,6 +350,9 @@ public class NetCipherHelper implements StatusCallback { } return builder.build(); } + + // for unit tests only + static public OkHttpClient mockClient = null; } private static final String PREFS_NAME = "tor"; diff --git a/app/src/test/java/com/m2049r/xmrwallet/service/exchange/ecb/ExchangeRateTest.java b/app/src/test/java/com/m2049r/xmrwallet/service/exchange/ecb/ExchangeRateTest.java index a9dc9fdb..ef937247 100644 --- a/app/src/test/java/com/m2049r/xmrwallet/service/exchange/ecb/ExchangeRateTest.java +++ b/app/src/test/java/com/m2049r/xmrwallet/service/exchange/ecb/ExchangeRateTest.java @@ -20,6 +20,7 @@ import com.m2049r.xmrwallet.service.exchange.api.ExchangeApi; import com.m2049r.xmrwallet.service.exchange.api.ExchangeCallback; import com.m2049r.xmrwallet.service.exchange.api.ExchangeException; import com.m2049r.xmrwallet.service.exchange.api.ExchangeRate; +import com.m2049r.xmrwallet.util.NetCipherHelper; import net.jodah.concurrentunit.Waiter; @@ -46,7 +47,6 @@ public class ExchangeRateTest { private ExchangeApi exchangeApi; - private final OkHttpClient okHttpClient = new OkHttpClient(); private Waiter waiter; @Mock @@ -60,8 +60,8 @@ public class ExchangeRateTest { waiter = new Waiter(); MockitoAnnotations.initMocks(this); - - exchangeApi = new ExchangeApiImpl(okHttpClient, mockWebServer.url("/")); + NetCipherHelper.Request.mockClient = new OkHttpClient(); + exchangeApi = new ExchangeApiImpl( mockWebServer.url("/")); } @After diff --git a/app/src/test/java/com/m2049r/xmrwallet/service/exchange/kraken/ExchangeRateTest.java b/app/src/test/java/com/m2049r/xmrwallet/service/exchange/kraken/ExchangeRateTest.java index 2e5d089a..edb8be73 100644 --- a/app/src/test/java/com/m2049r/xmrwallet/service/exchange/kraken/ExchangeRateTest.java +++ b/app/src/test/java/com/m2049r/xmrwallet/service/exchange/kraken/ExchangeRateTest.java @@ -20,6 +20,7 @@ import com.m2049r.xmrwallet.service.exchange.api.ExchangeApi; import com.m2049r.xmrwallet.service.exchange.api.ExchangeCallback; import com.m2049r.xmrwallet.service.exchange.api.ExchangeException; import com.m2049r.xmrwallet.service.exchange.api.ExchangeRate; +import com.m2049r.xmrwallet.util.NetCipherHelper; import net.jodah.concurrentunit.Waiter; @@ -46,7 +47,6 @@ public class ExchangeRateTest { private ExchangeApi exchangeApi; - private final OkHttpClient okHttpClient = new OkHttpClient(); private Waiter waiter; @Mock @@ -60,8 +60,8 @@ public class ExchangeRateTest { waiter = new Waiter(); MockitoAnnotations.initMocks(this); - - exchangeApi = new ExchangeApiImpl(okHttpClient, mockWebServer.url("/")); + NetCipherHelper.Request.mockClient = new OkHttpClient(); + exchangeApi = new ExchangeApiImpl(mockWebServer.url("/")); } @After diff --git a/app/src/test/java/com/m2049r/xmrwallet/service/shift/sideshift/SideShiftApiCreateOrderTest.java b/app/src/test/java/com/m2049r/xmrwallet/service/shift/sideshift/SideShiftApiCreateOrderTest.java index 56150c3b..78926948 100644 --- a/app/src/test/java/com/m2049r/xmrwallet/service/shift/sideshift/SideShiftApiCreateOrderTest.java +++ b/app/src/test/java/com/m2049r/xmrwallet/service/shift/sideshift/SideShiftApiCreateOrderTest.java @@ -16,11 +16,14 @@ package com.m2049r.xmrwallet.service.shift.sideshift; +import static org.junit.Assert.assertEquals; + import com.m2049r.xmrwallet.service.shift.ShiftCallback; import com.m2049r.xmrwallet.service.shift.ShiftException; import com.m2049r.xmrwallet.service.shift.sideshift.api.CreateOrder; import com.m2049r.xmrwallet.service.shift.sideshift.api.SideShiftApi; import com.m2049r.xmrwallet.service.shift.sideshift.network.SideShiftApiImpl; +import com.m2049r.xmrwallet.util.NetCipherHelper; import com.m2049r.xmrwallet.util.ServiceHelper; import net.jodah.concurrentunit.Waiter; @@ -38,15 +41,12 @@ import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; -import static org.junit.Assert.assertEquals; - public class SideShiftApiCreateOrderTest { private MockWebServer mockWebServer; private SideShiftApi xmrToApi; - private final OkHttpClient okHttpClient = new OkHttpClient(); private Waiter waiter; @Mock @@ -60,9 +60,9 @@ public class SideShiftApiCreateOrderTest { waiter = new Waiter(); MockitoAnnotations.initMocks(this); - - xmrToApi = new SideShiftApiImpl(okHttpClient, mockWebServer.url("/")); - ServiceHelper.ASSET="btc"; // all tests run with BTC + NetCipherHelper.Request.mockClient = new OkHttpClient(); + xmrToApi = new SideShiftApiImpl(mockWebServer.url("/")); + ServiceHelper.ASSET = "btc"; // all tests run with BTC } @After diff --git a/app/src/test/java/com/m2049r/xmrwallet/service/shift/sideshift/SideShiftApiOrderParameterTest.java b/app/src/test/java/com/m2049r/xmrwallet/service/shift/sideshift/SideShiftApiOrderParameterTest.java index b085481a..bfd1533b 100644 --- a/app/src/test/java/com/m2049r/xmrwallet/service/shift/sideshift/SideShiftApiOrderParameterTest.java +++ b/app/src/test/java/com/m2049r/xmrwallet/service/shift/sideshift/SideShiftApiOrderParameterTest.java @@ -21,6 +21,7 @@ import com.m2049r.xmrwallet.service.shift.sideshift.api.QueryOrderParameters; import com.m2049r.xmrwallet.service.shift.sideshift.api.SideShiftApi; import com.m2049r.xmrwallet.service.shift.ShiftCallback; import com.m2049r.xmrwallet.service.shift.sideshift.network.SideShiftApiImpl; +import com.m2049r.xmrwallet.util.NetCipherHelper; import net.jodah.concurrentunit.Waiter; @@ -45,7 +46,6 @@ public class SideShiftApiOrderParameterTest { private SideShiftApi xmrToApi; - private final OkHttpClient okHttpClient = new OkHttpClient(); private Waiter waiter; @Mock @@ -59,8 +59,8 @@ public class SideShiftApiOrderParameterTest { waiter = new Waiter(); MockitoAnnotations.initMocks(this); - - xmrToApi = new SideShiftApiImpl(okHttpClient, mockWebServer.url("/")); + NetCipherHelper.Request.mockClient = new OkHttpClient(); + xmrToApi = new SideShiftApiImpl(mockWebServer.url("/")); } @After diff --git a/app/src/test/java/com/m2049r/xmrwallet/service/shift/sideshift/SideShiftApiQueryOrderStatusTest.java b/app/src/test/java/com/m2049r/xmrwallet/service/shift/sideshift/SideShiftApiQueryOrderStatusTest.java index f4bd21f1..4f913a88 100644 --- a/app/src/test/java/com/m2049r/xmrwallet/service/shift/sideshift/SideShiftApiQueryOrderStatusTest.java +++ b/app/src/test/java/com/m2049r/xmrwallet/service/shift/sideshift/SideShiftApiQueryOrderStatusTest.java @@ -16,11 +16,14 @@ package com.m2049r.xmrwallet.service.shift.sideshift; +import static org.junit.Assert.assertEquals; + +import com.m2049r.xmrwallet.service.shift.ShiftCallback; import com.m2049r.xmrwallet.service.shift.ShiftException; import com.m2049r.xmrwallet.service.shift.sideshift.api.QueryOrderStatus; import com.m2049r.xmrwallet.service.shift.sideshift.api.SideShiftApi; -import com.m2049r.xmrwallet.service.shift.ShiftCallback; import com.m2049r.xmrwallet.service.shift.sideshift.network.SideShiftApiImpl; +import com.m2049r.xmrwallet.util.NetCipherHelper; import net.jodah.concurrentunit.Waiter; @@ -37,14 +40,11 @@ import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; -import static org.junit.Assert.assertEquals; - public class SideShiftApiQueryOrderStatusTest { private MockWebServer mockWebServer; private SideShiftApi xmrToApi; - private final OkHttpClient okHttpClient = new OkHttpClient(); private Waiter waiter; @Mock @@ -58,8 +58,8 @@ public class SideShiftApiQueryOrderStatusTest { waiter = new Waiter(); MockitoAnnotations.initMocks(this); - - xmrToApi = new SideShiftApiImpl(okHttpClient, mockWebServer.url("/")); + NetCipherHelper.Request.mockClient = new OkHttpClient(); + xmrToApi = new SideShiftApiImpl(mockWebServer.url("/")); } @After diff --git a/app/src/test/java/com/m2049r/xmrwallet/service/shift/sideshift/SideShiftApiRequestQuoteTest.java b/app/src/test/java/com/m2049r/xmrwallet/service/shift/sideshift/SideShiftApiRequestQuoteTest.java index d5a112ee..ffcde3f0 100644 --- a/app/src/test/java/com/m2049r/xmrwallet/service/shift/sideshift/SideShiftApiRequestQuoteTest.java +++ b/app/src/test/java/com/m2049r/xmrwallet/service/shift/sideshift/SideShiftApiRequestQuoteTest.java @@ -22,6 +22,7 @@ import com.m2049r.xmrwallet.service.shift.ShiftException; import com.m2049r.xmrwallet.service.shift.sideshift.api.RequestQuote; import com.m2049r.xmrwallet.service.shift.sideshift.api.SideShiftApi; import com.m2049r.xmrwallet.service.shift.sideshift.network.SideShiftApiImpl; +import com.m2049r.xmrwallet.util.NetCipherHelper; import com.m2049r.xmrwallet.util.ServiceHelper; import net.jodah.concurrentunit.Waiter; @@ -47,7 +48,6 @@ public class SideShiftApiRequestQuoteTest { private SideShiftApi xmrToApi; - private final OkHttpClient okHttpClient = new OkHttpClient(); private Waiter waiter; @Mock @@ -61,8 +61,8 @@ public class SideShiftApiRequestQuoteTest { waiter = new Waiter(); MockitoAnnotations.initMocks(this); - - xmrToApi = new SideShiftApiImpl(okHttpClient, mockWebServer.url("/")); + NetCipherHelper.Request.mockClient = new OkHttpClient(); + xmrToApi = new SideShiftApiImpl(mockWebServer.url("/")); ServiceHelper.ASSET="btc"; // all tests run with BTC }