mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-22 01:18:35 +01:00
Add a method for verifying that numbers are normalized in addition to being dialable
This commit is contained in:
committed by
Jon Chambers
parent
a3fe4b9980
commit
7762afc497
@@ -5,14 +5,20 @@
|
||||
|
||||
package org.whispersystems.textsecuregcm.tests.util;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.whispersystems.textsecuregcm.util.ImpossibleNumberException;
|
||||
import org.whispersystems.textsecuregcm.util.NonNormalizedNumberException;
|
||||
import org.whispersystems.textsecuregcm.util.Util;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class ValidNumberTest {
|
||||
|
||||
@@ -53,4 +59,51 @@ class ValidNumberTest {
|
||||
Arguments.of("+689123456", true)
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"+447700900111",
|
||||
"+14151231234",
|
||||
"+71234567890",
|
||||
"+447535742222",
|
||||
"+4915174108888",
|
||||
"+298123456",
|
||||
"+299123456",
|
||||
"+376123456",
|
||||
"+68512345",
|
||||
"+689123456"})
|
||||
void requireNormalizedNumber(final String number) {
|
||||
assertDoesNotThrow(() -> Util.requireNormalizedNumber(number));
|
||||
}
|
||||
|
||||
@Test
|
||||
void requireNormalizedNumberNull() {
|
||||
assertThrows(ImpossibleNumberException.class, () -> Util.requireNormalizedNumber(null));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"Definitely not a phone number at all",
|
||||
"+141512312341",
|
||||
"+712345678901",
|
||||
"+4475357422221",
|
||||
"+491517410888811111",
|
||||
"71234567890",
|
||||
"001447535742222",
|
||||
"+1415123123a"
|
||||
})
|
||||
void requireNormalizedNumberImpossibleNumber(final String number) {
|
||||
assertThrows(ImpossibleNumberException.class, () -> Util.requireNormalizedNumber(number));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"+4407700900111",
|
||||
"+1 415 123 1234",
|
||||
"+1 (415) 123-1234",
|
||||
"+1 415)123-1234",
|
||||
" +14151231234"})
|
||||
void requireNormalizedNumberNonNormalized(final String number) {
|
||||
assertThrows(NonNormalizedNumberException.class, () -> Util.requireNormalizedNumber(number));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user