Commit 9436738e authored by Ricki Hirner's avatar Ricki Hirner

Switch to JUnit4

parent 7e8cbcfd
Pipeline #4554690 passed with stage
in 4 minutes and 50 seconds
......@@ -40,8 +40,13 @@ android {
disable 'AllowBackup'
disable 'InvalidPackage'
}
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
dependencies {
compile 'org.apache.commons:commons-lang3:3.4'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
......@@ -49,6 +54,9 @@ dependencies {
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.4.1'
testCompile 'junit:junit:4.12'
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:0.5'
testCompile 'junit:junit:4.12'
testCompile 'com.squareup.okhttp3:mockwebserver:3.4.1'
}
package at.bitfire.dav4android;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
import java.net.HttpURLConnection;
......@@ -23,8 +16,22 @@ import at.bitfire.dav4android.property.GetCTag;
import at.bitfire.dav4android.property.GetContentType;
import at.bitfire.dav4android.property.GetETag;
import at.bitfire.dav4android.property.ResourceType;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class DavResourceTest extends TestCase {
public class DavResourceTest {
private static final String
sampleText = "SAMPLE RESPONSE";
......@@ -35,13 +42,13 @@ public class DavResourceTest extends TestCase {
private MockWebServer mockServer = new MockWebServer();
@Override
public void setUp() throws IOException {
@Before
public void startServer() throws IOException {
mockServer.start();
}
@Override
public void tearDown() throws IOException {
@After
public void stopServer() throws IOException {
mockServer.shutdown();
}
......@@ -50,6 +57,7 @@ public class DavResourceTest extends TestCase {
}
@Test
public void testOptions() throws InterruptedException, IOException, HttpException, DavException {
HttpUrl url = sampleUrl();
DavResource dav = new DavResource(httpClient, url);
......@@ -69,6 +77,7 @@ public class DavResourceTest extends TestCase {
assertTrue(dav.capabilities.isEmpty());
}
@Test
public void testGet() throws InterruptedException, IOException, HttpException, DavException {
HttpUrl url = sampleUrl();
DavResource dav = new DavResource(httpClient, url);
......@@ -118,6 +127,7 @@ public class DavResourceTest extends TestCase {
assertNull(dav.properties.get(GetETag.NAME));
}
@Test
public void testPut() throws InterruptedException, IOException, HttpException, DavException {
HttpUrl url = sampleUrl();
DavResource dav = new DavResource(httpClient, url);
......@@ -165,6 +175,7 @@ public class DavResourceTest extends TestCase {
assertNull(rq.getHeader("If-None-Match"));
}
@Test
public void testDelete() throws InterruptedException, IOException, HttpException {
HttpUrl url = sampleUrl();
DavResource dav = new DavResource(httpClient, url);
......@@ -203,6 +214,7 @@ public class DavResourceTest extends TestCase {
}
}
@Test
public void testPropfindAndMultiStatus() throws IOException, HttpException, DavException {
HttpUrl url = sampleUrl();
DavResource dav = new DavResource(httpClient, url);
......@@ -487,6 +499,7 @@ public class DavResourceTest extends TestCase {
assertEquals("Without Status", ((DisplayName) dav.properties.get(DisplayName.NAME)).displayName);
}
@Test
public void testPropfindUpdateProperties() throws IOException, HttpException, DavException {
HttpUrl url = sampleUrl();
DavResource dav = new DavResource(httpClient, url);
......
......@@ -8,7 +8,7 @@
package at.bitfire.dav4android;
import android.text.TextUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.util.LinkedList;
......@@ -191,7 +191,7 @@ public class BasicDigestAuthHandler implements Authenticator, Interceptor {
if (response != null) {
params.add("response=" + quotedString(response));
return request.newBuilder()
.header(HEADER_AUTHORIZATION, "Digest " + TextUtils.join(", ", params))
.header(HEADER_AUTHORIZATION, "Digest " + StringUtils.join(params, ", "))
.build();
} else
return null;
......
/*
* Copyright © 2013 – 2015 Ricki Hirner (bitfire web engineering).
* Copyright © Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
......@@ -8,14 +8,20 @@
package at.bitfire.dav4android;
import org.junit.Test;
import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.RequestBody;
import junit.framework.TestCase;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class BasicDigestAuthHandlerTest extends TestCase {
public class BasicDigestAuthHandlerTest {
@Test
public void testRFCExample() {
// use cnonce from example
BasicDigestAuthHandler authenticator = new BasicDigestAuthHandler(null, "Mufasa", "Circle Of Life");
......@@ -46,6 +52,7 @@ public class BasicDigestAuthHandlerTest extends TestCase {
assertTrue(auth.contains("opaque=\"5ccc069c403ebaf9f0171e9517f40e41\""));
}
@Test
public void testRealWorldExamples() {
BasicDigestAuthHandler authenticator = new BasicDigestAuthHandler(null, "demo", "demo");
authenticator.clientNonce = "MDI0ZDgxYTNmZDk4MTA1ODM0NDNjNmJjNDllYjQ1ZTI=";
......@@ -99,6 +106,7 @@ public class BasicDigestAuthHandlerTest extends TestCase {
assertTrue(auth.contains("opaque=\"571609eb7058505d35c7bf7288fbbec4-ODdjNGMyYWNlZWQ5YWJmMzBkZDY4YzcxLDAuMC4wLjAsMTQ0NTM3NzE0Nw==\""));
}
@Test
public void testMD5Sess() {
BasicDigestAuthHandler authenticator = new BasicDigestAuthHandler(null, "admin", "12345");
authenticator.clientNonce = "hxk1lu63b6c7vhk";
......@@ -136,6 +144,7 @@ public class BasicDigestAuthHandlerTest extends TestCase {
assertTrue(auth.contains("opaque=\"5ccc069c403ebaf9f0171e9517f40e41\""));
}
@Test
public void testMD5AuthInt() {
BasicDigestAuthHandler authenticator = new BasicDigestAuthHandler(null, "admin", "12435");
authenticator.clientNonce = "hxk1lu63b6c7vhk";
......@@ -173,6 +182,7 @@ public class BasicDigestAuthHandlerTest extends TestCase {
assertTrue(auth.contains("opaque=\"87aaxcval4gba36\""));
}
@Test
public void testLegacyDigest() {
BasicDigestAuthHandler authenticator = new BasicDigestAuthHandler(null, "Mufasa", "CircleOfLife");
......@@ -199,6 +209,7 @@ public class BasicDigestAuthHandlerTest extends TestCase {
assertTrue(auth.contains("opaque=\"5ccc069c403ebaf9f0171e9517f40e41\""));
}
@Test
public void testIncompleteAuthenticationRequests() {
BasicDigestAuthHandler authenticator = new BasicDigestAuthHandler(null, "demo", "demo");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment