mirror of https://github.com/m2049r/xmrwallet.git
fix unit tests (#803)
This commit is contained in:
parent
22d9173cea
commit
ab8fb82c1b
|
@ -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";
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,8 +60,8 @@ public class SideShiftApiCreateOrderTest {
|
|||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue