14
14
*******************************************************************************/
15
15
package org .eclipse .swt .tests .junit ;
16
16
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 ;
21
23
22
24
import java .util .Arrays ;
23
25
import java .util .stream .Collectors ;
29
31
import org .eclipse .swt .graphics .Rectangle ;
30
32
import org .eclipse .swt .printing .Printer ;
31
33
import org .eclipse .swt .printing .PrinterData ;
32
- import org .junit .Test ;
34
+ import org .junit .jupiter . api . Test ;
33
35
34
36
/**
35
37
* Automated Test Suite for class org.eclipse.swt.printing.Printer
@@ -40,117 +42,87 @@ public class Test_org_eclipse_swt_printing_Printer {
40
42
41
43
@ Test
42
44
public void test_Constructor () {
43
- boolean exceptionThrown = false ;
44
- String detail = "" ;
45
45
if (Printer .getDefaultPrinterData () == null ) {
46
46
/* There aren't any printers, so verify that the
47
47
* constructor throws an ERROR_NO_HANDLES SWTError.
48
48
*/
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" );
56
51
} else {
57
52
/* There is at least a default printer, so verify that
58
53
* the constructor does not throw any exceptions.
59
54
*/
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 ();
68
58
}
69
59
}
70
60
71
61
@ Test
72
62
public void test_ConstructorLorg_eclipse_swt_printing_PrinterData () {
73
- boolean exceptionThrown = false ;
74
- String detail = "" ;
75
63
PrinterData data = Printer .getDefaultPrinterData ();
76
64
if (data == null ) {
77
65
/* There aren't any printers, so verify that the
78
66
* constructor throws an ERROR_NO_HANDLES SWTError.
79
67
*/
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" );
87
70
} else {
88
71
/* There is at least a default printer, so verify that
89
72
* the constructor does not throw any exceptions.
90
73
*/
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 ();
99
77
}
100
78
}
101
79
102
80
@ Test
103
81
public void test_computeTrimIIII () {
104
82
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" );
107
84
Printer printer = new Printer (data );
108
85
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" );
110
87
printer .dispose ();
111
88
}
112
89
113
90
@ Test
114
91
public void test_getBounds () {
115
92
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" );
118
94
Printer printer = new Printer (data );
119
95
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" );
121
97
printer .dispose ();
122
98
}
123
99
124
100
@ Test
125
101
public void test_getClientArea () {
126
102
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" );
129
104
Printer printer = new Printer (data );
130
105
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" );
132
107
printer .dispose ();
133
108
}
134
109
135
110
@ Test
136
111
public void test_getDPI () {
137
112
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" );
140
114
Printer printer = new Printer (data );
141
115
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" );
143
117
printer .dispose ();
144
118
}
145
119
146
120
@ Test
147
121
public void test_getPrinterData () {
148
122
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" );
151
124
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" );
154
126
printer .dispose ();
155
127
}
156
128
@@ -191,26 +163,24 @@ public void test_getPrinterList() {
191
163
});
192
164
}
193
165
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 );
197
168
} else {
198
169
/* If there is at least a default printer, verify
199
170
* that the printer list is not empty.
200
171
*/
201
172
PrinterData list [] = Printer .getPrinterList ();
202
- assertTrue ("printer list is empty" , list . length > 0 );
173
+ assertTrue (list . length > 0 , "printer list is empty" );
203
174
}
204
175
}
205
176
206
177
@ Test
207
178
public void test_isAutoScalable () {
208
179
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" );
211
181
Printer printer = new Printer (data );
212
182
boolean isAutoScalable = printer .isAutoScalable ();
213
- assertFalse ("SWT doesnot auto-scale for Printer devices" , isAutoScalable );
183
+ assertFalse (isAutoScalable , "SWT doesnot auto-scale for Printer devices" );
214
184
printer .dispose ();
215
185
}
216
186
}
0 commit comments