Skip to content

Commit 20bb38c

Browse files
committed
Cleanup Link tests to use assertThrows
And one small correction to call the correct getter.
1 parent 6425e28 commit 20bb38c

1 file changed

Lines changed: 7 additions & 28 deletions

File tree

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

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2016 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 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
@@ -17,8 +17,8 @@
1717
import static org.junit.jupiter.api.Assertions.assertFalse;
1818
import static org.junit.jupiter.api.Assertions.assertNotEquals;
1919
import static org.junit.jupiter.api.Assertions.assertNotNull;
20+
import static org.junit.jupiter.api.Assertions.assertThrows;
2021
import static org.junit.jupiter.api.Assertions.assertTrue;
21-
import static org.junit.jupiter.api.Assertions.fail;
2222

2323
import org.eclipse.swt.SWT;
2424
import org.eclipse.swt.events.SelectionEvent;
@@ -60,13 +60,7 @@ public void test_ConstructorLorg_eclipse_swt_widgets_CompositeI() {
6060
link.dispose();
6161
link = new Link(shell, SWT.BORDER);
6262
link.dispose();
63-
try {
64-
link = new Link(null, 0);
65-
fail("No exception thrown for parent == null");
66-
}
67-
catch (IllegalArgumentException e) {
68-
// expected
69-
}
63+
assertThrows(IllegalArgumentException.class, () -> new Link(null, 0), "No exception thrown for parent == null");
7064
}
7165

7266
@Test
@@ -82,23 +76,13 @@ public void widgetDefaultSelected(SelectionEvent e) {
8276
}
8377
};
8478

85-
try {
86-
link.addSelectionListener(null);
87-
fail("No exception thrown for addSelectionListener with null argument");
88-
} catch (IllegalArgumentException e) {
89-
// expected
90-
}
79+
assertThrows(IllegalArgumentException.class, () -> link.addSelectionListener(null), "No exception thrown for addSelectionListener with null argument");
9180

9281
link.addSelectionListener(listener);
9382
link.notifyListeners(SWT.Selection, new Event());
9483
assertTrue(listenerCalled);
9584

96-
try {
97-
link.removeSelectionListener(null);
98-
fail("No exception thrown for removeSelectionListener with null argument");
99-
} catch (IllegalArgumentException e) {
100-
// expected
101-
}
85+
assertThrows(IllegalArgumentException.class, () -> link.removeSelectionListener(null), "No exception thrown for removeSelectionListener with null argument");
10286
listenerCalled = false;
10387
link.removeSelectionListener(listener);
10488
link.notifyListeners(SWT.Selection, new Event());
@@ -174,12 +158,7 @@ public void test_setTextLjava_lang_String() {
174158
link.setText(text);
175159
assertEquals(link.getText() , text);
176160
}
177-
try {
178-
link.setText(null);
179-
fail("No exception thrown for text == null");
180-
} catch (IllegalArgumentException e) {
181-
// expected
182-
}
161+
assertThrows(IllegalArgumentException.class, () -> link.setText(null), "No exception thrown for text == null");
183162
}
184163

185164
@Test
@@ -189,7 +168,7 @@ public void test_setLinkForegroundLorg_eclipse_swt_graphics_Color() {
189168
link.setLinkForeground(color);
190169
assertEquals(color, link.getLinkForeground());
191170
link.setLinkForeground(null);
192-
assertNotEquals(color, link.getForeground());
171+
assertNotEquals(color, link.getLinkForeground());
193172
}
194173

195174

0 commit comments

Comments
 (0)