2014-04-24 23:40:54 +00:00
|
|
|
package org.thoughtcrime.securesms.util;
|
|
|
|
|
|
|
|
import android.test.AndroidTestCase;
|
|
|
|
|
|
|
|
import junit.framework.AssertionFailedError;
|
|
|
|
|
2015-01-12 21:34:36 +00:00
|
|
|
import org.thoughtcrime.securesms.TextSecureTestCase;
|
2014-11-12 19:15:05 +00:00
|
|
|
import org.whispersystems.textsecure.api.util.InvalidNumberException;
|
|
|
|
import org.whispersystems.textsecure.api.util.PhoneNumberFormatter;
|
2014-12-31 00:49:57 +00:00
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
2014-04-24 23:40:54 +00:00
|
|
|
|
2015-01-12 21:34:36 +00:00
|
|
|
public class PhoneNumberFormatterTest extends TextSecureTestCase {
|
2014-04-24 23:40:54 +00:00
|
|
|
private static final String LOCAL_NUMBER = "+15555555555";
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testFormatNumberEmail() throws Exception {
|
|
|
|
try {
|
|
|
|
PhoneNumberFormatter.formatNumber("person@domain.com", LOCAL_NUMBER);
|
|
|
|
throw new AssertionFailedError("should have thrown on email");
|
|
|
|
} catch (InvalidNumberException ine) {
|
|
|
|
// success
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setUp() throws Exception {
|
|
|
|
super.setUp();
|
|
|
|
}
|
|
|
|
}
|