Skip to content

Commit deb75d4

Browse files
Maximilian WittmerHeikoKlare
authored andcommitted
Move specific FindReplaceDialog Tests into the separated test-class
Some tests in FindReplaceUITest.java are not general to all find/replace interfaces and are specific for the find/replace dialog. This commit moves these tests into the dedicated test class and provides the necessary interface in FindReplaceUITest
1 parent 8ba3829 commit deb75d4

File tree

2 files changed

+93
-58
lines changed

2 files changed

+93
-58
lines changed

tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/FindReplaceDialogTest.java

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
package org.eclipse.ui.workbench.texteditor.tests;
1515

1616
import static org.eclipse.ui.workbench.texteditor.tests.FindReplaceTestUtil.runEventQueue;
17+
import static org.hamcrest.MatcherAssert.assertThat;
18+
import static org.hamcrest.Matchers.is;
1719
import static org.junit.Assert.assertEquals;
1820
import static org.junit.Assert.assertTrue;
1921
import static org.junit.Assume.assumeFalse;
@@ -37,7 +39,6 @@
3739
import org.eclipse.ui.internal.findandreplace.SearchOptions;
3840

3941
public class FindReplaceDialogTest extends FindReplaceUITest<DialogAccess> {
40-
4142
@Override
4243
public DialogAccess openUIFromTextViewer(TextViewer viewer) {
4344
TextViewer textViewer= getTextViewer();
@@ -146,4 +147,87 @@ public void testShiftEnterReversesSearchDirectionDialogSpecific() {
146147
dialog.simulateEnterInFindInputField(true);
147148
assertEquals(5, (target.getSelection()).x);
148149
}
150+
151+
@Test
152+
public void testReplaceAndFindAfterInitializingFindWithSelectedString() {
153+
openTextViewer("text text text");
154+
getTextViewer().setSelectedRange(0, 4);
155+
initializeFindReplaceUIForTextViewer();
156+
DialogAccess dialog= getDialog();
157+
158+
assertThat(dialog.getFindText(), is("text"));
159+
160+
IFindReplaceTarget target= dialog.getTarget();
161+
assertEquals(0, (target.getSelection()).x);
162+
assertEquals(4, (target.getSelection()).y);
163+
164+
dialog.performReplaceAndFind();
165+
166+
assertEquals(" text text", getTextViewer().getDocument().get());
167+
assertEquals(1, (target.getSelection()).x);
168+
assertEquals(4, (target.getSelection()).y);
169+
}
170+
171+
@Test
172+
public void testIncrementalSearchOnlyEnabledWhenAllowed() {
173+
initializeTextViewerWithFindReplaceUI("text text text");
174+
DialogAccess dialog= getDialog();
175+
176+
dialog.select(SearchOptions.INCREMENTAL);
177+
dialog.select(SearchOptions.REGEX);
178+
179+
dialog.assertSelected(SearchOptions.INCREMENTAL);
180+
dialog.assertDisabled(SearchOptions.INCREMENTAL);
181+
}
182+
183+
/*
184+
* Test for https://github.com/eclipse-platform/eclipse.platform.ui/pull/1805#pullrequestreview-1993772378
185+
*/
186+
@Test
187+
public void testIncrementalSearchOptionRecoveredCorrectly() {
188+
initializeTextViewerWithFindReplaceUI("text text text");
189+
DialogAccess dialog= getDialog();
190+
191+
dialog.select(SearchOptions.INCREMENTAL);
192+
dialog.assertSelected(SearchOptions.INCREMENTAL);
193+
dialog.assertEnabled(SearchOptions.INCREMENTAL);
194+
195+
reopenFindReplaceUIForTextViewer();
196+
dialog= getDialog();
197+
dialog.assertSelected(SearchOptions.INCREMENTAL);
198+
dialog.assertEnabled(SearchOptions.INCREMENTAL);
199+
200+
dialog.select(SearchOptions.REGEX);
201+
dialog.assertSelected(SearchOptions.INCREMENTAL);
202+
dialog.assertDisabled(SearchOptions.INCREMENTAL);
203+
204+
reopenFindReplaceUIForTextViewer();
205+
dialog= getDialog();
206+
dialog.assertSelected(SearchOptions.INCREMENTAL);
207+
dialog.assertDisabled(SearchOptions.INCREMENTAL);
208+
}
209+
210+
@Test
211+
public void testFindWithWholeWordEnabledWithMultipleWordsNotIncremental() {
212+
initializeTextViewerWithFindReplaceUI("two words two");
213+
DialogAccess dialog = getDialog();
214+
dialog.setFindText("two");
215+
dialog.select(SearchOptions.WHOLE_WORD);
216+
dialog.select(SearchOptions.WRAP);
217+
IFindReplaceTarget target= dialog.getTarget();
218+
219+
dialog.simulateEnterInFindInputField(false);
220+
assertEquals(0, (target.getSelection()).x);
221+
assertEquals(3, (target.getSelection()).y);
222+
223+
dialog.setFindText("two wo");
224+
dialog.assertDisabled(SearchOptions.WHOLE_WORD);
225+
dialog.assertSelected(SearchOptions.WHOLE_WORD);
226+
227+
dialog.simulateEnterInFindInputField(false);
228+
assertThat(target.getSelectionText(), is(dialog.getFindText()));
229+
230+
assertEquals(0, (target.getSelection()).x);
231+
assertEquals(dialog.getFindText().length(), (target.getSelection()).y);
232+
}
149233
}

tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/workbench/texteditor/tests/FindReplaceUITest.java

Lines changed: 8 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ protected final void initializeTextViewerWithFindReplaceUI(String content) {
4949
initializeFindReplaceUIForTextViewer();
5050
}
5151

52-
private void openTextViewer(String content) {
52+
protected void openTextViewer(String content) {
5353
fTextViewer= new TextViewer(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
5454
fTextViewer.setDocument(new Document(content));
5555
fTextViewer.getControl().setFocus();
5656
}
5757

58-
private void initializeFindReplaceUIForTextViewer() {
58+
protected void initializeFindReplaceUIForTextViewer() {
5959
dialog= openUIFromTextViewer(fTextViewer);
6060
dialog.assertInitialConfiguration();
6161
}
6262

63-
private void reopenFindReplaceUIForTextViewer() {
63+
protected void reopenFindReplaceUIForTextViewer() {
6464
dialog.close();
6565
dialog= openUIFromTextViewer(fTextViewer);
6666
}
@@ -189,45 +189,31 @@ public void testChangeInputForIncrementalSearch() {
189189
@Test
190190
public void testFindWithWholeWordEnabledWithMultipleWords() {
191191
initializeTextViewerWithFindReplaceUI("two words two");
192-
dialog.setFindText("two");
192+
dialog.select(SearchOptions.INCREMENTAL);
193193
dialog.select(SearchOptions.WHOLE_WORD);
194194
dialog.select(SearchOptions.WRAP);
195+
dialog.setFindText("two");
195196
IFindReplaceTarget target= dialog.getTarget();
196197
assertEquals(0, (target.getSelection()).x);
197-
assertEquals(0, (target.getSelection()).y);
198+
assertEquals(3, (target.getSelection()).y);
198199

199200
dialog.setFindText("two wo");
200201
dialog.assertDisabled(SearchOptions.WHOLE_WORD);
201202
dialog.assertSelected(SearchOptions.WHOLE_WORD);
202203

203204
dialog.simulateEnterInFindInputField(false);
204205
assertThat(target.getSelectionText(), is(dialog.getFindText()));
205-
assertEquals(0, (target.getSelection()).x);
206-
assertEquals(dialog.getFindText().length(), (target.getSelection()).y);
207-
}
208-
209-
@Test
210-
public void testReplaceAndFindAfterInitializingFindWithSelectedString() {
211-
openTextViewer("text text text");
212-
fTextViewer.setSelectedRange(0, 4);
213-
initializeFindReplaceUIForTextViewer();
214206

215-
IFindReplaceTarget target= dialog.getTarget();
216207
assertEquals(0, (target.getSelection()).x);
217-
assertEquals(4, (target.getSelection()).y);
218-
219-
dialog.performReplaceAndFind();
220-
221-
assertEquals(" text text", fTextViewer.getDocument().get());
222-
assertEquals(1, (target.getSelection()).x);
223-
assertEquals(4, (target.getSelection()).y);
208+
assertEquals(dialog.getFindText().length(), (target.getSelection()).y);
224209
}
225210

226211
@Test
227212
public void testRegExSearch() {
228213
initializeTextViewerWithFindReplaceUI("abc");
229214
dialog.select(SearchOptions.REGEX);
230215
dialog.setFindText("(a|bc)");
216+
231217
IFindReplaceTarget target= dialog.getTarget();
232218
dialog.simulateEnterInFindInputField(false);
233219
assertEquals(0, (target.getSelection()).x);
@@ -304,41 +290,6 @@ public void testActivateDialogWithSelectionActive() {
304290
assertThat(fTextViewer.getDocument().get(), is("text" + System.lineSeparator() + System.lineSeparator()));
305291
}
306292

307-
@Test
308-
public void testIncrementalSearchOnlyEnabledWhenAllowed() {
309-
initializeTextViewerWithFindReplaceUI("text text text");
310-
311-
dialog.select(SearchOptions.INCREMENTAL);
312-
dialog.select(SearchOptions.REGEX);
313-
314-
dialog.assertSelected(SearchOptions.INCREMENTAL);
315-
dialog.assertDisabled(SearchOptions.INCREMENTAL);
316-
}
317-
318-
/*
319-
* Test for https://github.com/eclipse-platform/eclipse.platform.ui/pull/1805#pullrequestreview-1993772378
320-
*/
321-
@Test
322-
public void testIncrementalSearchOptionRecoveredCorrectly() {
323-
initializeTextViewerWithFindReplaceUI("text text text");
324-
325-
dialog.select(SearchOptions.INCREMENTAL);
326-
dialog.assertSelected(SearchOptions.INCREMENTAL);
327-
dialog.assertEnabled(SearchOptions.INCREMENTAL);
328-
329-
reopenFindReplaceUIForTextViewer();
330-
dialog.assertSelected(SearchOptions.INCREMENTAL);
331-
dialog.assertEnabled(SearchOptions.INCREMENTAL);
332-
333-
dialog.select(SearchOptions.REGEX);
334-
dialog.assertSelected(SearchOptions.INCREMENTAL);
335-
dialog.assertDisabled(SearchOptions.INCREMENTAL);
336-
337-
reopenFindReplaceUIForTextViewer();
338-
dialog.assertSelected(SearchOptions.INCREMENTAL);
339-
dialog.assertDisabled(SearchOptions.INCREMENTAL);
340-
}
341-
342293
protected AccessType getDialog() {
343294
return dialog;
344295
}

0 commit comments

Comments
 (0)