Skip to content

Commit e3d73d5

Browse files
ptzieglerakurtakov
authored andcommitted
Refactor fail() calls in Cursor tests
This replaces the following pattern with a simple assertThrows(...): try { ... fail(...) } catch (Exception e) { }
1 parent 2e13c10 commit e3d73d5

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

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

Lines changed: 8 additions & 20 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, 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
@@ -16,8 +16,8 @@
1616

1717

1818
import static org.junit.Assert.assertNotNull;
19+
import static org.junit.Assert.assertThrows;
1920
import static org.junit.Assert.assertTrue;
20-
import static org.junit.Assert.fail;
2121

2222
import java.io.IOException;
2323
import java.io.InputStream;
@@ -120,20 +120,12 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceI() {
120120
cursor.dispose();
121121

122122
// illegal argument, style > SWT.CURSOR_HAND (21)
123-
try {
124-
cursor = new Cursor(display, 100);
125-
cursor.dispose();
126-
fail("No exception thrown for style > SWT.CURSOR_HAND (21)");
127-
} catch (IllegalArgumentException e) {
128-
}
123+
assertThrows("No exception thrown for style > SWT.CURSOR_HAND (21)",
124+
IllegalArgumentException.class, () -> new Cursor(display, 100));
129125

130126
// illegal argument, style < 0
131-
try {
132-
cursor = new Cursor(display, -100);
133-
cursor.dispose();
134-
fail("No exception thrown for style < 0");
135-
} catch (IllegalArgumentException e) {
136-
}
127+
assertThrows("No exception thrown for style < 0",
128+
IllegalArgumentException.class, () -> new Cursor(display, -100));
137129
}
138130

139131
@Test
@@ -164,12 +156,8 @@ public void test_ConstructorWithImageDataProvider() {
164156
cursor.dispose();
165157
sourceImage.dispose();
166158

167-
try {
168-
cursor = new Cursor(display, (ImageDataProvider) null, 0, 0);
169-
cursor.dispose();
170-
fail("No exception thrown when ImageDataProvider is null");
171-
} catch (IllegalArgumentException e) {
172-
}
159+
assertThrows("No exception thrown when ImageDataProvider is null",
160+
IllegalArgumentException.class, () -> new Cursor(display, (ImageDataProvider) null, 0, 0));
173161
}
174162

175163
@Test

0 commit comments

Comments
 (0)