From 08b37f8d75508a1c82afc1dd94a36c7c08af2e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Fri, 17 Oct 2025 12:11:48 +0300 Subject: [PATCH] Use assertThrows in Test*BidiSegmentListener --- ...clipse_swt_custom_BidiSegmentListener.java | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_BidiSegmentListener.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_BidiSegmentListener.java index cb7d031a3c..9a04a2b5ff 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_BidiSegmentListener.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_BidiSegmentListener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,9 +14,9 @@ *******************************************************************************/ package org.eclipse.swt.tests.junit; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import org.eclipse.swt.SWT; @@ -49,7 +49,6 @@ public void tearDown() { shell.dispose(); } private void testListener(final int[] segments, boolean exceptionExpected) { - boolean exceptionThrown = false; BidiSegmentListener listener = event -> { assertEquals(0, event.lineOffset, " incorrect BidiSegmentEvent"); assertEquals(line, event.lineText, " incorrect BidiSegmentEvent"); @@ -60,18 +59,19 @@ private void testListener(final int[] segments, boolean exceptionExpected) { listenerCalled = false; try { - text.addBidiSegmentListener(listener); - text.getLocationAtOffset(0); - } catch (IllegalArgumentException e) { - exceptionThrown = true; + if (exceptionExpected) { + assertThrows(IllegalArgumentException.class, () -> { + text.addBidiSegmentListener(listener); + text.getLocationAtOffset(0); + }); + } else { + text.addBidiSegmentListener(listener); + text.getLocationAtOffset(0); + } + } finally { text.removeBidiSegmentListener(listener); } - if (exceptionExpected) { - assertTrue(exceptionThrown, " expected exception not thrown"); - } else { - assertFalse(exceptionThrown, " unexpected exception thrown"); - } if (SwtTestUtil.isBidi()) { assertTrue(listenerCalled, " listener not called"); } else { @@ -79,7 +79,6 @@ private void testListener(final int[] segments, boolean exceptionExpected) { } } private void testStyleRangeSegmenting(final int[] segments, int[] boldRanges) { - boolean exceptionThrown = false; BidiSegmentListener listener = event -> { assertEquals(0, event.lineOffset, " incorrect BidiSegmentEvent"); assertEquals(line, event.lineText, " incorrect BidiSegmentEvent"); @@ -97,12 +96,9 @@ private void testStyleRangeSegmenting(final int[] segments, int[] boldRanges) { text.setStyleRange(styleRange); } text.getLocationAtOffset(0); - } catch (IllegalArgumentException e) { - exceptionThrown = true; } finally { text.removeBidiSegmentListener(listener); } - assertFalse(exceptionThrown, " unexpected exception thrown"); if (SwtTestUtil.isBidi()) { assertTrue(listenerCalled, " listener not called"); } else {