Skip to content

Commit 751c2e4

Browse files
committed
Fix responsive breakpoint format field implementation, add tests.
1 parent 4f0c11e commit 751c2e4

File tree

2 files changed

+15
-26
lines changed

2 files changed

+15
-26
lines changed

cloudinary-core/src/main/java/com/cloudinary/ResponsiveBreakpoint.java

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package com.cloudinary;
22

3-
import com.cloudinary.utils.StringUtils;
4-
53
import org.cloudinary.json.JSONObject;
64

75
public class ResponsiveBreakpoint extends JSONObject {
8-
private Transformation transformation = null;
9-
private String format = "";
10-
116
public ResponsiveBreakpoint() {
127
put("create_derived", true);
138
}
@@ -22,33 +17,21 @@ public ResponsiveBreakpoint createDerived(boolean createDerived) {
2217
}
2318

2419
public Transformation transformation() {
25-
return transformation;
20+
return (Transformation) opt("transformation");
2621
}
2722

2823
public ResponsiveBreakpoint transformation(Transformation transformation) {
29-
this.transformation = transformation;
30-
updateTransformationKey();
24+
put("transformation", transformation);
3125
return this;
3226
}
3327

34-
3528
public ResponsiveBreakpoint format(String format) {
36-
this.format = format;
37-
updateTransformationKey();
29+
put("format", format);
3830
return this;
3931
}
4032

4133
public String format() {
42-
return format;
43-
}
44-
45-
private synchronized void updateTransformationKey() {
46-
String transformationStr = transformation == null ? "" : transformation.generate();
47-
if (StringUtils.isNotBlank(format)){
48-
transformationStr += "/" + format;
49-
}
50-
51-
put("transformation", transformationStr);
34+
return optString("format");
5235
}
5336

5437
public int maxWidth() {

cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractUploaderTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -502,16 +502,22 @@ public void testFilenameOption() throws Exception {
502502

503503
@Test
504504
public void testResponsiveBreakpoints() throws Exception {
505-
ResponsiveBreakpoint breakpoint = new ResponsiveBreakpoint().maxImages(2).createDerived(false).format("gif");
505+
ResponsiveBreakpoint breakpoint = new ResponsiveBreakpoint()
506+
.createDerived(true)
507+
.maxImages(2)
508+
.transformation(new Transformation().angle(90))
509+
.format("gif");
506510

507511
// A single breakpoint
508512
Map result = cloudinary.uploader().upload(SRC_TEST_IMAGE, asMap("responsive_breakpoints",
509-
breakpoint, "tags", Arrays.asList(SDK_TEST_TAG, UPLOADER_TAG)
510-
));
513+
breakpoint, "tags", Arrays.asList(SDK_TEST_TAG, UPLOADER_TAG)));
514+
511515
java.util.ArrayList breakpointsResponse = (java.util.ArrayList) result.get("responsive_breakpoints");
512-
java.util.ArrayList breakpoints = (java.util.ArrayList) ((Map) breakpointsResponse.get(0)).get("breakpoints");
513-
assertEquals(2, breakpoints.size());
516+
Map map = (Map) breakpointsResponse.get(0);
517+
518+
java.util.ArrayList breakpoints = (java.util.ArrayList) map.get("breakpoints");
514519
assertTrue(((Map) breakpoints.get(0)).get("url").toString().endsWith("gif"));
520+
assertEquals("a_90", map.get("transformation"));
515521

516522
// check again with transformation + format
517523
breakpoint.transformation(new Transformation().effect("sepia"));

0 commit comments

Comments
 (0)