1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-08 08:26:10 +00:00

Updated unit tests

This commit is contained in:
David A. Velasco 2015-02-10 12:57:17 +01:00
parent f5fe254c09
commit 24110ba178
4 changed files with 55 additions and 24 deletions

View File

@ -54,6 +54,11 @@ public class OwnCloudAccount {
if (savedAccount == null) { if (savedAccount == null) {
throw new IllegalArgumentException("Parameter 'savedAccount' cannot be null"); throw new IllegalArgumentException("Parameter 'savedAccount' cannot be null");
} }
if (context == null) {
throw new IllegalArgumentException("Parameter 'context' cannot be null");
}
mSavedAccount = savedAccount; mSavedAccount = savedAccount;
mSavedAccountName = savedAccount.name; mSavedAccountName = savedAccount.name;
mBaseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, mSavedAccount)); mBaseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, mSavedAccount));
@ -73,8 +78,14 @@ public class OwnCloudAccount {
throws AccountNotFoundException, AuthenticatorException, throws AccountNotFoundException, AuthenticatorException,
IOException, OperationCanceledException { IOException, OperationCanceledException {
mCredentials = AccountUtils.getCredentialsForAccount(context, mSavedAccount); if (context == null) {
} throw new IllegalArgumentException("Parameter 'context' cannot be null");
}
if (mSavedAccount != null) {
mCredentials = AccountUtils.getCredentialsForAccount(context, mSavedAccount);
}
}
/* /*
public OwnCloudAccount(Account savedAccount, Context context) public OwnCloudAccount(Account savedAccount, Context context)

View File

@ -92,6 +92,7 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory {
/** /**
* @see ProtocolSocketFactory#createSocket(java.lang.String,int,java.net.InetAddress,int) * @see ProtocolSocketFactory#createSocket(java.lang.String,int,java.net.InetAddress,int)
*/ */
@Override
public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort) public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort)
throws IOException, UnknownHostException { throws IOException, UnknownHostException {
@ -157,6 +158,7 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory {
* @throws UnknownHostException if the IP address of the host cannot be * @throws UnknownHostException if the IP address of the host cannot be
* determined * determined
*/ */
@Override
public Socket createSocket(final String host, final int port, public Socket createSocket(final String host, final int port,
final InetAddress localAddress, final int localPort, final InetAddress localAddress, final int localPort,
final HttpConnectionParams params) throws IOException, final HttpConnectionParams params) throws IOException,
@ -187,6 +189,7 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory {
/** /**
* @see ProtocolSocketFactory#createSocket(java.lang.String,int) * @see ProtocolSocketFactory#createSocket(java.lang.String,int)
*/ */
@Override
public Socket createSocket(String host, int port) throws IOException, public Socket createSocket(String host, int port) throws IOException,
UnknownHostException { UnknownHostException {
Log_OC.d(TAG, "Creating SSL Socket with remote " + host + ":" + port); Log_OC.d(TAG, "Creating SSL Socket with remote " + host + ":" + port);

View File

@ -94,23 +94,31 @@ public class SimpleFactoryManagerTest extends AndroidTestCase {
} }
public void testGetClientFor() { public void testGetClientFor() {
OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext()); try {
OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext());
assertNotSame("Got same client instances for same account", assertNotSame("Got same client instances for same account",
client, mSFMgr.getClientFor(mValidAccount, getContext())); client, mSFMgr.getClientFor(mValidAccount, getContext()));
assertNotSame("Got same client instances for different accounts", assertNotSame("Got same client instances for different accounts",
client, mSFMgr.getClientFor(mAnonymousAccount, getContext())); client, mSFMgr.getClientFor(mAnonymousAccount, getContext()));
} catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
}
// TODO harder tests // TODO harder tests
} }
public void testRemoveClientFor() { public void testRemoveClientFor() {
OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext()); try {
mSFMgr.removeClientFor(mValidAccount); OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext());
assertNotSame("Got same client instance after removing it from manager", mSFMgr.removeClientFor(mValidAccount);
client, mSFMgr.getClientFor(mValidAccount, getContext())); assertNotSame("Got same client instance after removing it from manager",
client, mSFMgr.getClientFor(mValidAccount, getContext()));
} catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
}
// TODO harder tests // TODO harder tests
} }

View File

@ -93,22 +93,31 @@ public class SingleSessionManagerTest extends AndroidTestCase {
} }
public void testGetClientFor() { public void testGetClientFor() {
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext()); try {
OwnCloudClient client2 = mSSMgr.getClientFor(mAnonymousAccount, getContext()); OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext());
OwnCloudClient client2 = mSSMgr.getClientFor(mAnonymousAccount, getContext());
assertNotSame("Got same client instances for different accounts", assertNotSame("Got same client instances for different accounts",
client1, client2); client1, client2);
assertSame("Got different client instances for same account", assertSame("Got different client instances for same account",
client1, mSSMgr.getClientFor(mValidAccount, getContext())); client1, mSSMgr.getClientFor(mValidAccount, getContext()));
} catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
}
// TODO harder tests // TODO harder tests
} }
public void testRemoveClientFor() { public void testRemoveClientFor() {
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext()); try {
mSSMgr.removeClientFor(mValidAccount); OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext());
assertNotSame("Got same client instance after removing it from manager", mSSMgr.removeClientFor(mValidAccount);
client1, mSSMgr.getClientFor(mValidAccount, getContext())); assertNotSame("Got same client instance after removing it from manager",
client1, mSSMgr.getClientFor(mValidAccount, getContext()));
} catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
}
// TODO harder tests // TODO harder tests
} }