68 {
69
70 FlutterJNI flutterJNI = new FlutterJNI();
71
72 Context context = mock(Context.class);
73 Resources resources = mock(Resources.class);
74 Configuration config = mock(Configuration.class);
75 DartExecutor dartExecutor = mock(DartExecutor.class);
76 LocaleList localeList =
77 new LocaleList(new Locale("es", "MX"), new Locale("zh", "CN"), new Locale("en", "US"));
78 when(context.getResources()).thenReturn(resources);
79 when(resources.getConfiguration()).thenReturn(config);
80 when(config.getLocales()).thenReturn(localeList);
81
82 flutterJNI.setLocalizationPlugin(
83 new LocalizationPlugin(context, new LocalizationChannel(dartExecutor)));
84 String[] supportedLocales =
85 new String[] {
86 "fr", "FR", "",
87 "zh", "", "",
88 "en", "CA", ""
89 };
90 String[]
result = flutterJNI.computePlatformResolvedLocale(supportedLocales);
91 assertEquals(
result.length, 3);
92 assertEquals(
result[0],
"zh");
93 assertEquals(
result[1],
"");
94 assertEquals(
result[2],
"");
95
96 supportedLocales =
97 new String[] {
98 "fr", "FR", "",
99 "ar", "", "",
100 "en", "CA", ""
101 };
102 result = flutterJNI.computePlatformResolvedLocale(supportedLocales);
103 assertEquals(
result.length, 3);
104 assertEquals(
result[0],
"en");
105 assertEquals(
result[1],
"CA");
106 assertEquals(
result[2],
"");
107
108 supportedLocales =
109 new String[] {
110 "fr", "FR", "",
111 "ar", "", "",
112 "en", "US", ""
113 };
114 result = flutterJNI.computePlatformResolvedLocale(supportedLocales);
115 assertEquals(
result.length, 3);
116 assertEquals(
result[0],
"en");
117 assertEquals(
result[1],
"US");
118 assertEquals(
result[2],
"");
119
120 supportedLocales =
121 new String[] {
122 "ar", "", "",
123 "es", "MX", "",
124 "en", "US", ""
125 };
126 result = flutterJNI.computePlatformResolvedLocale(supportedLocales);
127 assertEquals(
result.length, 3);
128 assertEquals(
result[0],
"es");
129 assertEquals(
result[1],
"MX");
130 assertEquals(
result[2],
"");
131
132
133 supportedLocales = new String[] {};
134 result = flutterJNI.computePlatformResolvedLocale(supportedLocales);
135 assertEquals(
result.length, 0);
136
137
138 supportedLocales =
139 new String[] {
140 "fr", "FR", "",
141 "zh", "", "",
142 "en", "CA", ""
143 };
144 localeList = new LocaleList();
145 when(config.getLocales()).thenReturn(localeList);
146 result = flutterJNI.computePlatformResolvedLocale(supportedLocales);
147
148 assertEquals(
result.length, 3);
149 assertEquals(
result[0],
"fr");
150 assertEquals(
result[1],
"FR");
151 assertEquals(
result[2],
"");
152 }