Revert "use new android unit test support"

This reverts commit 06e137aee9.
This commit is contained in:
Moxie Marlinspike
2015-08-10 09:30:59 -07:00
parent ae17b4b24a
commit 65ac2b3e18
5 changed files with 68 additions and 37 deletions

View File

@@ -1,11 +1,9 @@
package org.thoughtcrime.securesms.util;
import org.junit.Test;
import org.thoughtcrime.securesms.TextSecureTestCase;
import static org.junit.Assert.assertEquals;
public class BitmapUtilTest {
@Test public void testScaleFactorNormal() {
public class BitmapUtilTest extends TextSecureTestCase {
public void testScaleFactorNormal() {
assertEquals(1, BitmapUtil.getScaleFactor(1000, 1000, 9000, 9000, false));
assertEquals(1, BitmapUtil.getScaleFactor(1000, 1000, 750, 750, false));
@@ -20,7 +18,7 @@ public class BitmapUtilTest {
assertEquals(2, BitmapUtil.getScaleFactor(1000, 2000, 499, 499, false));
}
@Test public void testScaleFactorConstrained() {
public void testScaleFactorConstrained() {
assertEquals(1, BitmapUtil.getScaleFactor(1000, 1000, 9000, 9000, true));
assertEquals(2, BitmapUtil.getScaleFactor(1000, 1000, 750, 750, true));

View File

@@ -1,15 +1,15 @@
package org.thoughtcrime.securesms.util;
import org.junit.Test;
import org.thoughtcrime.securesms.TextSecureTestCase;
import java.util.LinkedList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static junit.framework.Assert.assertEquals;
public class ListPartitionTest {
public class ListPartitionTest extends TextSecureTestCase {
@Test public void testPartitionEven() {
public void testPartitionEven() {
List<Integer> list = new LinkedList<>();
for (int i=0;i<100;i++) {
@@ -32,7 +32,7 @@ public class ListPartitionTest {
}
}
@Test public void testPartitionOdd() {
public void testPartitionOdd() {
List<Integer> list = new LinkedList<>();
for (int i=0;i<100;i++) {
@@ -60,7 +60,7 @@ public class ListPartitionTest {
assertEquals((int)partitions.get(10).get(0), 100);
}
@Test public void testPathological() {
public void testPathological() {
List<Integer> list = new LinkedList<>();
for (int i=0;i<100;i++) {

View File

@@ -1,23 +1,25 @@
package org.thoughtcrime.securesms.util;
import android.test.AndroidTestCase;
import junit.framework.AssertionFailedError;
import org.junit.Test;
import org.thoughtcrime.securesms.TextSecureTestCase;
import org.whispersystems.textsecure.api.util.InvalidNumberException;
import org.whispersystems.textsecure.api.util.PhoneNumberFormatter;
import static org.assertj.core.api.Assertions.assertThat;
public class PhoneNumberFormatterTest {
public class PhoneNumberFormatterTest extends TextSecureTestCase {
private static final String LOCAL_NUMBER = "+15555555555";
@Test public void testFormatNumberE164() throws Exception, InvalidNumberException {
public void testFormatNumberE164() throws Exception, InvalidNumberException {
assertThat(PhoneNumberFormatter.formatNumber("(555) 555-5555", LOCAL_NUMBER)).isEqualTo(LOCAL_NUMBER);
assertThat(PhoneNumberFormatter.formatNumber("555-5555", LOCAL_NUMBER)).isEqualTo(LOCAL_NUMBER);
assertThat(PhoneNumberFormatter.formatNumber("(123) 555-5555", LOCAL_NUMBER)).isNotEqualTo(LOCAL_NUMBER);
}
@Test public void testFormatNumberEmail() throws Exception {
public void testFormatNumberEmail() throws Exception {
try {
PhoneNumberFormatter.formatNumber("person@domain.com", LOCAL_NUMBER);
throw new AssertionFailedError("should have thrown on email");
@@ -25,4 +27,9 @@ public class PhoneNumberFormatterTest {
// success
}
}
@Override
public void setUp() throws Exception {
super.setUp();
}
}

View File

@@ -19,19 +19,15 @@ package org.thoughtcrime.securesms.util;
import android.util.Log;
import junit.framework.AssertionFailedError;
import org.junit.Test;
import org.thoughtcrime.securesms.TextSecureTestCase;
import java.net.URISyntaxException;
import static org.junit.Assert.assertTrue;
public class Rfc5724UriTest {
public class Rfc5724UriTest extends TextSecureTestCase {
private static final String TAG = Rfc5724UriTest.class.getSimpleName();
@Test public void testInvalidPath() throws Exception {
public void testInvalidPath() throws Exception {
final String[] invalidSchemaUris = {
"",
":",
@@ -44,14 +40,13 @@ public class Rfc5724UriTest {
for (String uri : invalidSchemaUris) {
try {
new Rfc5724Uri(uri);
throw new AssertionFailedError("URISyntaxException should be thrown");
} catch (URISyntaxException e) {
// success
}
Log.e(TAG, "uri " + uri + " should have failed path check");
assertTrue(false);
} catch (URISyntaxException e) { }
}
}
@Test public void testGetSchema() throws Exception {
public void testGetSchema() throws Exception {
final String[][] uriTestPairs = {
{"sms:+15555555555", "sms"},
{"sMs:+15555555555", "sMs"},
@@ -62,14 +57,15 @@ public class Rfc5724UriTest {
for (String[] uriTestPair : uriTestPairs) {
final Rfc5724Uri testUri = new Rfc5724Uri(uriTestPair[0]);
Log.d(TAG, testUri.getSchema() + " ?= " + uriTestPair[1]);
assertTrue(testUri.getSchema().equals(uriTestPair[1]));
}
}
@Test public void testGetPath() throws Exception {
public void testGetPath() throws Exception {
final String[][] uriTestPairs = {
{"sms:+15555555555", "+15555555555"},
{"sms:%2B555555555", "%2B555555555"},
{"sms:%2B49555555555", "%2B555555555"},
{"smsto:+15555555555?", "+15555555555"},
{"mms:+15555555555?a=b", "+15555555555"},
{"mmsto:+15555555555?a=b&c=d", "+15555555555"},
@@ -81,11 +77,12 @@ public class Rfc5724UriTest {
for (String[] uriTestPair : uriTestPairs) {
final Rfc5724Uri testUri = new Rfc5724Uri(uriTestPair[0]);
Log.d(TAG, testUri.getPath() + " ?= " + uriTestPair[1]);
assertTrue(testUri.getPath().equals(uriTestPair[1]));
}
}
@Test public void testGetQueryParams() throws Exception {
public void testGetQueryParams() throws Exception {
final String[][] uriTestPairs = {
{"sms:+15555555555", "a", null},
{"mms:+15555555555?b=", "a", null},
@@ -106,4 +103,5 @@ public class Rfc5724UriTest {
else assertTrue(paramResult.equals(uriTestPair[2]));
}
}
}