Skip to content

Commit afcda7f

Browse files
authored
Merge pull request #106 from cloudinary/fix/responsive-breakpoints-format
Add format field to `ResponsiveBreakpoint`.
2 parents 6f631ea + fb5f034 commit afcda7f

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

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

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

3-
import org.cloudinary.json.JSONObject;
3+
import com.cloudinary.utils.StringUtils;
44

5-
import java.util.Collections;
5+
import org.cloudinary.json.JSONObject;
66

77
public class ResponsiveBreakpoint extends JSONObject {
8+
private Transformation transformation = null;
9+
private String format = "";
10+
811
public ResponsiveBreakpoint() {
912
put("create_derived", true);
1013
}
@@ -19,14 +22,35 @@ public ResponsiveBreakpoint createDerived(boolean createDerived) {
1922
}
2023

2124
public Transformation transformation() {
22-
return (Transformation) opt("transformation");
25+
return transformation;
2326
}
2427

2528
public ResponsiveBreakpoint transformation(Transformation transformation) {
26-
put("transformation", Util.buildEager(Collections.singletonList(transformation)));
29+
this.transformation = transformation;
30+
updateTransformationKey();
31+
return this;
32+
}
33+
34+
35+
public ResponsiveBreakpoint format(String format) {
36+
this.format = format;
37+
updateTransformationKey();
2738
return this;
2839
}
2940

41+
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);
52+
}
53+
3054
public int maxWidth() {
3155
return optInt("max_width");
3256
}
@@ -62,5 +86,4 @@ public ResponsiveBreakpoint maxImages(Integer maxImages) {
6286
put("max_images", maxImages);
6387
return this;
6488
}
65-
6689
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ public void testFilenameOption() throws Exception {
493493

494494
@Test
495495
public void testResponsiveBreakpoints() throws Exception {
496-
ResponsiveBreakpoint breakpoint = new ResponsiveBreakpoint().maxImages(2).createDerived(false).transformation(new EagerTransformation().format("gif").effect("sepia"));
496+
ResponsiveBreakpoint breakpoint = new ResponsiveBreakpoint().maxImages(2).createDerived(false).format("gif");
497497

498498
// A single breakpoint
499499
Map result = cloudinary.uploader().upload(SRC_TEST_IMAGE, asMap("responsive_breakpoints",
@@ -504,13 +504,17 @@ public void testResponsiveBreakpoints() throws Exception {
504504
assertEquals(2, breakpoints.size());
505505
assertTrue(((Map) breakpoints.get(0)).get("url").toString().endsWith("gif"));
506506

507+
// check again with transformation + format
508+
breakpoint.transformation(new Transformation().effect("sepia"));
509+
507510
// an array of breakpoints
508511
result = cloudinary.uploader().upload(SRC_TEST_IMAGE, asMap("responsive_breakpoints",
509512
new ResponsiveBreakpoint[]{breakpoint}, "tags", Arrays.asList(SDK_TEST_TAG, UPLOADER_TAG)
510513
));
511514
breakpointsResponse = (java.util.ArrayList) result.get("responsive_breakpoints");
512515
breakpoints = (java.util.ArrayList) ((Map) breakpointsResponse.get(0)).get("breakpoints");
513516
assertEquals(2, breakpoints.size());
517+
assertTrue(((Map) breakpoints.get(0)).get("url").toString().endsWith("gif"));
514518

515519
// a JSONArray of breakpoints
516520
JSONArray array = new JSONArray();

0 commit comments

Comments
 (0)