11package com .cloudinary .test ;
22
3- import java .io .UnsupportedEncodingException ;
4- import java .net .URI ;
5- import java .net .URLDecoder ;
6- import java .util .*;
7- import java .util .regex .Matcher ;
8- import java .util .regex .Pattern ;
9-
3+ import com .cloudinary .Cloudinary ;
104import com .cloudinary .ResponsiveBreakpoint ;
11- import org .cloudinary .json .JSONArray ;
5+ import com .cloudinary .Transformation ;
6+ import com .cloudinary .transformation .*;
7+ import com .cloudinary .utils .ObjectUtils ;
8+ import junitparams .JUnitParamsRunner ;
9+ import junitparams .Parameters ;
10+ import junitparams .naming .TestCaseName ;
1211import org .cloudinary .json .JSONObject ;
1312import org .junit .Before ;
1413import org .junit .Rule ;
1514import org .junit .Test ;
1615import org .junit .rules .TestName ;
16+ import org .junit .runner .RunWith ;
1717
18- import com .cloudinary .Cloudinary ;
19- import com .cloudinary .Transformation ;
20- import com .cloudinary .transformation .*;
21- import com .cloudinary .utils .ObjectUtils ;
18+ import java .io .UnsupportedEncodingException ;
19+ import java .net .URI ;
20+ import java .net .URLDecoder ;
21+ import java .util .Arrays ;
22+ import java .util .HashMap ;
23+ import java .util .Map ;
24+ import java .util .regex .Matcher ;
25+ import java .util .regex .Pattern ;
2226
2327import static org .junit .Assert .*;
2428
29+ @ RunWith (JUnitParamsRunner .class )
2530public class CloudinaryTest {
2631 private static final String DEFAULT_ROOT_PATH = "http://res.cloudinary.com/test123/" ;
2732 private static final String DEFAULT_UPLOAD_PATH = DEFAULT_ROOT_PATH + "image/upload/" ;
@@ -257,8 +262,8 @@ public void testCrop() {
257262 Transformation transformation = new Transformation ().width (100 ).height (101 );
258263 String result = cloudinary .url ().transformation (transformation ).generate ("test" );
259264 assertEquals (DEFAULT_UPLOAD_PATH + "h_101,w_100/test" , result );
260- assertEquals ("101" , transformation .getHtmlHeight (). toString () );
261- assertEquals ("100" , transformation .getHtmlWidth (). toString () );
265+ assertEquals ("101" , transformation .getHtmlHeight ());
266+ assertEquals ("100" , transformation .getHtmlWidth ());
262267 transformation = new Transformation ().width (100 ).height (101 ).crop ("crop" );
263268 result = cloudinary .url ().transformation (transformation ).generate ("test" );
264269 assertEquals (DEFAULT_UPLOAD_PATH + "c_crop,h_101,w_100/test" , result );
@@ -273,18 +278,21 @@ public void testVariousOptions() {
273278 }
274279
275280 @ Test
276- public void testQuality () {
277- // should use x, y, radius, prefix, gravity and quality from options
278- Transformation transformation = new Transformation ().quality (0.4 );
279- String result = cloudinary .url ().transformation (transformation ).generate ("test" );
280- assertEquals (DEFAULT_UPLOAD_PATH + "q_0.4/test" , result );
281- transformation = new Transformation ().quality ("auto" );
282- result = cloudinary .url ().transformation (transformation ).generate ("test" );
283- assertEquals (DEFAULT_UPLOAD_PATH + "q_auto/test" , result );
284- transformation = new Transformation ().quality ("auto:good" );
285- result = cloudinary .url ().transformation (transformation ).generate ("test" );
286- assertEquals (DEFAULT_UPLOAD_PATH + "q_auto:good/test" , result );
281+ @ TestCaseName ("{method}: {params}" )
282+ @ Parameters
283+ public void testQuality ( Object quality , String result ) {
284+ Transformation transformation = new Transformation ().quality (quality );
285+ assertEquals (result , transformation .generate ());
287286 }
287+ private Object parametersForTestQuality () {
288+ Object [][] q = {
289+ {0.4 , "q_0.4" },
290+ {"0.4" , "q_0.4" },
291+ {"auto" , "q_auto" },
292+ {"auto:good" , "q_auto:good" }};
293+ return q ;
294+
295+ };
288296
289297 @ Test
290298 public void testTransformationSimple () {
@@ -610,23 +618,21 @@ public void testResponsiveWidth() {
610618 assertEquals (DEFAULT_UPLOAD_PATH + "c_crop,h_100,w_100/c_pad,w_auto/test" , result );
611619 Transformation .setResponsiveWidthTransformation (null );
612620 }
621+
622+ @ Parameters ({
623+ "auto:20|c_fill\\ ,w_auto:20" ,
624+ "auto:20:350|c_fill\\ ,w_auto:20:350" ,
625+ "auto:breakpoints|c_fill\\ ,w_auto:breakpoints" ,
626+ "auto:breakpoints_100_1900_20_15|c_fill\\ ,w_auto:breakpoints_100_1900_20_15" ,
627+ "auto:breakpoints:json|c_fill\\ ,w_auto:breakpoints:json" })
628+ @ TestCaseName ("Width {0}: {1}" )
613629 @ Test
614- public void testShouldSupportAutoWidth (){
630+ public void testShouldSupportAutoWidth (String width , String result ){
615631 String trans ;
616-
617- trans = new Transformation ().width ("auto:20" ).crop ("fill" ).generate ();
618- assertEquals ("c_fill,w_auto:20" , trans );
619- trans = new Transformation ().width ("auto:20:350" ).crop ("fill" ).generate ();
620- assertEquals ("c_fill,w_auto:20:350" , trans );
621- trans = new Transformation ().width ("auto:breakpoints" ).crop ("fill" ).generate ();
622- assertEquals ("c_fill,w_auto:breakpoints" , trans );
623- trans = new Transformation ().width ("auto:breakpoints_100_1900_20_15" ).crop ("fill" ).generate ();
624- assertEquals ("c_fill,w_auto:breakpoints_100_1900_20_15" , trans );
625- trans = new Transformation ().width ("auto:breakpoints:json" ).crop ("fill" ).generate ();
626- assertEquals ("c_fill,w_auto:breakpoints:json" , trans );
632+ trans = new Transformation ().width (width ).crop ("fill" ).generate ();
633+ assertEquals (result , trans );
627634 }
628635
629-
630636 @ Test
631637 public void testShouldSupportOhOw (){
632638 String trans = new Transformation ().width ("ow" ).height ("oh" ).crop ("crop" ).generate ();
0 commit comments