Skip to content

Commit

Permalink
Improve "silent" fails in MarkOccurrenceTest
Browse files Browse the repository at this point in the history
Test is unstable (e.g. failed in tonight's I-build
https://download.eclipse.org/eclipse/downloads/drops4/I20240421-1800/testresults/html/org.eclipse.jdt.text.tests_ep432I-unit-cen64-gtk3-java17_linux.gtk.x86_64_17.html
).
This change replaces silent fails with proper exception reporting.
  • Loading branch information
akurtakov committed Apr 22, 2024
1 parent 435b254 commit a1cc709
Showing 1 changed file with 26 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2020 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -111,10 +111,6 @@ public void setUp() throws Exception {
fMatch= null;
fSelWASTListener= new ISelectionListenerWithAST() {

/*
* @see org.eclipse.jdt.internal.ui.viewsupport.ISelectionListenerWithAST#selectionChanged(org.eclipse.ui.IEditorPart, org.eclipse.jface.text.ITextSelection, org.eclipse.jdt.core.dom.CompilationUnit)
* @since 3.1
*/
@Override
public void selectionChanged(IEditorPart part, ITextSelection selection, CompilationUnit astRoot) {
if (fMatch != null && selection != null && selection.getOffset() == fMatch.getOffset() && selection.getLength() == fMatch.getLength()) {
Expand Down Expand Up @@ -159,18 +155,14 @@ private JavaEditor openJavaEditor(IPath path) {
try {
return (JavaEditor)EditorTestHelper.openInEditor(file, true);
} catch (PartInitException e) {
fail();
fail(e.getMessage());
return null;
}
}

@Test
public void markTypeOccurrences() {
try {
fMatch= fFindReplaceDocumentAdapter.find(0, "TestResult", true, true, true, false);
} catch (BadLocationException e) {
fail();
}
public void markTypeOccurrences() throws BadLocationException {
fMatch= fFindReplaceDocumentAdapter.find(0, "TestResult", true, true, true, false);
assertNotNull(fMatch);

fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
Expand All @@ -180,7 +172,7 @@ public void markTypeOccurrences() {
}

@Test
public void markOccurrencesAfterEditorReuse() {
public void markOccurrencesAfterEditorReuse() throws BadLocationException {
IPreferenceStore store= getPlatformUIStore();
store.setValue("REUSE_OPEN_EDITORS_BOOLEAN", true);

Expand All @@ -198,11 +190,8 @@ public void markOccurrencesAfterEditorReuse() {
fFindReplaceDocumentAdapter= new FindReplaceDocumentAdapter(fDocument);
fAnnotationModel= fEditor.getDocumentProvider().getAnnotationModel(fEditor.getEditorInput());

try {
fMatch= fFindReplaceDocumentAdapter.find(0, "Test {", true, true, false, false);
} catch (BadLocationException e) {
fail();
}
fMatch= fFindReplaceDocumentAdapter.find(0, "Test {", true, true, false, false);

assertNotNull(fMatch);
fMatch= new Region(fMatch.getOffset(), 4);
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
Expand All @@ -229,12 +218,8 @@ private IPreferenceStore getPlatformUIStore() {
}

@Test
public void markMethodOccurrences() {
try {
fMatch= fFindReplaceDocumentAdapter.find(0, "getClass", true, true, true, false);
} catch (BadLocationException e) {
fail();
}
public void markMethodOccurrences() throws BadLocationException {
fMatch= fFindReplaceDocumentAdapter.find(0, "getClass", true, true, true, false);
assertNotNull(fMatch);

fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
Expand All @@ -243,12 +228,8 @@ public void markMethodOccurrences() {
assertOccurrencesInWidget();
}
@Test
public void markFieldOccurrences() {
try {
fMatch= fFindReplaceDocumentAdapter.find(0, "fName", true, true, true, false);
} catch (BadLocationException e) {
fail();
}
public void markFieldOccurrences() throws BadLocationException {
fMatch= fFindReplaceDocumentAdapter.find(0, "fName", true, true, true, false);
assertNotNull(fMatch);

fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
Expand All @@ -258,12 +239,8 @@ public void markFieldOccurrences() {
}

@Test
public void markLocalOccurrences() {
try {
fMatch= fFindReplaceDocumentAdapter.find(0, "runMethod", true, true, true, false);
} catch (BadLocationException e) {
fail();
}
public void markLocalOccurrences() throws BadLocationException {
fMatch= fFindReplaceDocumentAdapter.find(0, "runMethod", true, true, true, false);
assertNotNull(fMatch);

fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
Expand All @@ -273,12 +250,8 @@ public void markLocalOccurrences() {
}

@Test
public void markMethodExitOccurrences() {
try {
fMatch= fFindReplaceDocumentAdapter.find(0, "void runTest() throws", true, true, false, false);
} catch (BadLocationException e) {
fail();
}
public void markMethodExitOccurrences() throws BadLocationException {
fMatch= fFindReplaceDocumentAdapter.find(0, "void runTest() throws", true, true, false, false);
assertNotNull(fMatch);
fMatch= new Region(fMatch.getOffset(), 4);

Expand All @@ -289,12 +262,8 @@ public void markMethodExitOccurrences() {
}

@Test
public void markMethodExceptionOccurrences() {
try {
fMatch= fFindReplaceDocumentAdapter.find(0, "NoSuchMethodException", true, true, true, false);
} catch (BadLocationException e) {
fail();
}
public void markMethodExceptionOccurrences() throws BadLocationException {
fMatch= fFindReplaceDocumentAdapter.find(0, "NoSuchMethodException", true, true, true, false);
assertNotNull(fMatch);

fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
Expand All @@ -304,12 +273,8 @@ public void markMethodExceptionOccurrences() {
}

@Test
public void markImplementOccurrences1() {
try {
fMatch= fFindReplaceDocumentAdapter.find(0, "Test {", true, true, false, false);
} catch (BadLocationException e) {
fail();
}
public void markImplementOccurrences1() throws BadLocationException {
fMatch= fFindReplaceDocumentAdapter.find(0, "Test {", true, true, false, false);
assertNotNull(fMatch);
fMatch= new Region(fMatch.getOffset(), 4);

Expand All @@ -320,14 +285,10 @@ public void markImplementOccurrences1() {
}

@Test
public void markImplementOccurrences2() {
public void markImplementOccurrences2() throws BadLocationException {
JavaPlugin.getDefault().getPreferenceStore().setValue(PreferenceConstants.EDITOR_MARK_IMPLEMENTORS, false);

try {
fMatch= fFindReplaceDocumentAdapter.find(0, "Test {", true, true, false, false);
} catch (BadLocationException e) {
fail();
}
fMatch= fFindReplaceDocumentAdapter.find(0, "Test {", true, true, false, false);
assertNotNull(fMatch);
fMatch= new Region(fMatch.getOffset(), 4);

Expand All @@ -338,12 +299,8 @@ public void markImplementOccurrences2() {
}

@Test
public void markImplementOccurrences3() {
try {
fMatch= fFindReplaceDocumentAdapter.find(0, "Assert", true, true, false, false);
} catch (BadLocationException e) {
fail();
}
public void markImplementOccurrences3() throws BadLocationException {
fMatch= fFindReplaceDocumentAdapter.find(0, "Assert", true, true, false, false);
assertNotNull(fMatch);

fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
Expand All @@ -353,13 +310,9 @@ public void markImplementOccurrences3() {
}

@Test
public void noOccurrencesIfDisabled() {
public void noOccurrencesIfDisabled() throws BadLocationException {
JavaPlugin.getDefault().getPreferenceStore().setValue(PreferenceConstants.EDITOR_MARK_OCCURRENCES, false);
try {
fMatch= fFindReplaceDocumentAdapter.find(0, "TestResult", true, true, true, false);
} catch (BadLocationException e) {
fail();
}
fMatch= fFindReplaceDocumentAdapter.find(0, "TestResult", true, true, true, false);
assertNotNull(fMatch);

fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
Expand Down Expand Up @@ -387,7 +340,7 @@ private void assertOccurrenceInWidget(Position position) {
return;
}
}
fail();
fail("No StyleRange with expected highlight RGB for given position(" + position.offset + "," + position.length + ")");
}

/**
Expand Down

0 comments on commit a1cc709

Please sign in to comment.