1414 *******************************************************************************/
1515package org .eclipse .swt .tests .junit ;
1616
17-
18- import static org .junit .Assert .assertEquals ;
19- import static org .junit .Assert .assertFalse ;
20- import static org .junit .Assert .assertTrue ;
17+ import static org .junit .jupiter .api .Assertions .assertEquals ;
18+ import static org .junit .jupiter .api .Assertions .assertFalse ;
19+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
20+ import static org .junit .jupiter .api .Assertions .assertThrows ;
21+ import static org .junit .jupiter .api .Assertions .assertTrue ;
22+ import static org .junit .jupiter .api .Assumptions .assumeTrue ;
2123
2224import java .util .Arrays ;
2325import java .util .stream .Collectors ;
2931import org .eclipse .swt .graphics .Rectangle ;
3032import org .eclipse .swt .printing .Printer ;
3133import org .eclipse .swt .printing .PrinterData ;
32- import org .junit .Test ;
34+ import org .junit .jupiter . api . Test ;
3335
3436/**
3537 * Automated Test Suite for class org.eclipse.swt.printing.Printer
@@ -40,117 +42,87 @@ public class Test_org_eclipse_swt_printing_Printer {
4042
4143@ Test
4244public void test_Constructor () {
43- boolean exceptionThrown = false ;
44- String detail = "" ;
4545 if (Printer .getDefaultPrinterData () == null ) {
4646 /* There aren't any printers, so verify that the
4747 * constructor throws an ERROR_NO_HANDLES SWTError.
4848 */
49- try {
50- Printer printer = new Printer ();
51- printer .dispose ();
52- } catch (SWTError ex ) {
53- if (ex .code == SWT .ERROR_NO_HANDLES ) exceptionThrown = true ;
54- }
55- assertTrue ("ERROR_NO_HANDLES not thrown" , exceptionThrown );
49+ SWTError ex = assertThrows (SWTError .class , ()->new Printer ());
50+ assertEquals (SWT .ERROR_NO_HANDLES , ex .code , "ERROR_NO_HANDLES not thrown" );
5651 } else {
5752 /* There is at least a default printer, so verify that
5853 * the constructor does not throw any exceptions.
5954 */
60- try {
61- Printer printer = new Printer ();
62- printer .dispose ();
63- } catch (Throwable ex ) {
64- exceptionThrown = true ;
65- detail = ex .getMessage ();
66- }
67- assertFalse ("Exception thrown: " + detail , exceptionThrown );
55+ Printer printer = new Printer ();
56+ assertNotNull (printer );
57+ printer .dispose ();
6858 }
6959}
7060
7161@ Test
7262public void test_ConstructorLorg_eclipse_swt_printing_PrinterData () {
73- boolean exceptionThrown = false ;
74- String detail = "" ;
7563 PrinterData data = Printer .getDefaultPrinterData ();
7664 if (data == null ) {
7765 /* There aren't any printers, so verify that the
7866 * constructor throws an ERROR_NO_HANDLES SWTError.
7967 */
80- try {
81- Printer printer = new Printer (data );
82- printer .dispose ();
83- } catch (SWTError ex ) {
84- if (ex .code == SWT .ERROR_NO_HANDLES ) exceptionThrown = true ;
85- }
86- assertTrue ("ERROR_NO_HANDLES not thrown" , exceptionThrown );
68+ SWTError ex = assertThrows (SWTError .class , ()-> new Printer (data ));
69+ assertEquals (SWT .ERROR_NO_HANDLES , ex .code , "ERROR_NO_HANDLES not thrown" );
8770 } else {
8871 /* There is at least a default printer, so verify that
8972 * the constructor does not throw any exceptions.
9073 */
91- try {
92- Printer printer = new Printer (data );
93- printer .dispose ();
94- } catch (Throwable ex ) {
95- exceptionThrown = true ;
96- detail = ex .getMessage ();
97- }
98- assertFalse ("Exception thrown: " + detail , exceptionThrown );
74+ Printer printer = new Printer (data );
75+ assertNotNull (printer );
76+ printer .dispose ();
9977 }
10078}
10179
10280@ Test
10381public void test_computeTrimIIII () {
10482 PrinterData data = Printer .getDefaultPrinterData ();
105- // if there aren't any printers, don't do this test
106- if (data == null ) return ;
83+ assumeTrue (data != null , "if there aren't any printers, don't do this test" );
10784 Printer printer = new Printer (data );
10885 Rectangle trim = printer .computeTrim (0 , 0 , 10 , 10 );
109- assertTrue (" trim width or height is incorrect" , trim .width >= 10 && trim .height >= 10 );
86+ assertTrue (trim .width >= 10 && trim .height >= 10 , "trim width or height is incorrect" );
11087 printer .dispose ();
11188}
11289
11390@ Test
11491public void test_getBounds () {
11592 PrinterData data = Printer .getDefaultPrinterData ();
116- // if there aren't any printers, don't do this test
117- if (data == null ) return ;
93+ assumeTrue (data != null , "if there aren't any printers, don't do this test" );
11894 Printer printer = new Printer (data );
11995 Rectangle bounds = printer .getBounds ();
120- assertTrue (" bounds width or height is zero" , bounds .width > 0 && bounds .height > 0 );
96+ assertTrue (bounds .width > 0 && bounds .height > 0 , "bounds width or height is zero" );
12197 printer .dispose ();
12298}
12399
124100@ Test
125101public void test_getClientArea () {
126102 PrinterData data = Printer .getDefaultPrinterData ();
127- // if there aren't any printers, don't do this test
128- if (data == null ) return ;
103+ assumeTrue (data != null , "if there aren't any printers, don't do this test" );
129104 Printer printer = new Printer (data );
130105 Rectangle clientArea = printer .getClientArea ();
131- assertTrue (" clientArea width or height is zero" , clientArea .width > 0 && clientArea .height > 0 );
106+ assertTrue (clientArea .width > 0 && clientArea .height > 0 , "clientArea width or height is zero" );
132107 printer .dispose ();
133108}
134109
135110@ Test
136111public void test_getDPI () {
137112 PrinterData data = Printer .getDefaultPrinterData ();
138- // if there aren't any printers, don't do this test
139- if (data == null ) return ;
113+ assumeTrue (data != null , "if there aren't any printers, don't do this test" );
140114 Printer printer = new Printer (data );
141115 Point dpi = printer .getDPI ();
142- assertTrue (" dpi x or y is zero" , dpi .x > 0 && dpi .y > 0 );
116+ assertTrue (dpi .x > 0 && dpi .y > 0 , "dpi x or y is zero" );
143117 printer .dispose ();
144118}
145119
146120@ Test
147121public void test_getPrinterData () {
148122 PrinterData data = Printer .getDefaultPrinterData ();
149- // if there aren't any printers, don't do this test
150- if (data == null ) return ;
123+ assumeTrue (data != null , "if there aren't any printers, don't do this test" );
151124 Printer printer = new Printer (data );
152- assertTrue ("getPrinterData != data used in constructor" ,
153- data == printer .getPrinterData ());
125+ assertTrue (data == printer .getPrinterData (), "getPrinterData != data used in constructor" );
154126 printer .dispose ();
155127}
156128
@@ -191,26 +163,24 @@ public void test_getPrinterList() {
191163 });
192164 }
193165 PrinterData [] list = printerStream .toArray (PrinterData []::new );
194- String printerNames = Arrays .stream (list ).map (String ::valueOf ).collect (Collectors .joining (", " ));
195- assertEquals ("printer list contains items even though there are no printers, printers from list are: " +printerNames ,
196- 0 , list .length );
166+ String printerNames = Arrays .stream (list ).map (String ::valueOf ).collect (Collectors .joining (", " ));
167+ assertEquals (0 , list .length , "printer list contains items even though there are no printers, printers from list are: " +printerNames );
197168 } else {
198169 /* If there is at least a default printer, verify
199170 * that the printer list is not empty.
200171 */
201172 PrinterData list [] = Printer .getPrinterList ();
202- assertTrue ("printer list is empty" , list . length > 0 );
173+ assertTrue (list . length > 0 , "printer list is empty" );
203174 }
204175}
205176
206177@ Test
207178public void test_isAutoScalable () {
208179 PrinterData data = Printer .getDefaultPrinterData ();
209- // if there aren't any printers, don't do this test
210- if (data == null ) return ;
180+ assumeTrue (data != null , "if there aren't any printers, don't do this test" );
211181 Printer printer = new Printer (data );
212182 boolean isAutoScalable = printer .isAutoScalable ();
213- assertFalse ("SWT doesnot auto-scale for Printer devices" , isAutoScalable );
183+ assertFalse (isAutoScalable , "SWT doesnot auto-scale for Printer devices" );
214184 printer .dispose ();
215185}
216186}
0 commit comments