Skip to content

Commit 73f342c

Browse files
committed
Use assertThrows in ToolBar tests
1 parent 3a62d65 commit 73f342c

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

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

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
import static org.junit.Assert.assertArrayEquals;
1717
import static org.junit.Assert.assertEquals;
18+
import static org.junit.Assert.assertThrows;
1819
import static org.junit.Assert.assertTrue;
19-
import static org.junit.Assert.fail;
2020

2121
import java.util.ArrayList;
2222
import java.util.List;
@@ -45,12 +45,7 @@ public void setUp() {
4545
@Override
4646
@Test
4747
public void test_ConstructorLorg_eclipse_swt_widgets_CompositeI() {
48-
try {
49-
new ToolBar(null, 0);
50-
fail("No exception thrown for parent == null");
51-
}
52-
catch (IllegalArgumentException e) {
53-
}
48+
assertThrows("No exception thrown for parent == null", IllegalArgumentException.class, () -> new ToolBar(null, 0));
5449
}
5550

5651
@Override
@@ -84,17 +79,12 @@ public void test_getItemI() {
8479
}
8580

8681
toolBar = new ToolBar(shell, 0);
87-
number = 5;
8882
items = new ToolItem[number];
8983
for (int i = 0; i<number ; i++){
9084
items[i] = new ToolItem(toolBar, 0);
9185
}
92-
try {
93-
toolBar.getItem(number);
94-
fail("No exception thrown for illegal index argument");
95-
}
96-
catch (IllegalArgumentException e) {
97-
}
86+
assertThrows("No exception thrown for illegal index argument", IllegalArgumentException.class, ()->
87+
toolBar.getItem(number));
9888
}
9989

10090
@Test
@@ -159,12 +149,8 @@ public void test_indexOfLorg_eclipse_swt_widgets_ToolItem() {
159149
tis[i] = new ToolItem(toolBar, 0);
160150
}
161151
for (int i = 0; i<number ; i++){
162-
try {
163-
toolBar.indexOf(null);
164-
fail("No exception thrown for toolItem == null");
165-
}
166-
catch (IllegalArgumentException e) {
167-
}
152+
assertThrows("No exception thrown for toolItem == null", IllegalArgumentException.class,
153+
() -> toolBar.indexOf(null));
168154
}
169155
}
170156

0 commit comments

Comments
 (0)