18
18
import static org .hamcrest .MatcherAssert .assertThat ;
19
19
import static org .hamcrest .Matchers .is ;
20
20
import static org .hamcrest .Matchers .not ;
21
- import static org .junit .Assert .assertArrayEquals ;
22
- import static org .junit .Assert .assertEquals ;
23
- import static org .junit .Assert .assertFalse ;
24
- import static org .junit .Assert .assertNotEquals ;
25
- import static org .junit .Assert .assertNotNull ;
26
- import static org .junit .Assert .assertNull ;
27
- import static org .junit .Assert .assertTrue ;
28
- import static org .junit .Assert .fail ;
21
+ import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
22
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
23
+ import static org .junit .jupiter .api .Assertions .assertFalse ;
24
+ import static org .junit .jupiter .api .Assertions .assertNotEquals ;
25
+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
26
+ import static org .junit .jupiter .api .Assertions .assertNull ;
27
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
28
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
29
+ import static org .junit .jupiter .api .Assumptions .assumeFalse ;
29
30
import static org .junit .jupiter .api .Assumptions .assumeTrue ;
30
31
31
32
import java .util .concurrent .atomic .AtomicReference ;
48
49
import org .eclipse .swt .widgets .Canvas ;
49
50
import org .eclipse .swt .widgets .Display ;
50
51
import org .eclipse .swt .widgets .Shell ;
51
- import org .junit .After ;
52
- import org .junit .Assume ;
53
- import org .junit .Before ;
54
- import org .junit .Test ;
52
+ import org .junit .jupiter .api .AfterEach ;
53
+ import org .junit .jupiter .api .BeforeEach ;
54
+ import org .junit .jupiter .api .Test ;
55
55
56
56
/**
57
57
* Automated Test Suite for class org.eclipse.swt.graphics.GC
61
61
@ SuppressWarnings ("restriction" )
62
62
public class Test_org_eclipse_swt_graphics_GC {
63
63
64
- @ Before
64
+ @ BeforeEach
65
65
public void setUp () {
66
66
display = Display .getDefault ();
67
67
shell = new Shell (display );
@@ -70,7 +70,7 @@ public void setUp() {
70
70
gc = new GC (image );
71
71
}
72
72
73
- @ After
73
+ @ AfterEach
74
74
public void tearDown () {
75
75
gc .dispose ();
76
76
image .dispose ();
@@ -79,54 +79,52 @@ public void tearDown() {
79
79
80
80
@ Test
81
81
public void test_ConstructorLorg_eclipse_swt_graphics_Drawable () {
82
- try {
83
- GC gc = new GC (null );
84
- gc .dispose ();
85
- fail ("No exception thrown for drawable == null" );
86
- } catch (IllegalArgumentException e ) {
87
- assertSWTProblem ("Incorrect exception thrown for drawable == null" , SWT .ERROR_NULL_ARGUMENT , e );
88
- }
82
+ IllegalArgumentException e = assertThrows (IllegalArgumentException .class , () -> new GC (null ),
83
+ "No exception thrown for drawable == null" );
84
+ assertSWTProblem ("Incorrect exception thrown for drawable == null" , SWT .ERROR_NULL_ARGUMENT , e );
89
85
90
- Image image = null ;
91
- GC gc1 = null , gc2 = null ;
92
- try {
93
- image = new Image (display , 10 , 10 );
94
- gc1 = new GC (image );
95
- gc2 = new GC (image );
96
- fail ("No exception thrown for more than one GC on one image" );
97
- } catch (IllegalArgumentException e ) {
98
- assertSWTProblem ("Incorrect exception thrown for more than one GC on one image" , SWT .ERROR_INVALID_ARGUMENT , e );
99
- } finally {
100
- if (image != null ) image .dispose ();
101
- if (gc1 != null ) gc1 .dispose ();
102
- if (gc2 != null ) gc2 .dispose ();
103
- }
86
+ IllegalArgumentException e1 = assertThrows (IllegalArgumentException .class , () -> {
87
+ Image image = null ;
88
+ GC gc1 = null , gc2 = null ;
89
+ try {
90
+ image = new Image (display , 10 , 10 );
91
+ gc1 = new GC (image );
92
+ gc2 = new GC (image );
93
+ } finally {
94
+ if (image != null )
95
+ image .dispose ();
96
+ if (gc1 != null )
97
+ gc1 .dispose ();
98
+ if (gc2 != null )
99
+ gc2 .dispose ();
100
+ }
101
+ }, "No exception thrown for more than one GC on one image" );
102
+ assertSWTProblem ("Incorrect exception thrown for more than one GC on one image" , SWT .ERROR_INVALID_ARGUMENT , e1 );
104
103
}
105
104
106
105
@ Test
107
106
public void test_ConstructorLorg_eclipse_swt_graphics_DrawableI () {
108
- try {
109
- GC gc = new GC (null , SWT .LEFT_TO_RIGHT );
110
- gc .dispose ();
111
- fail ("No exception thrown for drawable == null" );
112
- } catch (IllegalArgumentException e ) {
113
- assertSWTProblem ("Incorrect exception thrown for drawable == null" , SWT .ERROR_NULL_ARGUMENT , e );
114
- }
107
+ IllegalArgumentException e = assertThrows (IllegalArgumentException .class , () -> new GC (null , SWT .LEFT_TO_RIGHT ),
108
+ "No exception thrown for drawable == null" );
109
+ assertSWTProblem ("Incorrect exception thrown for drawable == null" , SWT .ERROR_NULL_ARGUMENT , e );
115
110
116
- Image image = null ;
117
- GC gc1 = null , gc2 = null ;
118
- try {
119
- image = new Image (display , 10 , 10 );
120
- gc1 = new GC (image , SWT .RIGHT_TO_LEFT );
121
- gc2 = new GC (image , SWT .LEFT_TO_RIGHT );
122
- fail ("No exception thrown for more than one GC on one image" );
123
- } catch (IllegalArgumentException e ) {
124
- assertSWTProblem ("Incorrect exception thrown for more than one GC on one image" , SWT .ERROR_INVALID_ARGUMENT , e );
125
- } finally {
126
- if (image != null ) image .dispose ();
127
- if (gc1 != null ) gc1 .dispose ();
128
- if (gc2 != null ) gc2 .dispose ();
129
- }
111
+ IllegalArgumentException e1 = assertThrows (IllegalArgumentException .class , () -> {
112
+ Image image = null ;
113
+ GC gc1 = null , gc2 = null ;
114
+ try {
115
+ image = new Image (display , 10 , 10 );
116
+ new GC (image , SWT .RIGHT_TO_LEFT );
117
+ new GC (image , SWT .LEFT_TO_RIGHT );
118
+ } finally {
119
+ if (image != null )
120
+ image .dispose ();
121
+ if (gc1 != null )
122
+ gc1 .dispose ();
123
+ if (gc2 != null )
124
+ gc2 .dispose ();
125
+ }
126
+ }, "No exception thrown for more than one GC on one image" );
127
+ assertSWTProblem ("Incorrect exception thrown for more than one GC on one image" , SWT .ERROR_INVALID_ARGUMENT , e1 );
130
128
131
129
Canvas canvas = new Canvas (shell , SWT .NULL );
132
130
GC testGC = new GC (canvas , SWT .RIGHT_TO_LEFT );
@@ -138,6 +136,10 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DrawableI() {
138
136
139
137
@ Test
140
138
public void test_copyAreaIIIIII () {
139
+ // This test verifies pixel-level color values after a copyArea() operation.
140
+ // Such pixel-accurate checks are only reliable at 100% zoom due to fractional scaling.
141
+ assumeTrue (DPIUtil .getDeviceZoom () == 100 , "Skipping test due to non-100% zoom" );
142
+
141
143
Color white = display .getSystemColor (SWT .COLOR_WHITE );
142
144
Color blue = display .getSystemColor (SWT .COLOR_BLUE );
143
145
RGB whiteRGB = getRealRGB (white );
@@ -156,22 +158,22 @@ public void test_copyAreaIIIIII() {
156
158
ImageData imageData = image .getImageData ();
157
159
PaletteData palette = imageData .palette ;
158
160
159
- // This test verifies pixel-level color values after a copyArea() operation.
160
- // Such pixel-accurate checks are only reliable at 100% zoom due to fractional scaling.
161
- assumeTrue (DPIUtil .getDeviceZoom () == 100 , "Skipping test due to non-100% zoom" );
162
-
163
161
int pixel = imageData .getPixel (destX + 4 , destY );
164
- assertEquals (":a:" , whiteRGB , palette .getRGB (pixel ));
162
+ assertEquals (whiteRGB , palette .getRGB (pixel ));
165
163
pixel = imageData .getPixel (destX + 6 , destY );
166
- assertEquals (":b:" , blueRGB , palette .getRGB (pixel ));
164
+ assertEquals (blueRGB , palette .getRGB (pixel ));
167
165
pixel = imageData .getPixel (destX + 10 , destY );
168
- assertEquals (":c:" , blueRGB , palette .getRGB (pixel ));
166
+ assertEquals (blueRGB , palette .getRGB (pixel ));
169
167
pixel = imageData .getPixel (destX + 12 , destY );
170
- assertEquals (":d:" , whiteRGB , palette .getRGB (pixel ));
168
+ assertEquals (whiteRGB , palette .getRGB (pixel ));
171
169
}
172
170
173
171
@ Test
174
172
public void test_copyAreaIIIIII_overlapingSourceTarget () {
173
+ // This test verifies pixel-level color values after a copyArea() operation.
174
+ // Such pixel-accurate checks are only reliable at 100% zoom due to fractional scaling.
175
+ assumeTrue (DPIUtil .getDeviceZoom () == 100 , "Skipping test due to non-100% zoom" );
176
+
175
177
Color red = display .getSystemColor (SWT .COLOR_RED );
176
178
Color blue = display .getSystemColor (SWT .COLOR_BLUE );
177
179
RGB redRGB = getRealRGB (red );
@@ -197,10 +199,6 @@ public void test_copyAreaIIIIII_overlapingSourceTarget() {
197
199
imageData = image .getImageData ();
198
200
palette = imageData .palette ;
199
201
200
- // This test verifies pixel-level color values after a copyArea() operation.
201
- // Such pixel-accurate checks are only reliable at 100% zoom due to fractional scaling.
202
- assumeTrue (DPIUtil .getDeviceZoom () == 100 , "Skipping test due to non-100% zoom" );
203
-
204
202
pixel = imageData .getPixel (0 , 105 );
205
203
assertEquals (redRGB , palette .getRGB (pixel ));
206
204
pixel = imageData .getPixel (0 , 145 );
@@ -214,6 +212,10 @@ public void test_copyAreaIIIIII_overlapingSourceTarget() {
214
212
215
213
@ Test
216
214
public void test_copyAreaLorg_eclipse_swt_graphics_ImageII () {
215
+ // This test verifies pixel-level color values after a copyArea() operation.
216
+ // Such pixel-accurate checks are only reliable at 100% zoom due to fractional scaling.
217
+ assumeTrue (DPIUtil .getDeviceZoom () == 100 , "Skipping test due to non-100% zoom" );
218
+
217
219
Color white = display .getSystemColor (SWT .COLOR_WHITE );
218
220
Color blue = display .getSystemColor (SWT .COLOR_BLUE );
219
221
RGB whiteRGB = getRealRGB (white );
@@ -228,18 +230,14 @@ public void test_copyAreaLorg_eclipse_swt_graphics_ImageII() {
228
230
ImageData imageData = image .getImageData ();
229
231
PaletteData palette = imageData .palette ;
230
232
231
- // This test verifies pixel-level color values after a copyArea() operation.
232
- // Such pixel-accurate checks are only reliable at 100% zoom due to fractional scaling.
233
- assumeTrue (DPIUtil .getDeviceZoom () == 100 , "Skipping test due to non-100% zoom" );
234
-
235
233
int pixel = imageData .getPixel (4 , 0 );
236
- assertEquals (":a:" , whiteRGB , palette .getRGB (pixel ));
234
+ assertEquals (whiteRGB , palette .getRGB (pixel ));
237
235
pixel = imageData .getPixel (5 , 0 );
238
- assertEquals (":b:" , blueRGB , palette .getRGB (pixel ));
236
+ assertEquals (blueRGB , palette .getRGB (pixel ));
239
237
pixel = imageData .getPixel (10 , 0 );
240
- assertEquals (":c:" , blueRGB , palette .getRGB (pixel ));
238
+ assertEquals (blueRGB , palette .getRGB (pixel ));
241
239
pixel = imageData .getPixel (11 , 0 );
242
- assertEquals (":d:" , whiteRGB , palette .getRGB (pixel ));
240
+ assertEquals (whiteRGB , palette .getRGB (pixel ));
243
241
image .dispose ();
244
242
}
245
243
@@ -288,12 +286,7 @@ public void test_drawImageLorg_eclipse_swt_graphics_ImageII() {
288
286
gc .drawImage (image , 100 , 100 );
289
287
gc .drawImage (imageTransparent , 130 , 100 );
290
288
gc .drawImage (imageAlpha , 160 , 100 );
291
- try {
292
- gc .drawImage (null , 100 , 100 );
293
- fail ("No exception thrown" );
294
- }
295
- catch (IllegalArgumentException e ) {
296
- }
289
+ assertThrows (IllegalArgumentException .class , () -> gc .drawImage (null , 100 , 100 ));
297
290
image .dispose ();
298
291
imageTransparent .dispose ();
299
292
imageAlpha .dispose ();
@@ -329,12 +322,7 @@ public void test_drawImageLorg_eclipse_swt_graphics_ImageIIIIIIII() {
329
322
gc .drawImage (image , 10 , 5 , 20 , 15 , 100 , 120 , 50 , 60 );
330
323
gc .drawImage (imageTransparent , 10 , 5 , 20 , 15 , 100 , 120 , 10 , 10 );
331
324
gc .drawImage (imageAlpha , 10 , 5 , 20 , 15 , 100 , 120 , 20 , 15 );
332
- try {
333
- gc .drawImage (null , 10 , 5 , 20 , 15 , 100 , 120 , 50 , 60 );
334
- fail ("No exception thrown" ); //should never get here
335
- }
336
- catch (IllegalArgumentException e ) {
337
- }
325
+ assertThrows (IllegalArgumentException .class , () -> gc .drawImage (null , 10 , 5 , 20 , 15 , 100 , 120 , 50 , 60 ));
338
326
image .dispose ();
339
327
imageAlpha .dispose ();
340
328
imageTransparent .dispose ();
@@ -551,18 +539,11 @@ public void test_setBackgroundLorg_eclipse_swt_graphics_Color() {
551
539
Color color = new Color (255 , 0 , 0 );
552
540
gc .setBackground (color );
553
541
assertEquals (color , gc .getBackground ());
554
- try {
555
- gc .setBackground (null );
556
- fail ("No exception thrown for null color" );
557
- } catch (IllegalArgumentException e ) {
558
- }
542
+ assertThrows (IllegalArgumentException .class , () -> gc .setBackground (null ), "No exception thrown for null color" );
559
543
assertEquals (gc .getBackground (),gc .getBackground ());
560
544
color .dispose ();
561
- try {
562
- gc .setBackground (color );
563
- fail ("No exception thrown for color disposed" );
564
- } catch (IllegalArgumentException e ) {
565
- }
545
+ assertThrows (IllegalArgumentException .class , () -> gc .setBackground (color ),
546
+ "No exception thrown for color disposed" );
566
547
}
567
548
568
549
@ Test
@@ -618,18 +599,11 @@ public void test_setForegroundLorg_eclipse_swt_graphics_Color() {
618
599
Color color = new Color (255 , 0 , 0 );
619
600
gc .setForeground (color );
620
601
assertEquals (color , gc .getForeground ());
621
- try {
622
- gc .setForeground (null );
623
- fail ("No exception thrown for null color" );
624
- } catch (IllegalArgumentException e ) {
625
- }
626
- assertEquals (gc .getForeground (),gc .getForeground ());
602
+ assertThrows (IllegalArgumentException .class , () -> gc .setForeground (null ), "No exception thrown for null color" );
603
+ assertEquals (gc .getForeground (), gc .getForeground ());
627
604
color .dispose ();
628
- try {
629
- gc .setForeground (color );
630
- fail ("No exception thrown for color disposed" );
631
- } catch (IllegalArgumentException e ) {
632
- }
605
+ assertThrows (IllegalArgumentException .class , () -> gc .setForeground (color ),
606
+ "No exception thrown for color disposed" );
633
607
}
634
608
635
609
@ Test
@@ -643,13 +617,12 @@ public void test_setForegroundLorg_eclipse_swt_graphics_Color() {
643
617
float miterLimit = 2.6f ;
644
618
LineAttributes passedLineAttributes = new LineAttributes (width , cap , join , style , dashes , dashOffset , miterLimit );
645
619
gc .setLineAttributes (passedLineAttributes );
646
- assertEquals ("unexpected line width" , width , gc .getLineWidth ());
647
- assertEquals ("unexpected line cap" , cap , gc .getLineCap ());
648
- assertEquals ("unexpected line join" , join , gc .getLineJoin ());
649
- assertEquals ("unexpected line style" , style , gc .getLineStyle ());
650
- assertEquals ("actual line attributes differ from the ones that have been set" ,
651
- new LineAttributes (width , cap , join , style , dashes , dashOffset , miterLimit ), gc .getLineAttributes ());
652
- assertEquals ("setter call changed line width" , width , passedLineAttributes .width , 0.0f );
620
+ assertEquals (width , gc .getLineWidth (), "unexpected line width" );
621
+ assertEquals (cap , gc .getLineCap (), "unexpected line cap" );
622
+ assertEquals (join , gc .getLineJoin (), "unexpected line join" );
623
+ assertEquals (style , gc .getLineStyle (), "unexpected line style" );
624
+ assertEquals (new LineAttributes (width , cap , join , style , dashes , dashOffset , miterLimit ), gc .getLineAttributes (), "actual line attributes differ from the ones that have been set" );
625
+ assertEquals (width , passedLineAttributes .width , 0.0f , "setter call changed line width" );
653
626
654
627
gc .setLineAttributes (new LineAttributes (1 ));
655
628
assertEquals (new LineAttributes (1 ), gc .getLineAttributes ());
@@ -684,12 +657,12 @@ public void test_setLineWidthI() {
684
657
685
658
@ Test
686
659
public void test_setLineWidthI_withDeviceScaling () {
687
- executeWithNonDefaultDeviceZoom (() -> test_setLineWidthI () );
660
+ executeWithNonDefaultDeviceZoom (this :: test_setLineWidthI );
688
661
}
689
662
690
663
@ Test
691
664
public void test_setLineDash$I () {
692
- int [] dashes = new int [] { 5 , 1 , 3 };
665
+ int [] dashes = { 5 , 1 , 3 };
693
666
gc .setLineDash (dashes );
694
667
assertArrayEquals (dashes , gc .getLineDash ());
695
668
gc .setLineDash (null );
@@ -698,7 +671,7 @@ public void test_setLineWidthI_withDeviceScaling() {
698
671
699
672
@ Test
700
673
public void test_setLineDash$I_withDeviceScaling () {
701
- executeWithNonDefaultDeviceZoom (() -> test_setLineDash$I () );
674
+ executeWithNonDefaultDeviceZoom (this :: test_setLineDash$I );
702
675
}
703
676
704
677
@ Test
@@ -739,7 +712,7 @@ public void test_toString() {
739
712
740
713
@ Test
741
714
public void test_bug493455_drawImageAlpha_srcPos () {
742
- Assume . assumeFalse ("https://github.com/eclipse-platform/eclipse.platform.swt/issues/40 causes test to fail on Mac" , SwtTestUtil . isCocoa );
715
+ assumeFalse (SwtTestUtil . isCocoa , "https://github.com/eclipse-platform/eclipse.platform.swt/issues/40 causes test to fail on Mac" );
743
716
RGB red = new RGB (255 , 0 , 0 );
744
717
RGB green = new RGB (0 , 255 , 0 );
745
718
@@ -828,7 +801,7 @@ public void test_bug1288_createGCFromImageFromNonDisplayThread() throws Interrup
828
801
});
829
802
thread .start ();
830
803
thread .join ();
831
- assertNull ("Creating a GC from an Image without a device threw an exception" , exceptionReference . get () );
804
+ assertNull (exceptionReference . get (), "Creating a GC from an Image without a device threw an exception" );
832
805
}
833
806
834
807
/* custom */
0 commit comments