@@ -242,6 +242,25 @@ public void withValidApiKeyPreserveShouldReturnSource() throws Exception, Interr
242242 assertEquals ("png file" , request1 .getBody ().readUtf8 ());
243243 }
244244
245+ @ Test
246+ public void withValidApiKeyConvertShouldReturnSource () throws Exception , InterruptedException {
247+ Tinify .setKey ("valid" );
248+
249+ server .enqueue (new MockResponse ()
250+ .setResponseCode (201 )
251+ .addHeader ("Location" , "https://api.tinify.com/some/location" ));
252+
253+ server .enqueue (new MockResponse ()
254+ .setResponseCode (200 )
255+ .setBody ("copyrighted file" ));
256+
257+ assertThat (Source .fromBuffer ("png file" .getBytes ()).convert (new Options ().with ("type" , "image/webp" )),
258+ isA (Source .class ));
259+
260+ RecordedRequest request1 = server .takeRequest (3 , TimeUnit .SECONDS );
261+ assertEquals ("png file" , request1 .getBody ().readUtf8 ());
262+ }
263+
245264 @ Test
246265 public void withValidApiKeyPreserveShouldReturnSourceWithData () throws Exception , IOException , InterruptedException {
247266 Tinify .setKey ("valid" );
@@ -356,6 +375,30 @@ public void withValidApiKeyResizeShouldReturnSourceWithData() throws Exception,
356375 assertJsonEquals ("{\" resize\" :{\" width\" :100,\" height\" :60}}" , request2 .getBody ().readUtf8 ());
357376 }
358377
378+ @ Test
379+ public void withValidApiKeyTransformShouldReturnSourceWithData () throws Exception , IOException , InterruptedException {
380+ Tinify .setKey ("valid" );
381+
382+ server .enqueue (new MockResponse ()
383+ .setResponseCode (201 )
384+ .addHeader ("Location" , "https://api.tinify.com/some/location" ));
385+
386+ server .enqueue (new MockResponse ()
387+ .setResponseCode (200 )
388+ .setBody ("small file" ));
389+
390+ Options options = new Options ().with ("background" , "black" );
391+
392+ assertThat (Source .fromBuffer ("png file" .getBytes ()).transform (options ).toBuffer (),
393+ is (equalTo ("small file" .getBytes ())));
394+
395+ RecordedRequest request1 = server .takeRequest (3 , TimeUnit .SECONDS );
396+ assertEquals ("png file" , request1 .getBody ().readUtf8 ());
397+
398+ RecordedRequest request2 = server .takeRequest (3 , TimeUnit .SECONDS );
399+ assertJsonEquals ("{\" transform\" :{\" background\" :\" black\" }}" , request2 .getBody ().readUtf8 ());
400+ }
401+
359402 @ Test
360403 public void withValidApiKeyStoreShouldReturnResultMeta () throws Exception , InterruptedException {
361404 Tinify .setKey ("valid" );
0 commit comments