1
0
mirror of https://github.com/etesync/android synced 2025-05-11 19:38:54 +00:00

Switch to JUnit4

This commit is contained in:
Ricki Hirner 2016-10-10 20:42:29 +02:00
parent ec0e792f12
commit bd8470e7eb
6 changed files with 64 additions and 18 deletions

View File

@ -1,6 +1,7 @@
image: registry.gitlab.com/bitfireat/davdroid:latest image: registry.gitlab.com/bitfireat/davdroid:latest
before_script: before_script:
- git submodule update --init --recursive
- export GRADLE_USER_HOME=`pwd`/.gradle - export GRADLE_USER_HOME=`pwd`/.gradle
- chmod +x gradlew - chmod +x gradlew
- emulator64-arm -avd test -no-skin -no-audio -no-window & wait-for-emulator.sh - emulator64-arm -avd test -no-skin -no-audio -no-window & wait-for-emulator.sh

View File

@ -59,6 +59,10 @@ android {
exclude 'META-INF/LICENSE.txt' exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt' exclude 'META-INF/NOTICE.txt'
} }
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
} }
dependencies { dependencies {
@ -81,7 +85,15 @@ dependencies {
provided 'org.projectlombok:lombok:1.16.10' provided 'org.projectlombok:lombok:1.16.10'
// for tests // for tests
androidTestCompile('com.android.support.test:runner:0.5') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test:rules:0.5') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.4.1'
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
testCompile 'com.squareup.okhttp3:mockwebserver:3.4.1' testCompile 'com.squareup.okhttp3:mockwebserver:3.4.1'
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.4.1'
} }

View File

@ -9,7 +9,12 @@
package at.bitfire.davdroid; package at.bitfire.davdroid;
import android.os.Build; import android.os.Build;
import android.test.InstrumentationTestCase; import android.support.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.IOException; import java.io.IOException;
import java.net.Socket; import java.net.Socket;
@ -19,23 +24,28 @@ import javax.net.ssl.SSLSocket;
import at.bitfire.cert4android.CustomCertManager; import at.bitfire.cert4android.CustomCertManager;
import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.MockWebServer;
public class SSLSocketFactoryCompatTest extends InstrumentationTestCase { import static android.support.test.InstrumentationRegistry.getTargetContext;
import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertTrue;
public class SSLSocketFactoryCompatTest {
SSLSocketFactoryCompat factory; SSLSocketFactoryCompat factory;
MockWebServer server = new MockWebServer(); MockWebServer server = new MockWebServer();
@Override @Before
protected void setUp() throws Exception { public void startServer() throws Exception {
factory = new SSLSocketFactoryCompat(new CustomCertManager(getInstrumentation().getTargetContext().getApplicationContext(), true)); factory = new SSLSocketFactoryCompat(new CustomCertManager(getTargetContext().getApplicationContext(), true));
server.start(); server.start();
} }
@Override @After
protected void tearDown() throws Exception { public void stopServer() throws Exception {
server.shutdown(); server.shutdown();
} }
@Test
public void testUpgradeTLS() throws IOException { public void testUpgradeTLS() throws IOException {
Socket s = factory.createSocket(server.getHostName(), server.getPort()); Socket s = factory.createSocket(server.getHostName(), server.getPort());
assertTrue(s instanceof SSLSocket); assertTrue(s instanceof SSLSocket);

View File

@ -9,8 +9,10 @@
package at.bitfire.davdroid.model; package at.bitfire.davdroid.model;
import android.content.ContentValues; import android.content.ContentValues;
import android.support.test.runner.AndroidJUnit4;
import junit.framework.TestCase; import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.IOException; import java.io.IOException;
@ -23,10 +25,16 @@ import at.bitfire.davdroid.model.ServiceDB.Collections;
import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.MockWebServer;
public class CollectionInfoTest extends TestCase { import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class CollectionInfoTest {
MockWebServer server = new MockWebServer(); MockWebServer server = new MockWebServer();
@Test
public void testFromDavResource() throws IOException, HttpException, DavException { public void testFromDavResource() throws IOException, HttpException, DavException {
// r/w address book // r/w address book
server.enqueue(new MockResponse() server.enqueue(new MockResponse()
@ -79,6 +87,7 @@ public class CollectionInfoTest extends TestCase {
assertTrue(info.supportsVTODO); assertTrue(info.supportsVTODO);
} }
@Test
public void testFromDB() { public void testFromDB() {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(Collections.ID, 1); values.put(Collections.ID, 1);

View File

@ -8,8 +8,14 @@
package at.bitfire.davdroid.ui.setup; package at.bitfire.davdroid.ui.setup;
import android.support.test.runner.AndroidJUnit4;
import android.test.InstrumentationTestCase; import android.test.InstrumentationTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
@ -29,7 +35,13 @@ import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest; import okhttp3.mockwebserver.RecordedRequest;
public class DavResourceFinderTest extends InstrumentationTestCase { import static android.support.test.InstrumentationRegistry.getTargetContext;
import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class DavResourceFinderTest {
MockWebServer server = new MockWebServer(); MockWebServer server = new MockWebServer();
@ -48,24 +60,24 @@ public class DavResourceFinderTest extends InstrumentationTestCase {
SUBPATH_ADDRESSBOOK_HOMESET = "/addressbooks", SUBPATH_ADDRESSBOOK_HOMESET = "/addressbooks",
SUBPATH_ADDRESSBOOK = "/addressbooks/private-contacts"; SUBPATH_ADDRESSBOOK = "/addressbooks/private-contacts";
@Override @Before
protected void setUp() throws Exception { public void initServerAndClient() throws Exception {
server.setDispatcher(new TestDispatcher()); server.setDispatcher(new TestDispatcher());
server.start(); server.start();
credentials = new LoginCredentials(URI.create("/"), "mock", "12345"); credentials = new LoginCredentials(URI.create("/"), "mock", "12345");
finder = new DavResourceFinder(getInstrumentation().getTargetContext(), credentials); finder = new DavResourceFinder(getTargetContext(), credentials);
client = HttpClient.create(null); client = HttpClient.create(null);
client = HttpClient.addAuthentication(client, credentials.userName, credentials.password); client = HttpClient.addAuthentication(client, credentials.userName, credentials.password);
} }
@Override @After
protected void tearDown() throws Exception { public void stopServer() throws Exception {
server.shutdown(); server.shutdown();
} }
@Test
public void testRememberIfAddressBookOrHomeset() throws IOException, HttpException, DavException { public void testRememberIfAddressBookOrHomeset() throws IOException, HttpException, DavException {
ServiceInfo info; ServiceInfo info;
@ -91,6 +103,7 @@ public class DavResourceFinderTest extends InstrumentationTestCase {
assertEquals(0, info.homeSets.size()); assertEquals(0, info.homeSets.size());
} }
@Test
public void testProvidesService() throws IOException { public void testProvidesService() throws IOException {
assertFalse(finder.providesService(server.url(PATH_NO_DAV), DavResourceFinder.Service.CALDAV)); assertFalse(finder.providesService(server.url(PATH_NO_DAV), DavResourceFinder.Service.CALDAV));
assertFalse(finder.providesService(server.url(PATH_NO_DAV), DavResourceFinder.Service.CARDDAV)); assertFalse(finder.providesService(server.url(PATH_NO_DAV), DavResourceFinder.Service.CARDDAV));
@ -105,6 +118,7 @@ public class DavResourceFinderTest extends InstrumentationTestCase {
assertTrue(finder.providesService(server.url(PATH_CALDAV_AND_CARDDAV), DavResourceFinder.Service.CARDDAV)); assertTrue(finder.providesService(server.url(PATH_CALDAV_AND_CARDDAV), DavResourceFinder.Service.CARDDAV));
} }
@Test
public void testGetCurrentUserPrincipal() throws IOException, HttpException, DavException { public void testGetCurrentUserPrincipal() throws IOException, HttpException, DavException {
assertNull(finder.getCurrentUserPrincipal(server.url(PATH_NO_DAV), DavResourceFinder.Service.CALDAV)); assertNull(finder.getCurrentUserPrincipal(server.url(PATH_NO_DAV), DavResourceFinder.Service.CALDAV));
assertNull(finder.getCurrentUserPrincipal(server.url(PATH_NO_DAV), DavResourceFinder.Service.CARDDAV)); assertNull(finder.getCurrentUserPrincipal(server.url(PATH_NO_DAV), DavResourceFinder.Service.CARDDAV));

@ -1 +1 @@
Subproject commit 9c6d977a54a53903f7240a4028170193276a1e44 Subproject commit 70ed4888b71b7c39efc3411114a6ebb6a05164d9