Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
io.flutter.plugin.editing.SpellCheckPluginTest Class Reference

Public Member Functions

void respondsToSpellCheckChannelMessage ()
 
void initiateSpellCheckPerformsSpellCheckWhenNoResultPending ()
 
void initiateSpellCheckThrowsErrorWhenResultPending ()
 
void destroyClosesSpellCheckerSessionAndClearsSpellCheckMethodHandler ()
 
void performSpellCheckSendsRequestToAndroidSpellCheckService ()
 
void performSpellCheckCreatesNewSpellCheckerSession ()
 
void onGetSentenceSuggestionsResultsWithSuccessAndNoResultsProperly ()
 
void onGetSentenceSuggestionsResultsWithSuccessAndResultsProperly ()
 
void onGetSentenceSuggestionsResultsWithSuccessAndNoResultsWhenSuggestionsAreInvalid ()
 
void onGetSentenceSuggestionsResultsWithSuccessAndNoResultsWhenSuggestionsAreInvalid2 ()
 

Detailed Description

Definition at line 37 of file SpellCheckPluginTest.java.

Member Function Documentation

◆ destroyClosesSpellCheckerSessionAndClearsSpellCheckMethodHandler()

void io.flutter.plugin.editing.SpellCheckPluginTest.destroyClosesSpellCheckerSessionAndClearsSpellCheckMethodHandler ( )
inline

Definition at line 110 of file SpellCheckPluginTest.java.

110 {
111 Context fakeContext = mock(Context.class);
112 SpellCheckChannel fakeSpellCheckChannel = mock(SpellCheckChannel.class);
113 TextServicesManager fakeTextServicesManager = mock(TextServicesManager.class);
114 when(fakeContext.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE))
115 .thenReturn(fakeTextServicesManager);
116 SpellCheckPlugin spellCheckPlugin =
117 spy(new SpellCheckPlugin(fakeTextServicesManager, fakeSpellCheckChannel));
118 SpellCheckerSession fakeSpellCheckerSession = mock(SpellCheckerSession.class);
119
120 when(fakeTextServicesManager.newSpellCheckerSession(
121 null, new Locale("en", "US"), spellCheckPlugin, true))
122 .thenReturn(fakeSpellCheckerSession);
123
124 spellCheckPlugin.performSpellCheck("en-US", "Hello, wrold!");
125 spellCheckPlugin.destroy();
126
127 verify(fakeSpellCheckChannel).setSpellCheckMethodHandler(isNull());
128 verify(fakeSpellCheckerSession).close();
129 }

◆ initiateSpellCheckPerformsSpellCheckWhenNoResultPending()

void io.flutter.plugin.editing.SpellCheckPluginTest.initiateSpellCheckPerformsSpellCheckWhenNoResultPending ( )
inline

Definition at line 76 of file SpellCheckPluginTest.java.

76 {
77 SpellCheckChannel fakeSpellCheckChannel = mock(SpellCheckChannel.class);
78 TextServicesManager fakeTextServicesManager = mock(TextServicesManager.class);
79 SpellCheckPlugin spellCheckPlugin =
80 spy(new SpellCheckPlugin(fakeTextServicesManager, fakeSpellCheckChannel));
81 MethodChannel.Result mockResult = mock(MethodChannel.Result.class);
82 SpellCheckerSession fakeSpellCheckerSession = mock(SpellCheckerSession.class);
83
84 when(fakeTextServicesManager.newSpellCheckerSession(
85 null, new Locale("en", "US"), spellCheckPlugin, true))
86 .thenReturn(fakeSpellCheckerSession);
87
88 spellCheckPlugin.initiateSpellCheck("en-US", "Hello, wrold!", mockResult);
89
90 verify(spellCheckPlugin).performSpellCheck("en-US", "Hello, wrold!");
91 }

◆ initiateSpellCheckThrowsErrorWhenResultPending()

void io.flutter.plugin.editing.SpellCheckPluginTest.initiateSpellCheckThrowsErrorWhenResultPending ( )
inline

Definition at line 94 of file SpellCheckPluginTest.java.

94 {
95 SpellCheckChannel fakeSpellCheckChannel = mock(SpellCheckChannel.class);
96 TextServicesManager fakeTextServicesManager = mock(TextServicesManager.class);
97 SpellCheckPlugin spellCheckPlugin =
98 spy(new SpellCheckPlugin(fakeTextServicesManager, fakeSpellCheckChannel));
99 MethodChannel.Result mockPendingResult = mock(MethodChannel.Result.class);
100 MethodChannel.Result mockResult = mock(MethodChannel.Result.class);
101 spellCheckPlugin.pendingResult = mockPendingResult;
102
103 spellCheckPlugin.initiateSpellCheck("en-US", "Hello, wrold!", mockResult);
104
105 verify(mockResult).error("error", "Previous spell check request still pending.", null);
106 verify(spellCheckPlugin, never()).performSpellCheck("en-US", "Hello, wrold!");
107 }

◆ onGetSentenceSuggestionsResultsWithSuccessAndNoResultsProperly()

void io.flutter.plugin.editing.SpellCheckPluginTest.onGetSentenceSuggestionsResultsWithSuccessAndNoResultsProperly ( )
inline

Definition at line 181 of file SpellCheckPluginTest.java.

181 {
182 TextServicesManager fakeTextServicesManager = mock(TextServicesManager.class);
183 SpellCheckChannel fakeSpellCheckChannel = mock(SpellCheckChannel.class);
184 SpellCheckPlugin spellCheckPlugin =
185 spy(new SpellCheckPlugin(fakeTextServicesManager, fakeSpellCheckChannel));
186 MethodChannel.Result mockResult = mock(MethodChannel.Result.class);
187 spellCheckPlugin.pendingResult = mockResult;
188
189 spellCheckPlugin.onGetSentenceSuggestions(new SentenceSuggestionsInfo[] {});
190
191 verify(mockResult).success(new ArrayList<HashMap<String, Object>>());
192 }

◆ onGetSentenceSuggestionsResultsWithSuccessAndNoResultsWhenSuggestionsAreInvalid()

void io.flutter.plugin.editing.SpellCheckPluginTest.onGetSentenceSuggestionsResultsWithSuccessAndNoResultsWhenSuggestionsAreInvalid ( )
inline

Definition at line 229 of file SpellCheckPluginTest.java.

229 {
230 TextServicesManager fakeTextServicesManager = mock(TextServicesManager.class);
231 SpellCheckChannel fakeSpellCheckChannel = mock(SpellCheckChannel.class);
232 SpellCheckPlugin spellCheckPlugin =
233 spy(new SpellCheckPlugin(fakeTextServicesManager, fakeSpellCheckChannel));
234 MethodChannel.Result mockResult = mock(MethodChannel.Result.class);
235 spellCheckPlugin.pendingResult = mockResult;
236
237 spellCheckPlugin.onGetSentenceSuggestions(
238 new SentenceSuggestionsInfo[] {
239 new SentenceSuggestionsInfo(
240 (new SuggestionsInfo[] {
241 new SuggestionsInfo(
242 SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO,
243 // This is the suggestion that may be provided by the Samsung spell checker:
244 new String[] {""})
245 }),
246 new int[] {7},
247 new int[] {5})
248 });
249
250 verify(mockResult).success(new ArrayList<HashMap<String, Object>>());
251 }

◆ onGetSentenceSuggestionsResultsWithSuccessAndNoResultsWhenSuggestionsAreInvalid2()

void io.flutter.plugin.editing.SpellCheckPluginTest.onGetSentenceSuggestionsResultsWithSuccessAndNoResultsWhenSuggestionsAreInvalid2 ( )
inline

Definition at line 254 of file SpellCheckPluginTest.java.

254 {
255 TextServicesManager fakeTextServicesManager = mock(TextServicesManager.class);
256 SpellCheckChannel fakeSpellCheckChannel = mock(SpellCheckChannel.class);
257 SpellCheckPlugin spellCheckPlugin =
258 spy(new SpellCheckPlugin(fakeTextServicesManager, fakeSpellCheckChannel));
259 MethodChannel.Result mockResult = mock(MethodChannel.Result.class);
260 spellCheckPlugin.pendingResult = mockResult;
261
262 spellCheckPlugin.onGetSentenceSuggestions(
263 new SentenceSuggestionsInfo[] {
264 // This "suggestion" may be provided by the Samsung spell checker:
265 null
266 });
267
268 verify(mockResult).success(new ArrayList<HashMap<String, Object>>());
269 }

◆ onGetSentenceSuggestionsResultsWithSuccessAndResultsProperly()

void io.flutter.plugin.editing.SpellCheckPluginTest.onGetSentenceSuggestionsResultsWithSuccessAndResultsProperly ( )
inline

Definition at line 195 of file SpellCheckPluginTest.java.

195 {
196 TextServicesManager fakeTextServicesManager = mock(TextServicesManager.class);
197 SpellCheckChannel fakeSpellCheckChannel = mock(SpellCheckChannel.class);
198 SpellCheckPlugin spellCheckPlugin =
199 spy(new SpellCheckPlugin(fakeTextServicesManager, fakeSpellCheckChannel));
200 MethodChannel.Result mockResult = mock(MethodChannel.Result.class);
201 spellCheckPlugin.pendingResult = mockResult;
202
203 spellCheckPlugin.onGetSentenceSuggestions(
204 new SentenceSuggestionsInfo[] {
205 new SentenceSuggestionsInfo(
206 (new SuggestionsInfo[] {
207 new SuggestionsInfo(
208 SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO,
209 new String[] {"world", "word", "old"})
210 }),
211 new int[] {7},
212 new int[] {5})
213 });
214
215 ArrayList<HashMap<String, Object>> expectedResults = new ArrayList<HashMap<String, Object>>();
216 HashMap<String, Object> expectedResult = new HashMap<String, Object>();
217
218 expectedResult.put(SpellCheckPlugin.START_INDEX_KEY, 7);
219 expectedResult.put(SpellCheckPlugin.END_INDEX_KEY, 12);
220 expectedResult.put(
221 SpellCheckPlugin.SUGGESTIONS_KEY,
222 new ArrayList<String>(Arrays.asList("world", "word", "old")));
223 expectedResults.add(expectedResult);
224
225 verify(mockResult).success(expectedResults);
226 }

◆ performSpellCheckCreatesNewSpellCheckerSession()

void io.flutter.plugin.editing.SpellCheckPluginTest.performSpellCheckCreatesNewSpellCheckerSession ( )
inline

Definition at line 159 of file SpellCheckPluginTest.java.

159 {
160 Context fakeContext = mock(Context.class);
161 SpellCheckChannel fakeSpellCheckChannel = mock(SpellCheckChannel.class);
162 TextServicesManager fakeTextServicesManager = mock(TextServicesManager.class);
163 when(fakeContext.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE))
164 .thenReturn(fakeTextServicesManager);
165 SpellCheckPlugin spellCheckPlugin =
166 spy(new SpellCheckPlugin(fakeTextServicesManager, fakeSpellCheckChannel));
167 SpellCheckerSession fakeSpellCheckerSession = mock(SpellCheckerSession.class);
168 Locale english_US = new Locale("en", "US");
169
170 when(fakeTextServicesManager.newSpellCheckerSession(null, english_US, spellCheckPlugin, true))
171 .thenReturn(fakeSpellCheckerSession);
172
173 spellCheckPlugin.performSpellCheck("en-US", "Hello, worl!");
174 spellCheckPlugin.performSpellCheck("en-US", "Hello, world!");
175
176 verify(fakeTextServicesManager, times(1))
177 .newSpellCheckerSession(null, english_US, spellCheckPlugin, true);
178 }
static SkISize times(const SkISize &size, float factor)

◆ performSpellCheckSendsRequestToAndroidSpellCheckService()

void io.flutter.plugin.editing.SpellCheckPluginTest.performSpellCheckSendsRequestToAndroidSpellCheckService ( )
inline

Definition at line 132 of file SpellCheckPluginTest.java.

132 {
133 Context fakeContext = mock(Context.class);
134 SpellCheckChannel fakeSpellCheckChannel = mock(SpellCheckChannel.class);
135 TextServicesManager fakeTextServicesManager = mock(TextServicesManager.class);
136 when(fakeContext.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE))
137 .thenReturn(fakeTextServicesManager);
138 SpellCheckPlugin spellCheckPlugin =
139 spy(new SpellCheckPlugin(fakeTextServicesManager, fakeSpellCheckChannel));
140 SpellCheckerSession fakeSpellCheckerSession = mock(SpellCheckerSession.class);
141 Locale english_US = new Locale("en", "US");
142
143 when(fakeTextServicesManager.newSpellCheckerSession(null, english_US, spellCheckPlugin, true))
144 .thenReturn(fakeSpellCheckerSession);
145
146 int maxSuggestions = 5;
147 ArgumentCaptor<TextInfo[]> textInfosCaptor = ArgumentCaptor.forClass(TextInfo[].class);
148 ArgumentCaptor<Integer> maxSuggestionsCaptor = ArgumentCaptor.forClass(Integer.class);
149
150 spellCheckPlugin.performSpellCheck("en-US", "Hello, wrold!");
151
152 verify(fakeSpellCheckerSession)
153 .getSentenceSuggestions(textInfosCaptor.capture(), maxSuggestionsCaptor.capture());
154 assertEquals("Hello, wrold!", textInfosCaptor.getValue()[0].getText());
155 assertEquals(Integer.valueOf(maxSuggestions), maxSuggestionsCaptor.getValue());
156 }

◆ respondsToSpellCheckChannelMessage()

void io.flutter.plugin.editing.SpellCheckPluginTest.respondsToSpellCheckChannelMessage ( )
inline

Definition at line 50 of file SpellCheckPluginTest.java.

50 {
51 ArgumentCaptor<BinaryMessenger.BinaryMessageHandler> binaryMessageHandlerCaptor =
52 ArgumentCaptor.forClass(BinaryMessenger.BinaryMessageHandler.class);
53 DartExecutor mockBinaryMessenger = mock(DartExecutor.class);
54 SpellCheckChannel.SpellCheckMethodHandler mockHandler =
55 mock(SpellCheckChannel.SpellCheckMethodHandler.class);
56 SpellCheckChannel spellCheckChannel = new SpellCheckChannel(mockBinaryMessenger);
57
58 spellCheckChannel.setSpellCheckMethodHandler(mockHandler);
59
60 verify(mockBinaryMessenger, times(1))
61 .setMessageHandler(any(String.class), binaryMessageHandlerCaptor.capture());
62
63 BinaryMessenger.BinaryMessageHandler binaryMessageHandler =
64 binaryMessageHandlerCaptor.getValue();
65
66 sendToBinaryMessageHandler(
67 binaryMessageHandler,
68 "SpellCheck.initiateSpellCheck",
69 Arrays.asList("en-US", "Hello, wrold!"));
70
71 verify(mockHandler)
72 .initiateSpellCheck(eq("en-US"), eq("Hello, wrold!"), any(MethodChannel.Result.class));
73 }
static bool eq(const SkM44 &a, const SkM44 &b, float tol)
Definition: M44Test.cpp:18
SIT bool any(const Vec< 1, T > &x)
Definition: SkVx.h:530

The documentation for this class was generated from the following file: