Skip to content

Commit fbdacfb

Browse files
committed
Convert Dialog(s) tests to JUnit 5
1 parent ea7af55 commit fbdacfb

7 files changed

+75
-134
lines changed

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
*******************************************************************************/
1414
package org.eclipse.swt.tests.junit;
1515

16-
import static org.junit.Assert.fail;
16+
import static org.junit.jupiter.api.Assertions.assertThrows;
1717

1818
import org.eclipse.swt.SWT;
1919
import org.eclipse.swt.printing.PrintDialog;
20-
import org.junit.Before;
21-
import org.junit.Test;
20+
import org.junit.jupiter.api.BeforeEach;
21+
import org.junit.jupiter.api.Test;
2222

2323
/**
2424
* Automated Test Suite for class org.eclipse.swt.printing.PrintDialog
@@ -28,7 +28,7 @@
2828
public class Test_org_eclipse_swt_printing_PrintDialog extends Test_org_eclipse_swt_widgets_Dialog {
2929

3030
@Override
31-
@Before
31+
@BeforeEach
3232
public void setUp() {
3333
super.setUp();
3434
printDialog = new PrintDialog(shell, SWT.NONE);
@@ -39,24 +39,14 @@ public void setUp() {
3939
public void test_ConstructorLorg_eclipse_swt_widgets_Shell() {
4040
new PrintDialog(shell);
4141

42-
try {
43-
new PrintDialog(null);
44-
fail("No exception thrown for parent == null");
45-
}
46-
catch (IllegalArgumentException e) {
47-
}
42+
assertThrows(IllegalArgumentException.class, () -> new PrintDialog(null),"No exception thrown for parent == null");
4843
}
4944

5045
@Test
5146
public void test_ConstructorLorg_eclipse_swt_widgets_ShellI() {
5247
new PrintDialog(shell, SWT.NONE);
5348

54-
try {
55-
new PrintDialog(null, SWT.NONE);
56-
fail("No exception thrown for parent == null");
57-
}
58-
catch (IllegalArgumentException e) {
59-
}
49+
assertThrows(IllegalArgumentException.class, () -> new PrintDialog(null, SWT.NONE),"No exception thrown for parent == null");
6050
}
6151

6252
/* custom */

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

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313
*******************************************************************************/
1414
package org.eclipse.swt.tests.junit;
1515

16-
17-
import static org.junit.Assert.assertNull;
18-
import static org.junit.Assert.assertTrue;
19-
import static org.junit.Assert.fail;
16+
import static org.junit.jupiter.api.Assertions.assertNull;
17+
import static org.junit.jupiter.api.Assertions.assertThrows;
18+
import static org.junit.jupiter.api.Assertions.assertTrue;
2019

2120
import org.eclipse.swt.SWT;
2221
import org.eclipse.swt.graphics.RGB;
2322
import org.eclipse.swt.widgets.ColorDialog;
24-
import org.junit.Before;
25-
import org.junit.Test;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
2625

2726
/**
2827
* Automated Test Suite for class org.eclipse.swt.widgets.ColorDialog
@@ -34,7 +33,7 @@ public class Test_org_eclipse_swt_widgets_ColorDialog extends Test_org_eclipse_s
3433
ColorDialog colorDialog;
3534

3635
@Override
37-
@Before
36+
@BeforeEach
3837
public void setUp() {
3938
super.setUp();
4039
colorDialog = new ColorDialog(shell, SWT.NULL);
@@ -45,36 +44,26 @@ public void setUp() {
4544
public void test_ConstructorLorg_eclipse_swt_widgets_Shell() {
4645
new ColorDialog(shell);
4746

48-
try {
49-
new ColorDialog(null);
50-
fail("No exception thrown for parent == null");
51-
}
52-
catch (IllegalArgumentException e) {
53-
}
47+
assertThrows(IllegalArgumentException.class,()-> new ColorDialog(null),"No exception thrown for parent == null");
5448
}
5549

5650
@Test
5751
public void test_ConstructorLorg_eclipse_swt_widgets_ShellI() {
5852
new ColorDialog(shell, SWT.NULL);
5953

60-
try {
61-
new ColorDialog(null, SWT.NULL);
62-
fail("No exception thrown for parent == null");
63-
}
64-
catch (IllegalArgumentException e) {
65-
}
54+
assertThrows(IllegalArgumentException.class,()-> new ColorDialog(null, SWT.NULL),"No exception thrown for parent == null");
6655
}
6756

6857
@Test
6958
public void test_setRGBLorg_eclipse_swt_graphics_RGB() {
7059
RGB rgb = new RGB(0, 0, 0);
7160

72-
assertNull(":a:", colorDialog.getRGB());
61+
assertNull(colorDialog.getRGB());
7362

7463
colorDialog.setRGB(rgb);
75-
assertTrue(":b:", colorDialog.getRGB() == rgb);
64+
assertTrue(colorDialog.getRGB() == rgb);
7665

7766
colorDialog.setRGB(null);
78-
assertNull(":c:", colorDialog.getRGB());
67+
assertNull(colorDialog.getRGB());
7968
}
8069
}

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
*******************************************************************************/
1414
package org.eclipse.swt.tests.junit;
1515

16-
import static org.junit.Assert.assertEquals;
17-
import static org.junit.Assert.assertTrue;
18-
import static org.junit.Assert.fail;
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertThrows;
18+
import static org.junit.jupiter.api.Assertions.assertTrue;
1919

2020
import org.eclipse.swt.widgets.Dialog;
2121
import org.eclipse.swt.widgets.Shell;
22-
import org.junit.After;
23-
import org.junit.Before;
24-
import org.junit.Test;
22+
import org.junit.jupiter.api.AfterEach;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
2525

2626
/**
2727
* Automated Test Suite for class org.eclipse.swt.widgets.Dialog
@@ -30,19 +30,19 @@
3030
*/
3131
public class Test_org_eclipse_swt_widgets_Dialog {
3232

33-
@Before
33+
@BeforeEach
3434
public void setUp() {
3535
shell = new Shell();
3636
}
3737

38-
@After
38+
@AfterEach
3939
public void tearDown() {
4040
shell.dispose();
4141
}
4242

4343
@Test
4444
public void test_getParent() {
45-
assertTrue(":a:", dialog.getParent() == shell);
45+
assertTrue(dialog.getParent() == shell);
4646
}
4747

4848
@Test
@@ -54,18 +54,13 @@ public void test_getStyle() {
5454

5555
@Test
5656
public void test_setTextLjava_lang_String() {
57-
assertTrue(":1:", dialog.getText() == "");
57+
assertTrue(dialog.getText() == "");
5858
String testStr = "test string";
5959
dialog.setText(testStr);
60-
assertEquals(":2:", testStr, dialog.getText());
60+
assertEquals(testStr, dialog.getText());
6161
dialog.setText("");
62-
assertTrue(":3:", dialog.getText().isEmpty());
63-
try {
64-
dialog.setText(null);
65-
fail("No exception thrown for string = null");
66-
}
67-
catch (IllegalArgumentException e) {
68-
}
62+
assertTrue(dialog.getText().isEmpty());
63+
assertThrows(IllegalArgumentException.class, () -> dialog.setText(null), "No exception thrown for string = null");
6964
}
7065

7166
/* custom */

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

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
*******************************************************************************/
1414
package org.eclipse.swt.tests.junit;
1515

16-
import static org.junit.Assert.assertEquals;
17-
import static org.junit.Assert.assertNull;
18-
import static org.junit.Assert.assertTrue;
19-
import static org.junit.Assert.fail;
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertNull;
18+
import static org.junit.jupiter.api.Assertions.assertThrows;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
2020

2121
import org.eclipse.swt.SWT;
2222
import org.eclipse.swt.widgets.DirectoryDialog;
23-
import org.junit.Before;
24-
import org.junit.Test;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
2525

2626
/**
2727
* Automated Test Suite for class org.eclipse.swt.widgets.DirectoryDialog
@@ -31,7 +31,7 @@
3131
public class Test_org_eclipse_swt_widgets_DirectoryDialog extends Test_org_eclipse_swt_widgets_Dialog {
3232

3333
@Override
34-
@Before
34+
@BeforeEach
3535
public void setUp() {
3636
super.setUp();
3737
dirDialog = new DirectoryDialog(shell, SWT.NULL);
@@ -41,12 +41,7 @@ public void setUp() {
4141
@Test
4242
public void test_ConstructorLorg_eclipse_swt_widgets_Shell() {
4343
new DirectoryDialog(shell);
44-
try {
45-
new DirectoryDialog(null);
46-
fail("No exception thrown for null parent");
47-
}
48-
catch (IllegalArgumentException e) {
49-
}
44+
assertThrows(IllegalArgumentException.class,()-> new DirectoryDialog(null),"No exception thrown for null parent");
5045
}
5146

5247
@Test
@@ -57,29 +52,25 @@ public void test_open() {
5752

5853
@Test
5954
public void test_setFilterPathLjava_lang_String() {
60-
assertTrue(":1:", dirDialog.getFilterPath() == "");
55+
assertTrue(dirDialog.getFilterPath() == "");
6156
String testStr = "./*";
6257
dirDialog.setFilterPath(testStr);
63-
assertEquals(":2:", testStr, dirDialog.getFilterPath());
58+
assertEquals(testStr, dirDialog.getFilterPath());
6459
dirDialog.setFilterPath("");
65-
assertTrue(":3:", dirDialog.getFilterPath().isEmpty());
60+
assertTrue(dirDialog.getFilterPath().isEmpty());
6661
dirDialog.setFilterPath(null);
67-
assertNull(":4:", dirDialog.getFilterPath());
62+
assertNull(dirDialog.getFilterPath());
6863
}
6964

7065
@Test
7166
public void test_setMessageLjava_lang_String() {
72-
assertTrue(":1:", dirDialog.getMessage() == "");
67+
assertTrue( dirDialog.getMessage() == "");
7368
String testStr = "test string";
7469
dirDialog.setMessage(testStr);
75-
assertEquals(":2:", testStr, dirDialog.getMessage());
70+
assertEquals(testStr, dirDialog.getMessage());
7671
dirDialog.setMessage("");
77-
assertTrue(":3:", dirDialog.getMessage().isEmpty());
78-
try {
79-
dirDialog.setMessage(null);
80-
fail ("null argument did not throw IllegalArgumentException");
81-
} catch (IllegalArgumentException e) {
82-
}
72+
assertTrue(dirDialog.getMessage().isEmpty());
73+
assertThrows(IllegalArgumentException.class,()->dirDialog.setMessage(null),"null argument did not throw IllegalArgumentException");
8374
}
8475

8576
/* custom */

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

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
*******************************************************************************/
1414
package org.eclipse.swt.tests.junit;
1515

16-
import static org.junit.Assert.assertEquals;
17-
import static org.junit.Assert.assertNull;
18-
import static org.junit.Assert.assertTrue;
19-
import static org.junit.Assert.fail;
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertNull;
18+
import static org.junit.jupiter.api.Assertions.assertThrows;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
2020

2121
import org.eclipse.swt.SWT;
2222
import org.eclipse.swt.widgets.FileDialog;
23-
import org.junit.Before;
24-
import org.junit.Test;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
2525

2626
/**
2727
* Automated Test Suite for class org.eclipse.swt.widgets.FileDialog
@@ -31,7 +31,7 @@
3131
public class Test_org_eclipse_swt_widgets_FileDialog extends Test_org_eclipse_swt_widgets_Dialog {
3232

3333
@Override
34-
@Before
34+
@BeforeEach
3535
public void setUp() {
3636
super.setUp();
3737
fileDialog = new FileDialog(shell, SWT.NULL);
@@ -42,12 +42,7 @@ public void setUp() {
4242
public void test_ConstructorLorg_eclipse_swt_widgets_Shell() {
4343
// Test FileDialog(Shell)
4444
new FileDialog(shell);
45-
try {
46-
new FileDialog(null);
47-
fail("No exception thrown for parent == null");
48-
}
49-
catch (IllegalArgumentException e) {
50-
}
45+
assertThrows(IllegalArgumentException.class,()-> new FileDialog(null),"No exception thrown for parent == null");
5146
}
5247

5348
@Test
@@ -136,14 +131,14 @@ public void test_setFileNameLjava_lang_String() {
136131

137132
@Test
138133
public void test_setFilterPathLjava_lang_String() {
139-
assertEquals(":1:", "", fileDialog.getFilterPath());
134+
assertEquals("", fileDialog.getFilterPath());
140135
String testStr = "./*";
141136
fileDialog.setFilterPath(testStr);
142-
assertEquals(":2:", testStr, fileDialog.getFilterPath());
137+
assertEquals(testStr, fileDialog.getFilterPath());
143138
fileDialog.setFilterPath("");
144-
assertTrue(":3:", fileDialog.getFilterPath().isEmpty());
139+
assertTrue(fileDialog.getFilterPath().isEmpty());
145140
fileDialog.setFilterPath(null);
146-
assertNull(":4:", fileDialog.getFilterPath());
141+
assertNull(fileDialog.getFilterPath());
147142
}
148143
/* custom */
149144
FileDialog fileDialog;

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

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
*******************************************************************************/
1414
package org.eclipse.swt.tests.junit;
1515

16-
import static org.junit.Assert.assertArrayEquals;
17-
import static org.junit.Assert.assertEquals;
18-
import static org.junit.Assert.assertNull;
19-
import static org.junit.Assert.fail;
16+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertNull;
19+
import static org.junit.jupiter.api.Assertions.assertThrows;
2020

2121
import org.eclipse.swt.SWT;
2222
import org.eclipse.swt.graphics.FontData;
2323
import org.eclipse.swt.graphics.RGB;
2424
import org.eclipse.swt.widgets.FontDialog;
25-
import org.junit.Before;
26-
import org.junit.Test;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
2727

2828
/**
2929
* Automated Test Suite for class org.eclipse.swt.widgets.FontDialog
@@ -33,7 +33,7 @@
3333
public class Test_org_eclipse_swt_widgets_FontDialog extends Test_org_eclipse_swt_widgets_Dialog {
3434

3535
@Override
36-
@Before
36+
@BeforeEach
3737
public void setUp() {
3838
super.setUp();
3939
fontDialog = new FontDialog(shell, SWT.NULL);
@@ -43,22 +43,12 @@ public void setUp() {
4343
@Test
4444
public void test_ConstructorLorg_eclipse_swt_widgets_Shell() {
4545
new FontDialog(shell);
46-
try {
47-
new FontDialog(null);
48-
fail("No exception thrown for parent == null");
49-
}
50-
catch (IllegalArgumentException e) {
51-
}
46+
assertThrows(IllegalArgumentException.class,()-> new FontDialog(null),"No exception thrown for parent == null");
5247
}
5348

5449
@Test
5550
public void test_ConstructorLorg_eclipse_swt_widgets_ShellI() {
56-
try {
57-
new FontDialog(null, SWT.NULL);
58-
fail("No exception thrown for parent == null");
59-
}
60-
catch (IllegalArgumentException e) {
61-
}
51+
assertThrows(IllegalArgumentException.class,()-> new FontDialog(null, SWT.NULL),"No exception thrown for parent == null");
6252
}
6353

6454
@Test

0 commit comments

Comments
 (0)