Skip to content

Commit 4fa896e

Browse files
author
Amir Tocker
committed
Add static import of asMap and emptyMap. Suppress deprecation warnings for backward compatibility tests.
1 parent bab5ad3 commit 4fa896e

File tree

1 file changed

+41
-69
lines changed

1 file changed

+41
-69
lines changed

cloudinary-core/src/test/java/com/cloudinary/test/CloudinaryTest.java

Lines changed: 41 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.regex.Matcher;
2525
import java.util.regex.Pattern;
2626

27+
import static com.cloudinary.utils.ObjectUtils.asMap;
28+
import static com.cloudinary.utils.ObjectUtils.emptyMap;
2729
import static org.junit.Assert.*;
2830

2931
@RunWith(JUnitParamsRunner.class)
@@ -284,15 +286,15 @@ public void testQuality( Object quality, String result) {
284286
Transformation transformation = new Transformation().quality(quality);
285287
assertEquals(result, transformation.generate());
286288
}
289+
@SuppressWarnings("unused")
287290
private Object parametersForTestQuality() {
288-
Object [][] q = {
291+
return new Object[][]{
289292
{0.4, "q_0.4"},
290293
{"0.4", "q_0.4"},
291294
{"auto", "q_auto"},
292295
{"auto:good", "q_auto:good"}};
293-
return q;
294296

295-
};
297+
}
296298

297299
@Test
298300
public void testTransformationSimple() {
@@ -315,7 +317,7 @@ public void testBaseTransformations() {
315317
// should support base transformation
316318
Transformation transformation = new Transformation().x(100).y(100).crop("fill").chain().crop("crop").width(100);
317319
String result = cloudinary.url().transformation(transformation).generate("test");
318-
assertEquals("100", transformation.getHtmlWidth().toString());
320+
assertEquals("100", transformation.getHtmlWidth());
319321
assertEquals(DEFAULT_UPLOAD_PATH + "c_fill,x_100,y_100/c_crop,w_100/test", result);
320322
}
321323

@@ -324,7 +326,7 @@ public void testBaseTransformationArray() {
324326
// should support array of base transformations
325327
Transformation transformation = new Transformation().x(100).y(100).width(200).crop("fill").chain().radius(10).chain().crop("crop").width(100);
326328
String result = cloudinary.url().transformation(transformation).generate("test");
327-
assertEquals("100", transformation.getHtmlWidth().toString());
329+
assertEquals("100", transformation.getHtmlWidth());
328330
assertEquals(DEFAULT_UPLOAD_PATH + "c_fill,w_200,x_100,y_100/r_10/c_crop,w_100/test", result);
329331
}
330332

@@ -373,37 +375,6 @@ public void testAngle() {
373375
assertEquals(DEFAULT_UPLOAD_PATH + "a_exif.12/test", result);
374376
}
375377

376-
@Test
377-
public void testOverlay() {
378-
// should support overlay
379-
Transformation transformation = new Transformation().overlay("text:hello");
380-
String result = cloudinary.url().transformation(transformation).generate("test");
381-
assertEquals(DEFAULT_UPLOAD_PATH + "l_text:hello/test", result);
382-
// should not pass width/height to html if overlay
383-
transformation = new Transformation().overlay("text:hello").width(100).height(100);
384-
result = cloudinary.url().transformation(transformation).generate("test");
385-
assertNull(transformation.getHtmlHeight());
386-
assertNull(transformation.getHtmlWidth());
387-
assertEquals(DEFAULT_UPLOAD_PATH + "h_100,l_text:hello,w_100/test", result);
388-
389-
transformation = new Transformation().overlay(new TextLayer().text("goodbye"));
390-
result = cloudinary.url().transformation(transformation).generate("test");
391-
assertEquals(DEFAULT_UPLOAD_PATH + "l_text:goodbye/test", result);
392-
}
393-
394-
@Test
395-
public void testUnderlay() {
396-
Transformation transformation = new Transformation().underlay("text:hello");
397-
String result = cloudinary.url().transformation(transformation).generate("test");
398-
assertEquals(DEFAULT_UPLOAD_PATH + "u_text:hello/test", result);
399-
// should not pass width/height to html if underlay
400-
transformation = new Transformation().underlay("text:hello").width(100).height(100);
401-
result = cloudinary.url().transformation(transformation).generate("test");
402-
assertNull(transformation.getHtmlHeight());
403-
assertNull(transformation.getHtmlWidth());
404-
assertEquals(DEFAULT_UPLOAD_PATH + "h_100,u_text:hello,w_100/test", result);
405-
}
406-
407378
@Test
408379
public void testFetchFormat() {
409380
// should support format for fetch urls
@@ -480,23 +451,23 @@ public void testOpacity() {
480451
@Test
481452
public void testImageTag() {
482453
Transformation transformation = new Transformation().width(100).height(101).crop("crop");
483-
String result = cloudinary.url().transformation(transformation).imageTag("test", ObjectUtils.asMap("alt", "my image"));
454+
String result = cloudinary.url().transformation(transformation).imageTag("test", asMap("alt", "my image"));
484455
assertEquals("<img src='http://res.cloudinary.com/test123/image/upload/c_crop,h_101,w_100/test' alt='my image' height='101' width='100'/>", result);
485456
transformation = new Transformation().width(0.9).height(0.9).crop("crop").responsiveWidth(true);
486-
result = cloudinary.url().transformation(transformation).imageTag("test", ObjectUtils.asMap("alt", "my image"));
457+
result = cloudinary.url().transformation(transformation).imageTag("test", asMap("alt", "my image"));
487458
assertEquals(
488459
"<img alt='my image' class='cld-responsive' data-src='http://res.cloudinary.com/test123/image/upload/c_crop,h_0.9,w_0.9/c_limit,w_auto/test'/>",
489460
result);
490-
result = cloudinary.url().transformation(transformation).imageTag("test", ObjectUtils.asMap("alt", "my image", "class", "extra"));
461+
result = cloudinary.url().transformation(transformation).imageTag("test", asMap("alt", "my image", "class", "extra"));
491462
assertEquals(
492463
"<img alt='my image' class='extra cld-responsive' data-src='http://res.cloudinary.com/test123/image/upload/c_crop,h_0.9,w_0.9/c_limit,w_auto/test'/>",
493464
result);
494465
transformation = new Transformation().width("auto").crop("crop");
495-
result = cloudinary.url().transformation(transformation).imageTag("test", ObjectUtils.asMap("alt", "my image", "responsive_placeholder", "blank"));
466+
result = cloudinary.url().transformation(transformation).imageTag("test", asMap("alt", "my image", "responsive_placeholder", "blank"));
496467
assertEquals(
497468
"<img src='data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7' alt='my image' class='cld-responsive' data-src='http://res.cloudinary.com/test123/image/upload/c_crop,w_auto/test'/>",
498469
result);
499-
result = cloudinary.url().transformation(transformation).imageTag("test", ObjectUtils.asMap("alt", "my image", "responsive_placeholder", "other.gif"));
470+
result = cloudinary.url().transformation(transformation).imageTag("test", asMap("alt", "my image", "responsive_placeholder", "other.gif"));
500471
assertEquals(
501472
"<img src='other.gif' alt='my image' class='cld-responsive' data-src='http://res.cloudinary.com/test123/image/upload/c_crop,w_auto/test'/>",
502473
result);
@@ -513,14 +484,14 @@ public void testClientHints() {
513484
.dpr("auto");
514485
testTag = cloudinary.url().transformation(trans).imageTag("sample.jpg");
515486
assertTrue(testTag.startsWith("<img") );
516-
assertFalse(testTag.contains("class="));
517-
assertFalse(testTag.contains("data-src"));
518-
assertTrue(testTag.contains("src='http://res.cloudinary.com/test123/image/upload/c_scale,dpr_auto,w_auto/sample.jpg'"));
487+
assertFalse(message, testTag.contains("class="));
488+
assertFalse(message, testTag.contains("data-src"));
489+
assertTrue(message, testTag.contains("src='http://res.cloudinary.com/test123/image/upload/c_scale,dpr_auto,w_auto/sample.jpg'"));
519490
testTag = cloudinary.url().transformation(trans).imageTag("sample.jpg");
520491
assertTrue(testTag.startsWith("<img") );
521492
assertFalse(testTag.contains("class="));
522-
assertFalse(testTag.contains("data-src"));
523-
assertTrue(testTag.contains("src='http://res.cloudinary.com/test123/image/upload/c_scale,dpr_auto,w_auto/sample.jpg'"));
493+
assertFalse(message, testTag.contains("data-src"));
494+
assertTrue(message, testTag.contains("src='http://res.cloudinary.com/test123/image/upload/c_scale,dpr_auto,w_auto/sample.jpg'"));
524495
}
525496
@Test
526497
public void testFolders() {
@@ -548,7 +519,7 @@ public void testShorten() {
548519
@SuppressWarnings("unchecked")
549520
@Test
550521
public void testPrivateDownload() throws Exception {
551-
String url = cloudinary.privateDownload("imgÿ=&é", "jpg", ObjectUtils.emptyMap());
522+
String url = cloudinary.privateDownload("imgÿ=&é", "jpg", emptyMap());
552523
URI uri = new URI(url);
553524
Map<String, String> parameters = getUrlParameters(uri);
554525
assertEquals("imgÿ=&é", parameters.get("public_id"));
@@ -560,7 +531,7 @@ public void testPrivateDownload() throws Exception {
560531
@SuppressWarnings("unchecked")
561532
@Test
562533
public void testZipDownload() throws Exception {
563-
String url = cloudinary.zipDownload("ttag", ObjectUtils.emptyMap());
534+
String url = cloudinary.zipDownload("ttag", emptyMap());
564535
URI uri = new URI(url);
565536
Map<String, String> parameters = getUrlParameters(uri);
566537
assertEquals("ttag", parameters.get("tag"));
@@ -580,7 +551,7 @@ public void testSpriteCss() {
580551
@Test
581552
public void testEscapePublicId() {
582553
// should escape public_ids
583-
Map<String, String> tests = ObjectUtils.asMap("a b", "a%20b", "a+b", "a%2Bb", "a%20b", "a%20b", "a-b", "a-b", "a??b", "a%3F%3Fb");
554+
Map<String, String> tests = asMap("a b", "a%20b", "a+b", "a%2Bb", "a%20b", "a%20b", "a-b", "a-b", "a??b", "a%3F%3Fb");
584555
for (Map.Entry<String, String> entry : tests.entrySet()) {
585556
String result = cloudinary.url().generate(entry.getKey());
586557
assertEquals(DEFAULT_UPLOAD_PATH + "" + entry.getValue(), result);
@@ -611,7 +582,7 @@ public void testResponsiveWidth() {
611582
String result = cloudinary.url().transformation(trans).generate("test");
612583
assertTrue(trans.isResponsive());
613584
assertEquals(DEFAULT_UPLOAD_PATH + "c_crop,h_100,w_100/c_limit,w_auto/test", result);
614-
Transformation.setResponsiveWidthTransformation(ObjectUtils.asMap("width", "auto", "crop", "pad"));
585+
Transformation.setResponsiveWidthTransformation(asMap("width", "auto", "crop", "pad"));
615586
trans = new Transformation().width(100).height(100).crop("crop").responsiveWidth(true);
616587
result = cloudinary.url().transformation(trans).generate("test");
617588
assertTrue(trans.isResponsive());
@@ -648,7 +619,7 @@ public void testVideoCodec() {
648619
// should support a hash value
649620
actual = cloudinary.url().resourceType("video")
650621
.transformation(
651-
new Transformation().videoCodec(ObjectUtils.asMap("codec", "h264", "profile", "basic", "level", "3.1"))
622+
new Transformation().videoCodec(asMap("codec", "h264", "profile", "basic", "level", "3.1"))
652623
).generate("video_id");
653624
assertEquals(VIDEO_UPLOAD_PATH + "vc_h264:basic:3.1/video_id", actual);
654625
}
@@ -784,13 +755,13 @@ public void testVideoTag() {
784755
+ "<source src='%s.ogv' type='video/ogg'>"
785756
+ "</video>";
786757
expectedTag = String.format(expectedTag, expectedUrl, expectedUrl, expectedUrl, expectedUrl);
787-
assertEquals(expectedTag, cloudinary.url().videoTag("movie", ObjectUtils.emptyMap()));
758+
assertEquals(expectedTag, cloudinary.url().videoTag("movie", emptyMap()));
788759
assertEquals(expectedTag, cloudinary.url().publicId("movie").videoTag());
789760
}
790761

791762
@Test
792763
public void testVideoTagWithAttributes() {
793-
Map attributes = ObjectUtils.asMap(
764+
Map attributes = asMap(
794765
"autoplay", true,
795766
"controls", null,
796767
"loop", null,
@@ -808,13 +779,13 @@ public void testVideoTagWithAttributes() {
808779

809780
@Test
810781
public void testVideoTagWithTransformation() {
811-
Transformation transformation = new Transformation().videoCodec(ObjectUtils.asMap("codec", "h264"))
782+
Transformation transformation = new Transformation().videoCodec(asMap("codec", "h264"))
812783
.audioCodec("acc").startOffset(3);
813784
String expectedUrl = VIDEO_UPLOAD_PATH + "ac_acc,so_3.0,vc_h264/movie";
814785
String expectedTag = "<video height='100' poster='%s.jpg' src='%s.mp4' width='200'></video>";
815786
expectedTag = String.format(expectedTag, expectedUrl, expectedUrl);
816787
String actualTag = cloudinary.url().transformation(transformation).sourceTypes(new String[]{"mp4"})
817-
.videoTag("movie", ObjectUtils.asMap("html_height", "100", "html_width", "200"));
788+
.videoTag("movie", asMap("html_height", "100", "html_width", "200"));
818789
assertEquals(expectedTag, actualTag);
819790

820791
expectedTag = "<video height='100' poster='%s.jpg' width='200'>"
@@ -824,7 +795,7 @@ public void testVideoTagWithTransformation() {
824795
+ "</video>";
825796
expectedTag = String.format(expectedTag, expectedUrl, expectedUrl, expectedUrl, expectedUrl);
826797
actualTag = cloudinary.url().transformation(transformation)
827-
.videoTag("movie", ObjectUtils.asMap("html_height", "100", "html_width", "200"));
798+
.videoTag("movie", asMap("html_height", "100", "html_width", "200"));
828799
assertEquals(expectedTag, actualTag);
829800

830801
transformation.width(250);
@@ -836,7 +807,7 @@ public void testVideoTagWithTransformation() {
836807
+ "</video>";
837808
expectedTag = String.format(expectedTag, expectedUrl, expectedUrl, expectedUrl, expectedUrl);
838809
actualTag = cloudinary.url().transformation(transformation)
839-
.videoTag("movie", ObjectUtils.asMap());
810+
.videoTag("movie", asMap());
840811
assertEquals(expectedTag, actualTag);
841812

842813
transformation.crop("fit");
@@ -848,7 +819,7 @@ public void testVideoTagWithTransformation() {
848819
+ "</video>";
849820
expectedTag = String.format(expectedTag, expectedUrl, expectedUrl, expectedUrl, expectedUrl);
850821
actualTag = cloudinary.url().transformation(transformation)
851-
.videoTag("movie", ObjectUtils.asMap());
822+
.videoTag("movie", asMap());
852823
assertEquals(expectedTag, actualTag);
853824
}
854825

@@ -859,13 +830,13 @@ public void testVideoTagWithFallback() {
859830
String expectedTag = "<video poster='%s.jpg' src='%s.mp4'>%s</video>";
860831
expectedTag = String.format(expectedTag, expectedUrl, expectedUrl, fallback);
861832
String actualTag = cloudinary.url().fallbackContent(fallback).sourceTypes(new String[]{"mp4"})
862-
.videoTag("movie", ObjectUtils.emptyMap());
833+
.videoTag("movie", emptyMap());
863834
assertEquals(expectedTag, actualTag);
864835

865836
expectedTag = "<video poster='%s.jpg'>" + "<source src='%s.webm' type='video/webm'>"
866837
+ "<source src='%s.mp4' type='video/mp4'>" + "<source src='%s.ogv' type='video/ogg'>%s" + "</video>";
867838
expectedTag = String.format(expectedTag, expectedUrl, expectedUrl, expectedUrl, expectedUrl, fallback);
868-
actualTag = cloudinary.url().fallbackContent(fallback).videoTag("movie", ObjectUtils.emptyMap());
839+
actualTag = cloudinary.url().fallbackContent(fallback).videoTag("movie", emptyMap());
869840
assertEquals(expectedTag, actualTag);
870841
}
871842

@@ -876,7 +847,7 @@ public void testVideoTagWithSourceTypes() {
876847
+ "<source src='%s.mp4' type='video/mp4'>" + "</video>";
877848
expectedTag = String.format(expectedTag, expectedUrl, expectedUrl, expectedUrl);
878849
String actualTag = cloudinary.url().sourceTypes(new String[]{"ogv", "mp4"})
879-
.videoTag("movie.mp4", ObjectUtils.emptyMap());
850+
.videoTag("movie.mp4", emptyMap());
880851
assertEquals(expectedTag, actualTag);
881852
}
882853

@@ -894,7 +865,7 @@ public void testVideoTagWithSourceTransformation() {
894865
String actualTag = cloudinary.url().transformation(new Transformation().quality(50).chain().width(100))
895866
.sourceTransformationFor("mp4", new Transformation().quality(30))
896867
.sourceTransformationFor("ogv", new Transformation().quality(70))
897-
.videoTag("movie", ObjectUtils.emptyMap());
868+
.videoTag("movie", emptyMap());
898869
assertEquals(expectedTag, actualTag);
899870

900871
expectedTag = "<video poster='%s.jpg' width='100'>" + "<source src='%s.webm' type='video/webm'>"
@@ -903,7 +874,7 @@ public void testVideoTagWithSourceTransformation() {
903874
actualTag = cloudinary.url().transformation(new Transformation().quality(50).chain().width(100))
904875
.sourceTransformationFor("mp4", new Transformation().quality(30))
905876
.sourceTransformationFor("ogv", new Transformation().quality(70))
906-
.sourceTypes(new String[]{"webm", "mp4"}).videoTag("movie", ObjectUtils.emptyMap());
877+
.sourceTypes(new String[]{"webm", "mp4"}).videoTag("movie", emptyMap());
907878
assertEquals(expectedTag, actualTag);
908879
}
909880

@@ -914,15 +885,15 @@ public void testVideoTagWithPoster() {
914885
String expectedTag = "<video poster='%s' src='%s.mp4'></video>";
915886
expectedTag = String.format(expectedTag, posterUrl, expectedUrl);
916887
String actualTag = cloudinary.url().sourceTypes(new String[]{"mp4"}).poster(posterUrl)
917-
.videoTag("movie", ObjectUtils.emptyMap());
888+
.videoTag("movie", emptyMap());
918889
assertEquals(expectedTag, actualTag);
919890

920891
posterUrl = VIDEO_UPLOAD_PATH + "g_north/movie.jpg";
921892
expectedTag = "<video poster='%s' src='%s.mp4'></video>";
922893
expectedTag = String.format(expectedTag, posterUrl, expectedUrl);
923894
actualTag = cloudinary.url().sourceTypes(new String[]{"mp4"})
924895
.poster(new Transformation().gravity("north"))
925-
.videoTag("movie", ObjectUtils.emptyMap());
896+
.videoTag("movie", emptyMap());
926897
assertEquals(expectedTag, actualTag);
927898

928899
posterUrl = DEFAULT_UPLOAD_PATH + "g_north/my_poster.jpg";
@@ -933,19 +904,19 @@ public void testVideoTagWithPoster() {
933904
.publicId("my_poster")
934905
.format("jpg")
935906
.transformation(new Transformation().gravity("north")))
936-
.videoTag("movie", ObjectUtils.emptyMap());
907+
.videoTag("movie", emptyMap());
937908
assertEquals(expectedTag, actualTag);
938909

939910
expectedTag = "<video src='%s.mp4'></video>";
940911
expectedTag = String.format(expectedTag, expectedUrl);
941912
actualTag = cloudinary.url().sourceTypes(new String[]{"mp4"})
942913
.poster(null)
943-
.videoTag("movie", ObjectUtils.emptyMap());
914+
.videoTag("movie", emptyMap());
944915
assertEquals(expectedTag, actualTag);
945916

946917
actualTag = cloudinary.url().sourceTypes(new String[]{"mp4"})
947918
.poster(false)
948-
.videoTag("movie", ObjectUtils.emptyMap());
919+
.videoTag("movie", emptyMap());
949920
assertEquals(expectedTag, actualTag);
950921

951922
}
@@ -994,6 +965,7 @@ public void testOverlayOptions() {
994965

995966

996967
@Test
968+
@SuppressWarnings("deprecation")
997969
public void testBackwardCampatibleOverlayOptions() {
998970
Object tests[] = {
999971
new LayerBuilder().publicId("logo"),
@@ -1061,7 +1033,7 @@ public static Map<String, String> getUrlParameters(URI uri) throws UnsupportedEn
10611033
if (pair.length > 1) {
10621034
value = URLDecoder.decode(pair[1], "UTF-8");
10631035
}
1064-
params.put(new String(key), new String(value));
1036+
params.put(key, value);
10651037
}
10661038
return params;
10671039
}

0 commit comments

Comments
 (0)