From bd8470e7eb533149d529b40505c9b60ff6d173bd Mon Sep 17 00:00:00 2001 From: Ricki Hirner Date: Mon, 10 Oct 2016 20:42:29 +0200 Subject: [PATCH] Switch to JUnit4 --- .gitlab-ci.yml | 1 + app/build.gradle | 14 +++++++++- .../davdroid/SSLSocketFactoryCompatTest.java | 24 +++++++++++----- .../davdroid/model/CollectionInfoTest.java | 13 +++++++-- .../ui/setup/DavResourceFinderTest.java | 28 ++++++++++++++----- ical4android | 2 +- 6 files changed, 64 insertions(+), 18 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4f0323dc..d7616e3e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,7 @@ image: registry.gitlab.com/bitfireat/davdroid:latest before_script: + - git submodule update --init --recursive - export GRADLE_USER_HOME=`pwd`/.gradle - chmod +x gradlew - emulator64-arm -avd test -no-skin -no-audio -no-window & wait-for-emulator.sh diff --git a/app/build.gradle b/app/build.gradle index 4aeabda0..cac5e788 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -59,6 +59,10 @@ android { exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' } + + defaultConfig { + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } } dependencies { @@ -81,7 +85,15 @@ dependencies { provided 'org.projectlombok:lombok:1.16.10' // 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 'com.squareup.okhttp3:mockwebserver:3.4.1' - androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.4.1' } diff --git a/app/src/androidTest/java/at/bitfire/davdroid/SSLSocketFactoryCompatTest.java b/app/src/androidTest/java/at/bitfire/davdroid/SSLSocketFactoryCompatTest.java index ed49a5aa..803a3dd7 100644 --- a/app/src/androidTest/java/at/bitfire/davdroid/SSLSocketFactoryCompatTest.java +++ b/app/src/androidTest/java/at/bitfire/davdroid/SSLSocketFactoryCompatTest.java @@ -9,7 +9,12 @@ package at.bitfire.davdroid; 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.net.Socket; @@ -19,23 +24,28 @@ import javax.net.ssl.SSLSocket; import at.bitfire.cert4android.CustomCertManager; 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; MockWebServer server = new MockWebServer(); - @Override - protected void setUp() throws Exception { - factory = new SSLSocketFactoryCompat(new CustomCertManager(getInstrumentation().getTargetContext().getApplicationContext(), true)); + @Before + public void startServer() throws Exception { + factory = new SSLSocketFactoryCompat(new CustomCertManager(getTargetContext().getApplicationContext(), true)); server.start(); } - @Override - protected void tearDown() throws Exception { + @After + public void stopServer() throws Exception { server.shutdown(); } + @Test public void testUpgradeTLS() throws IOException { Socket s = factory.createSocket(server.getHostName(), server.getPort()); assertTrue(s instanceof SSLSocket); diff --git a/app/src/androidTest/java/at/bitfire/davdroid/model/CollectionInfoTest.java b/app/src/androidTest/java/at/bitfire/davdroid/model/CollectionInfoTest.java index 3938de73..7d3b7d0b 100644 --- a/app/src/androidTest/java/at/bitfire/davdroid/model/CollectionInfoTest.java +++ b/app/src/androidTest/java/at/bitfire/davdroid/model/CollectionInfoTest.java @@ -9,8 +9,10 @@ package at.bitfire.davdroid.model; 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; @@ -23,10 +25,16 @@ import at.bitfire.davdroid.model.ServiceDB.Collections; import okhttp3.mockwebserver.MockResponse; 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(); + @Test public void testFromDavResource() throws IOException, HttpException, DavException { // r/w address book server.enqueue(new MockResponse() @@ -79,6 +87,7 @@ public class CollectionInfoTest extends TestCase { assertTrue(info.supportsVTODO); } + @Test public void testFromDB() { ContentValues values = new ContentValues(); values.put(Collections.ID, 1); diff --git a/app/src/androidTest/java/at/bitfire/davdroid/ui/setup/DavResourceFinderTest.java b/app/src/androidTest/java/at/bitfire/davdroid/ui/setup/DavResourceFinderTest.java index 41cf10ee..f8190fbe 100644 --- a/app/src/androidTest/java/at/bitfire/davdroid/ui/setup/DavResourceFinderTest.java +++ b/app/src/androidTest/java/at/bitfire/davdroid/ui/setup/DavResourceFinderTest.java @@ -8,8 +8,14 @@ package at.bitfire.davdroid.ui.setup; +import android.support.test.runner.AndroidJUnit4; 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.net.URI; @@ -29,7 +35,13 @@ import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; 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(); @@ -48,24 +60,24 @@ public class DavResourceFinderTest extends InstrumentationTestCase { SUBPATH_ADDRESSBOOK_HOMESET = "/addressbooks", SUBPATH_ADDRESSBOOK = "/addressbooks/private-contacts"; - @Override - protected void setUp() throws Exception { + @Before + public void initServerAndClient() throws Exception { server.setDispatcher(new TestDispatcher()); server.start(); credentials = new LoginCredentials(URI.create("/"), "mock", "12345"); - finder = new DavResourceFinder(getInstrumentation().getTargetContext(), credentials); + finder = new DavResourceFinder(getTargetContext(), credentials); client = HttpClient.create(null); client = HttpClient.addAuthentication(client, credentials.userName, credentials.password); } - @Override - protected void tearDown() throws Exception { + @After + public void stopServer() throws Exception { server.shutdown(); } - + @Test public void testRememberIfAddressBookOrHomeset() throws IOException, HttpException, DavException { ServiceInfo info; @@ -91,6 +103,7 @@ public class DavResourceFinderTest extends InstrumentationTestCase { assertEquals(0, info.homeSets.size()); } + @Test 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.CARDDAV)); @@ -105,6 +118,7 @@ public class DavResourceFinderTest extends InstrumentationTestCase { assertTrue(finder.providesService(server.url(PATH_CALDAV_AND_CARDDAV), DavResourceFinder.Service.CARDDAV)); } + @Test 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.CARDDAV)); diff --git a/ical4android b/ical4android index 9c6d977a..70ed4888 160000 --- a/ical4android +++ b/ical4android @@ -1 +1 @@ -Subproject commit 9c6d977a54a53903f7240a4028170193276a1e44 +Subproject commit 70ed4888b71b7c39efc3411114a6ebb6a05164d9