38 {
39
40 FlutterJNI flutterJNI = new FlutterJNI();
41
42 Context context = mock(Context.class);
43 Resources resources = mock(Resources.class);
44 Configuration config = mock(Configuration.class);
45 DartExecutor dartExecutor = mock(DartExecutor.class);
46 LocaleList localeList =
47 new LocaleList(new Locale("es", "MX"), new Locale("zh", "CN"), new Locale("en", "US"));
48 when(context.getResources()).thenReturn(resources);
49 when(resources.getConfiguration()).thenReturn(config);
50 when(config.getLocales()).thenReturn(localeList);
51
52 flutterJNI.setLocalizationPlugin(
53 new LocalizationPlugin(context, new LocalizationChannel(dartExecutor)));
54
55
56 String[] supportedLocales = new String[] {};
57 String[]
result = flutterJNI.computePlatformResolvedLocale(supportedLocales);
58 assertEquals(
result.length, 0);
59
60
61 supportedLocales =
62 new String[] {
63 "fr", "FR", "",
64 "zh", "", "",
65 "en", "CA", ""
66 };
67 localeList = new LocaleList();
68 when(config.getLocales()).thenReturn(localeList);
69 result = flutterJNI.computePlatformResolvedLocale(supportedLocales);
70
71 assertEquals(
result.length, 3);
72 assertEquals(
result[0],
"fr");
73 assertEquals(
result[1],
"FR");
74 assertEquals(
result[2],
"");
75
76
77 supportedLocales =
78 new String[] {
79 "en", "", "",
80 "de", "DE", "",
81 "es", "ES", "",
82 "fr", "FR", "",
83 "it", "IT", ""
84 };
85 localeList = new LocaleList(new Locale("fr", "CH"));
86 when(config.getLocales()).thenReturn(localeList);
87 result = flutterJNI.computePlatformResolvedLocale(supportedLocales);
88
89 assertEquals(
result.length, 3);
90 assertEquals(
result[0],
"fr");
91 assertEquals(
result[1],
"FR");
92 assertEquals(
result[2],
"");
93
94 supportedLocales =
95 new String[] {
96 "en", "", "",
97 "de", "DE", "",
98 "es", "ES", "",
99 "fr", "FR", "",
100 "fr", "", "",
101 "it", "IT", ""
102 };
103 localeList = new LocaleList(new Locale("fr", "CH"));
104 when(config.getLocales()).thenReturn(localeList);
105 result = flutterJNI.computePlatformResolvedLocale(supportedLocales);
106
107 assertEquals(
result.length, 3);
108 assertEquals(
result[0],
"fr");
109 assertEquals(
result[1],
"");
110 assertEquals(
result[2],
"");
111
112
113 supportedLocales =
114 new String[] {
115 "en", "", "",
116 "de", "DE", "",
117 "es", "ES", "",
118 "it", "IT", ""
119 };
120 localeList = new LocaleList(new Locale("fr", "CH"), new Locale("it", "CH"));
121 when(config.getLocales()).thenReturn(localeList);
122 result = flutterJNI.computePlatformResolvedLocale(supportedLocales);
123
124 assertEquals(
result.length, 3);
125 assertEquals(
result[0],
"it");
126 assertEquals(
result[1],
"IT");
127 assertEquals(
result[2],
"");
128
129 supportedLocales =
130 new String[] {
131 "zh", "CN", "Hans",
132 "zh", "HK", "Hant",
133 };
134 localeList = new LocaleList(new Locale("zh", "CN"));
135 when(config.getLocales()).thenReturn(localeList);
136 result = flutterJNI.computePlatformResolvedLocale(supportedLocales);
137 assertEquals(
result.length, 3);
138 assertEquals(
result[0],
"zh");
139 assertEquals(
result[1],
"CN");
140 assertEquals(
result[2],
"Hans");
141 }