Add TwilioVerifySender

This commit is contained in:
Chris Eager
2021-03-15 21:14:10 -05:00
committed by Chris Eager
parent 7057476048
commit 17ba630014
6 changed files with 546 additions and 2 deletions

View File

@@ -0,0 +1,45 @@
package org.whispersystems.textsecuregcm.tests.util;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Collections;
import java.util.List;
import java.util.Locale.LanguageRange;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.whispersystems.textsecuregcm.util.Util;
class LocaleTest {
private static final Set<String> SUPPORTED_LOCALES = Set.of("es", "en", "zh", "zh-HK");
@ParameterizedTest
@MethodSource
void testFindBestLocale(@Nullable final String languageRange, @Nullable final String expectedLocale) {
final List<LanguageRange> languageRanges = Optional.ofNullable(languageRange)
.map(LanguageRange::parse)
.orElse(Collections.emptyList());
assertEquals(Optional.ofNullable(expectedLocale), Util.findBestLocale(languageRanges, SUPPORTED_LOCALES));
}
static Stream<Arguments> testFindBestLocale() {
return Stream.of(
// languageRange, expectedLocale
Arguments.of("en-US, fr", "en"),
Arguments.of("es-ES", "es"),
Arguments.of("zh-Hant-HK, zh-HK", "zh"),
// zh-HK is supported, but Locale#lookup truncates from the end, per RFC-4647
Arguments.of("zh-Hant-HK", "zh"),
Arguments.of("zh-HK", "zh-HK"),
Arguments.of("de", null),
Arguments.of(null, null)
);
}
}