Skip to content

Commit 4ce9c35

Browse files
committed
Updated SaveableCompareEditorInputTest for swapped compare logic
Prepare the test to be executed with swapped left/right logic. See eclipse-platform/eclipse.platform.ui#3776
1 parent 4d46f12 commit 4ce9c35

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

team/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ui/SaveableCompareEditorInputTest.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.eclipse.compare.ITypedElement;
3434
import org.eclipse.compare.contentmergeviewer.TextMergeViewer;
3535
import org.eclipse.compare.internal.CompareEditor;
36+
import org.eclipse.compare.internal.ComparePreferencePage;
3637
import org.eclipse.compare.internal.CompareUIPlugin;
3738
import org.eclipse.compare.internal.MergeSourceViewer;
3839
import org.eclipse.compare.structuremergeviewer.Differencer;
@@ -47,6 +48,7 @@
4748
import org.eclipse.core.runtime.IStatus;
4849
import org.eclipse.core.runtime.Platform;
4950
import org.eclipse.core.tests.resources.util.WorkspaceResetExtension;
51+
import org.eclipse.jface.preference.IPreferenceStore;
5052
import org.eclipse.jface.viewers.Viewer;
5153
import org.eclipse.swt.custom.StyledText;
5254
import org.eclipse.swt.graphics.Image;
@@ -214,8 +216,8 @@ public TestSaveableEditorInput(ITypedElement left, ITypedElement right,
214216
protected ICompareInput prepareCompareInput(IProgressMonitor monitor)
215217
throws InvocationTargetException, InterruptedException {
216218
input = createCompareInput();
217-
getCompareConfiguration().setLeftEditable(true);
218-
getCompareConfiguration().setRightEditable(false);
219+
getCompareConfiguration().setLeftEditable(leftIsChanged());
220+
getCompareConfiguration().setRightEditable(rightIsChanged());
219221
return null;
220222
}
221223

@@ -229,6 +231,15 @@ protected void fireInputChange() {
229231
}
230232
}
231233

234+
static boolean rightIsChanged() {
235+
IPreferenceStore store = CompareUIPlugin.getDefault().getPreferenceStore();
236+
return store.getBoolean(ComparePreferencePage.SWAPPED);
237+
}
238+
239+
static boolean leftIsChanged() {
240+
return !rightIsChanged();
241+
}
242+
232243
private void verifyDirtyStateChanges(
233244
TestSaveableEditorInput compareEditorInput)
234245
throws IllegalArgumentException, SecurityException,
@@ -240,10 +251,14 @@ private void verifyDirtyStateChanges(
240251
.findContentViewer(null, compareEditorInput.input, shell);
241252
viewer.setInput(compareEditorInput.getCompareResult());
242253

243-
MergeSourceViewer left = (MergeSourceViewer) ReflectionUtils.getField(
244-
viewer, "fLeft");
254+
MergeSourceViewer changed;
255+
if (leftIsChanged()) {
256+
changed = (MergeSourceViewer) ReflectionUtils.getField(viewer, "fLeft");
257+
} else {
258+
changed = (MergeSourceViewer) ReflectionUtils.getField(viewer, "fRight");
259+
}
245260

246-
StyledText leftText = left.getSourceViewer().getTextWidget();
261+
StyledText leftText = changed.getSourceViewer().getTextWidget();
247262

248263
// modify the left side of editor
249264
leftText.append(appendFileContents);
@@ -270,7 +285,6 @@ public void testDirtyFlagOnLocalResourceTypedElement()
270285
ITypedElement el2 = new TestFileElement(file2);
271286

272287
CompareConfiguration conf = new CompareConfiguration();
273-
conf.setLeftEditable(true);
274288
TestSaveableEditorInput compareEditorInput = new TestSaveableEditorInput(
275289
el1, el2, conf);
276290

@@ -293,7 +307,6 @@ public void testDirtyFlagOnCustomTypedElement() throws CoreException,
293307
ITypedElement el2 = new TestFileElement(file2);
294308

295309
CompareConfiguration conf = new CompareConfiguration();
296-
conf.setLeftEditable(true);
297310
TestSaveableEditorInput compareEditorInput = new TestSaveableEditorInput(
298311
el1, el2, conf);
299312

@@ -321,7 +334,6 @@ public void testDirtyFlagOnLocalResourceTypedElementAndEmptyRight()
321334
ITypedElement el2 = null;
322335

323336
CompareConfiguration conf = new CompareConfiguration();
324-
conf.setLeftEditable(true);
325337
TestSaveableEditorInput compareEditorInput = new TestSaveableEditorInput(
326338
el1, el2, conf);
327339

@@ -344,7 +356,6 @@ public void testDirtyFlagOnCustomTypedElementAndEmptyRight()
344356
ITypedElement el2 = null;
345357

346358
CompareConfiguration conf = new CompareConfiguration();
347-
conf.setLeftEditable(true);
348359
TestSaveableEditorInput compareEditorInput = new TestSaveableEditorInput(
349360
el1, el2, conf);
350361

0 commit comments

Comments
 (0)