Skip to content

Commit 1f8df87

Browse files
committed
Use assertThrows in Test*BidiSegmentListener
1 parent ff25c35 commit 1f8df87

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_BidiSegmentListener.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2017 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,9 +14,9 @@
1414
*******************************************************************************/
1515
package org.eclipse.swt.tests.junit;
1616

17-
1817
import static org.junit.jupiter.api.Assertions.assertEquals;
1918
import static org.junit.jupiter.api.Assertions.assertFalse;
19+
import static org.junit.jupiter.api.Assertions.assertThrows;
2020
import static org.junit.jupiter.api.Assertions.assertTrue;
2121

2222
import org.eclipse.swt.SWT;
@@ -49,7 +49,6 @@ public void tearDown() {
4949
shell.dispose();
5050
}
5151
private void testListener(final int[] segments, boolean exceptionExpected) {
52-
boolean exceptionThrown = false;
5352
BidiSegmentListener listener = event -> {
5453
assertEquals(0, event.lineOffset, " incorrect BidiSegmentEvent");
5554
assertEquals(line, event.lineText, " incorrect BidiSegmentEvent");
@@ -60,26 +59,26 @@ private void testListener(final int[] segments, boolean exceptionExpected) {
6059

6160
listenerCalled = false;
6261
try {
63-
text.addBidiSegmentListener(listener);
64-
text.getLocationAtOffset(0);
65-
} catch (IllegalArgumentException e) {
66-
exceptionThrown = true;
62+
if (exceptionExpected) {
63+
assertThrows(IllegalArgumentException.class, () -> {
64+
text.addBidiSegmentListener(listener);
65+
text.getLocationAtOffset(0);
66+
});
67+
} else {
68+
text.addBidiSegmentListener(listener);
69+
text.getLocationAtOffset(0);
70+
}
71+
6772
} finally {
6873
text.removeBidiSegmentListener(listener);
6974
}
70-
if (exceptionExpected) {
71-
assertTrue(exceptionThrown, " expected exception not thrown");
72-
} else {
73-
assertFalse(exceptionThrown, " unexpected exception thrown");
74-
}
7575
if (SwtTestUtil.isBidi()) {
7676
assertTrue(listenerCalled, " listener not called");
7777
} else {
7878
assertFalse(listenerCalled, " listener called when it shouldn't be");
7979
}
8080
}
8181
private void testStyleRangeSegmenting(final int[] segments, int[] boldRanges) {
82-
boolean exceptionThrown = false;
8382
BidiSegmentListener listener = event -> {
8483
assertEquals(0, event.lineOffset, " incorrect BidiSegmentEvent");
8584
assertEquals(line, event.lineText, " incorrect BidiSegmentEvent");
@@ -97,12 +96,9 @@ private void testStyleRangeSegmenting(final int[] segments, int[] boldRanges) {
9796
text.setStyleRange(styleRange);
9897
}
9998
text.getLocationAtOffset(0);
100-
} catch (IllegalArgumentException e) {
101-
exceptionThrown = true;
10299
} finally {
103100
text.removeBidiSegmentListener(listener);
104101
}
105-
assertFalse(exceptionThrown, " unexpected exception thrown");
106102
if (SwtTestUtil.isBidi()) {
107103
assertTrue(listenerCalled, " listener not called");
108104
} else {

0 commit comments

Comments
 (0)