fix unit tests

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2019-08-21 07:31:10 +02:00
parent 8a30677577
commit 6473e7ed76
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
6 changed files with 23 additions and 6 deletions

View file

@ -145,7 +145,8 @@ public class UserAccountManagerImpl implements UserAccountManager {
try {
Account currentPlatformAccount = getCurrentAccount();
return new OwnCloudAccount(currentPlatformAccount, context);
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException ex) {
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException |
IllegalArgumentException ex) {
return null;
}
}

View file

@ -29,6 +29,8 @@ import android.net.Uri;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import org.apache.commons.httpclient.HttpClient;
import java.io.IOException;
public interface ClientFactory {
@ -46,4 +48,6 @@ public interface ClientFactory {
boolean useNextcloudUserAgent);
OwnCloudClient create(Uri uri, boolean followRedirects);
HttpClient createPlainClient();
}

View file

@ -31,6 +31,8 @@ import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import org.apache.commons.httpclient.HttpClient;
import java.io.IOException;
class ClientFactoryImpl implements ClientFactory {
@ -64,4 +66,9 @@ class ClientFactoryImpl implements ClientFactory {
public OwnCloudClient create(Uri uri, boolean followRedirects) {
return OwnCloudClientFactory.createOwnCloudClient(uri, context, followRedirects);
}
@Override
public HttpClient createPlainClient() {
return new HttpClient();
}
}

View file

@ -46,6 +46,7 @@ class ConnectivityServiceImpl implements ConnectivityService {
private ConnectivityManager connectivityManager;
private UserAccountManager accountManager;
private ClientFactory clientFactory;
private GetRequestBuilder requestBuilder;
static class GetRequestBuilder implements Function1<String, GetMethod> {
@ -57,9 +58,11 @@ class ConnectivityServiceImpl implements ConnectivityService {
ConnectivityServiceImpl(ConnectivityManager connectivityManager,
UserAccountManager accountManager,
ClientFactory clientFactory,
GetRequestBuilder requestBuilder) {
this.connectivityManager = connectivityManager;
this.accountManager = accountManager;
this.clientFactory = clientFactory;
this.requestBuilder = requestBuilder;
}
@ -80,7 +83,7 @@ class ConnectivityServiceImpl implements ConnectivityService {
}
GetMethod get = requestBuilder.invoke(url);
HttpClient client = new HttpClient();
HttpClient client = clientFactory.createPlainClient();
int status = client.executeMethod(get);

View file

@ -35,9 +35,11 @@ public class NetworkModule {
@Provides
ConnectivityService connectivityService(ConnectivityManager connectivityManager,
UserAccountManager accountManager) {
UserAccountManager accountManager,
ClientFactory clientFactory) {
return new ConnectivityServiceImpl(connectivityManager,
accountManager,
clientFactory,
new ConnectivityServiceImpl.GetRequestBuilder());
}

View file

@ -29,8 +29,8 @@ import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.whenever
import com.owncloud.android.lib.common.OwnCloudAccount
import com.owncloud.android.lib.common.OwnCloudClient
import com.owncloud.android.lib.resources.status.OwnCloudVersion
import org.apache.commons.httpclient.HttpClient
import org.apache.commons.httpclient.HttpStatus
import org.apache.commons.httpclient.methods.GetMethod
import org.junit.Assert.assertFalse
@ -77,7 +77,7 @@ class ConnectivityServiceTest {
lateinit var clientFactory: ClientFactory
@Mock
lateinit var client: OwnCloudClient
lateinit var client: HttpClient
@Mock
lateinit var getRequest: GetMethod
@ -107,7 +107,7 @@ class ConnectivityServiceTest {
)
whenever(platformConnectivityManager.activeNetworkInfo).thenReturn(networkInfo)
whenever(requestBuilder.invoke(any())).thenReturn(getRequest)
whenever(clientFactory.create(any())).thenReturn(client)
whenever(clientFactory.createPlainClient()).thenReturn(client)
whenever(accountManager.currentOwnCloudAccount).thenReturn(ownCloudAccount)
whenever(accountManager.currentAccount).thenReturn(platformAccount)
whenever(baseServerUri.toString()).thenReturn(SERVER_BASE_URL)