66import org .junit .jupiter .params .ParameterizedTest ;
77import org .junit .jupiter .params .provider .EnumSource ;
88
9- import static org .assertj .core .api .Assertions .assertThat ;
9+ import static net .datafaker .assertions .ImageAssertions .assertThatImage ;
10+ import static net .datafaker .providers .base .Image .ImageType .BMP ;
11+ import static net .datafaker .providers .base .Image .ImageType .GIF ;
12+ import static net .datafaker .providers .base .Image .ImageType .JPEG ;
13+ import static net .datafaker .providers .base .Image .ImageType .PNG ;
14+ import static net .datafaker .providers .base .Image .ImageType .SVG ;
15+ import static net .datafaker .providers .base .Image .ImageType .TIFF ;
16+ import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
1017import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
1118
1219class ImageTest {
1320 private final Faker faker = new Faker ();
1421
1522 @ Test
1623 void bmp () {
17- assertThat (faker .image ().base64BMP ()).startsWith ( "data:image/bmp;base64," );
24+ assertThatImage (faker .image ().base64BMP ()).is ( BMP , 256 , 256 );
1825 }
1926
2027 @ Test
2128 void gif () {
22- assertThat (faker .image ().base64GIF ()).startsWith ( "data:image/gif;base64," );
29+ assertThatImage (faker .image ().base64GIF ()).is ( GIF , 256 , 256 );
2330 }
2431
2532 @ Test
2633 void png () {
27- assertThat (faker .image ().base64PNG ()).startsWith ( "data:image/png;base64," );
34+ assertThatImage (faker .image ().base64PNG ()).is ( PNG , 256 , 256 );
2835 }
2936
3037 @ Test
3138 void jpg () {
32- assertThat (faker .image ().base64JPG ()).startsWith ( "data:image/jpeg;base64," );
39+ assertThatImage (faker .image ().base64JPG ()).is ( JPEG , 256 , 256 );
3340 }
3441
3542 @ Test
3643 void jpeg () {
37- assertThat (faker .image ().base64JPEG ()).startsWith ( "data:image/jpeg;base64," );
44+ assertThatImage (faker .image ().base64JPEG ()).is ( JPEG , 256 , 256 );
3845 }
3946
4047 @ Test
4148 void svg () {
42- assertThat (faker .image ().base64SVG ()).startsWith ( "data:image/svg+xml;base64," );
49+ assertThatImage (faker .image ().base64SVG ()).is ( SVG , 256 , 256 );
4350 }
4451
4552 @ Test
4653 void tiff () {
47- assertThat (faker .image ().base64TIFF ()).startsWith ( "data:image/tiff;base64," );
54+ assertThatImage (faker .image ().base64TIFF ()).is ( TIFF , 256 , 256 );
4855 }
4956
5057 @ ParameterizedTest
5158 @ EnumSource (ImageType .class )
5259 void base64 (ImageType imageType ) {
5360 String base64Image = faker .image ().base64 (new Image .Base64ImageRuleConfig (imageType , 1000 , 1000 ));
5461
55- assertThat (base64Image )
56- .startsWith ("data:" + imageType .getMimeType () + ";base64," );
57- assertThat (base64Image .substring (base64Image .indexOf ("," ) + 1 ))
58- .isNotBlank ()
59- .isBase64 ();
62+ assertThatImage (base64Image ).is (imageType , 1000 , 1000 );
6063 }
6164
6265 @ Test
63- void defaultBuilder () {
64- String image = faker .image ().base64 (Image .ImageBuilder .builder ()
65- .build ());
66- assertThat (image ).startsWith ("data:image/" );
66+ void defaultBuilder_generatesPngImage () {
67+ String image = faker .image ().base64 (Image .ImageBuilder .builder ().build ());
68+ assertThatImage (image ).is (PNG , 256 , 256 );
6769 }
6870
6971 @ Test
7072 void customBase64builder () {
7173 String gif = faker .image ().base64 (Image .ImageBuilder .builder ()
7274 .type (ImageType .GIF )
7375 .build ());
74- assertThat (gif ).startsWith ( "data:image/gif;base64," );
76+ assertThatImage (gif ).is ( GIF , 256 , 256 );
7577 }
7678
7779 @ Test
7880 void tinyBase64builder () {
7981 String tiny = faker .image ().base64 (Image .ImageBuilder .builder ()
8082 .height (1 )
8183 .width (1 )
82- .type (ImageType . PNG )
84+ .type (PNG )
8385 .build ());
8486
85- assertThat (tiny ).startsWith ( "data:image/png;base64," );
87+ assertThatImage (tiny ).is ( PNG , 1 , 1 );
8688 }
8789
8890 @ Test
@@ -92,12 +94,12 @@ void largeBase64builder() {
9294 .width (2000 )
9395 .type (ImageType .BMP )
9496 .build ());
95- assertThat (large ).startsWith ( "data:image/bmp;base64," );
97+ assertThatImage (large ).is ( BMP , 2000 , 1000 );
9698 }
9799
98100 @ Test
99101 void shouldErrorOnIllegalType () {
100- assertThatIllegalArgumentException ( ).isThrownBy (() -> Image .ImageBuilder .builder ().type (null ).build ());
102+ assertThatExceptionOfType ( NullPointerException . class ).isThrownBy (() -> Image .ImageBuilder .builder ().type (null ).build ());
101103 }
102104
103105 @ Test
0 commit comments