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
1414 *******************************************************************************/
1515package org .eclipse .swt .tests .junit ;
1616
17-
1817import static org .junit .jupiter .api .Assertions .assertEquals ;
1918import static org .junit .jupiter .api .Assertions .assertFalse ;
19+ import static org .junit .jupiter .api .Assertions .assertThrows ;
2020import static org .junit .jupiter .api .Assertions .assertTrue ;
2121
2222import org .eclipse .swt .SWT ;
@@ -49,7 +49,6 @@ public void tearDown() {
4949 shell .dispose ();
5050}
5151private 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}
8181private 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