mirror of
https://github.com/etesync/android
synced 2024-11-29 11:28:19 +00:00
Introduce local unit tests
* split tests into Android tests and local unit tests * LoginCredentialsFragment: check for empty host before doing IDN conversion
This commit is contained in:
parent
7997606550
commit
28e567cf78
@ -78,5 +78,6 @@ dependencies {
|
|||||||
compile 'org.apache.commons:commons-collections4:4.1'
|
compile 'org.apache.commons:commons-collections4:4.1'
|
||||||
|
|
||||||
// for tests
|
// for tests
|
||||||
|
testCompile 'junit:junit:4.12'
|
||||||
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.2.0'
|
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.2.0'
|
||||||
}
|
}
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright © 2013 – 2015 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
|
|
||||||
* http://www.gnu.org/licenses/gpl.html
|
|
||||||
*/
|
|
||||||
package at.bitfire.davdroid;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
|
|
||||||
public class ArrayUtilsTest extends TestCase {
|
|
||||||
|
|
||||||
public void testPartition() {
|
|
||||||
// n == 0
|
|
||||||
assertTrue(Arrays.deepEquals(
|
|
||||||
new Long[0][0],
|
|
||||||
ArrayUtils.partition(new Long[] { }, 5)));
|
|
||||||
|
|
||||||
// n < max
|
|
||||||
assertTrue(Arrays.deepEquals(
|
|
||||||
new Long[][] { { 1l, 2l } },
|
|
||||||
ArrayUtils.partition(new Long[] { 1l, 2l }, 5)));
|
|
||||||
|
|
||||||
// n == max
|
|
||||||
assertTrue(Arrays.deepEquals(
|
|
||||||
new Long[][] { { 1l, 2l }, { 3l, 4l } },
|
|
||||||
ArrayUtils.partition(new Long[] { 1l, 2l, 3l, 4l }, 2)));
|
|
||||||
|
|
||||||
// n > max
|
|
||||||
assertTrue(Arrays.deepEquals(
|
|
||||||
new Long[][] { { 1l, 2l, 3l, 4l, 5l }, { 6l, 7l, 8l, 9l, 10l }, { 11l } },
|
|
||||||
ArrayUtils.partition(new Long[] { 1l, 2l, 3l, 4l, 5l, 6l, 7l, 8l, 9l, 10l, 11l }, 5)));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,3 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2013 – 2016 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
|
||||||
|
* http://www.gnu.org/licenses/gpl.html
|
||||||
|
*/
|
||||||
|
|
||||||
package at.bitfire.davdroid.ui.setup;
|
package at.bitfire.davdroid.ui.setup;
|
||||||
|
|
||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
@ -12,7 +20,9 @@ import at.bitfire.dav4android.property.AddressbookHomeSet;
|
|||||||
import at.bitfire.dav4android.property.ResourceType;
|
import at.bitfire.dav4android.property.ResourceType;
|
||||||
import at.bitfire.davdroid.App;
|
import at.bitfire.davdroid.App;
|
||||||
import at.bitfire.davdroid.HttpClient;
|
import at.bitfire.davdroid.HttpClient;
|
||||||
|
import at.bitfire.davdroid.ui.setup.DavResourceFinder;
|
||||||
import at.bitfire.davdroid.ui.setup.DavResourceFinder.Configuration.ServiceInfo;
|
import at.bitfire.davdroid.ui.setup.DavResourceFinder.Configuration.ServiceInfo;
|
||||||
|
import at.bitfire.davdroid.ui.setup.LoginCredentials;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.mockwebserver.Dispatcher;
|
import okhttp3.mockwebserver.Dispatcher;
|
||||||
import okhttp3.mockwebserver.MockResponse;
|
import okhttp3.mockwebserver.MockResponse;
|
||||||
|
@ -9,17 +9,13 @@
|
|||||||
package at.bitfire.davdroid;
|
package at.bitfire.davdroid;
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import org.w3c.dom.Text;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import ezvcard.util.StringUtils;
|
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
|
|
||||||
public class DavUtils {
|
public class DavUtils {
|
||||||
@ -36,7 +32,7 @@ public class DavUtils {
|
|||||||
Collections.reverse(segments);
|
Collections.reverse(segments);
|
||||||
|
|
||||||
for (String segment : segments)
|
for (String segment : segments)
|
||||||
if (!TextUtils.isEmpty(segment))
|
if (!StringUtils.isEmpty(segment))
|
||||||
return segment;
|
return segment;
|
||||||
|
|
||||||
return "/";
|
return "/";
|
||||||
|
@ -118,11 +118,12 @@ public class LoginCredentialsFragment extends Fragment implements CompoundButton
|
|||||||
Uri baseUrl = Uri.parse(editBaseURL.getText().toString());
|
Uri baseUrl = Uri.parse(editBaseURL.getText().toString());
|
||||||
String scheme = baseUrl.getScheme();
|
String scheme = baseUrl.getScheme();
|
||||||
if ("https".equalsIgnoreCase(scheme) || "http".equalsIgnoreCase(scheme)) {
|
if ("https".equalsIgnoreCase(scheme) || "http".equalsIgnoreCase(scheme)) {
|
||||||
String host = IDN.toASCII(baseUrl.getHost());
|
String host = baseUrl.getHost();
|
||||||
if (host.isEmpty()) {
|
if (host.isEmpty()) {
|
||||||
editBaseURL.setError(getString(R.string.login_url_host_name_required));
|
editBaseURL.setError(getString(R.string.login_url_host_name_required));
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
} else
|
||||||
|
host = IDN.toASCII(host);
|
||||||
|
|
||||||
String path = baseUrl.getEncodedPath();
|
String path = baseUrl.getEncodedPath();
|
||||||
int port = baseUrl.getPort();
|
int port = baseUrl.getPort();
|
||||||
|
41
app/src/test/java/at/bitfire/davdroid/ArrayUtilsTest.java
Normal file
41
app/src/test/java/at/bitfire/davdroid/ArrayUtilsTest.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2013 – 2015 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
|
||||||
|
* http://www.gnu.org/licenses/gpl.html
|
||||||
|
*/
|
||||||
|
package at.bitfire.davdroid;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
|
||||||
|
public class ArrayUtilsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPartition() {
|
||||||
|
// n == 0
|
||||||
|
Assert.assertTrue(Arrays.deepEquals(
|
||||||
|
new Long[0][0],
|
||||||
|
ArrayUtils.partition(new Long[] {}, 5)));
|
||||||
|
|
||||||
|
// n < max
|
||||||
|
Assert.assertTrue(Arrays.deepEquals(
|
||||||
|
new Long[][] { { 1l, 2l } },
|
||||||
|
ArrayUtils.partition(new Long[] { 1l, 2l }, 5)));
|
||||||
|
|
||||||
|
// n == max
|
||||||
|
Assert.assertTrue(Arrays.deepEquals(
|
||||||
|
new Long[][] { { 1l, 2l }, { 3l, 4l } },
|
||||||
|
ArrayUtils.partition(new Long[] { 1l, 2l, 3l, 4l }, 2)));
|
||||||
|
|
||||||
|
// n > max
|
||||||
|
Assert.assertTrue(Arrays.deepEquals(
|
||||||
|
new Long[][] { { 1l, 2l, 3l, 4l, 5l }, { 6l, 7l, 8l, 9l, 10l }, { 11l } },
|
||||||
|
ArrayUtils.partition(new Long[] { 1l, 2l, 3l, 4l, 5l, 6l, 7l, 8l, 9l, 10l, 11l }, 5)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -8,17 +8,19 @@
|
|||||||
|
|
||||||
package at.bitfire.davdroid;
|
package at.bitfire.davdroid;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TestDavUtils extends TestCase {
|
public class TestDavUtils {
|
||||||
|
|
||||||
private static final String exampleURL = "http://example.com/";
|
private static final String exampleURL = "http://example.com/";
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testLastSegmentOfUrl() {
|
public void testLastSegmentOfUrl() {
|
||||||
assertEquals("/", DavUtils.lastSegmentOfUrl(exampleURL));
|
Assert.assertEquals("/", DavUtils.lastSegmentOfUrl(exampleURL));
|
||||||
assertEquals("dir", DavUtils.lastSegmentOfUrl(exampleURL + "dir"));
|
Assert.assertEquals("dir", DavUtils.lastSegmentOfUrl(exampleURL + "dir"));
|
||||||
assertEquals("dir", DavUtils.lastSegmentOfUrl(exampleURL + "dir/"));
|
Assert.assertEquals("dir", DavUtils.lastSegmentOfUrl(exampleURL + "dir/"));
|
||||||
assertEquals("file.html", DavUtils.lastSegmentOfUrl(exampleURL + "dir/file.html"));
|
Assert.assertEquals("file.html", DavUtils.lastSegmentOfUrl(exampleURL + "dir/file.html"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,2 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
./gradlew -i deviceCheck mergeAndroidReports --continue
|
./gradlew -i testDebug && \
|
||||||
|
./gradlew -i deviceCheck mergeAndroidReports --continue
|
||||||
|
Loading…
Reference in New Issue
Block a user