|
11 | 11 | import java.util.List; |
12 | 12 | import java.util.Map; |
13 | 13 |
|
| 14 | +import java.awt.Rectangle; |
| 15 | + |
14 | 16 | import org.junit.Before; |
15 | 17 | import org.junit.BeforeClass; |
16 | 18 | import org.junit.Test; |
17 | 19 |
|
18 | 20 | import com.cloudinary.Cloudinary; |
| 21 | +import com.cloudinary.Coordinates; |
19 | 22 | import com.cloudinary.Transformation; |
20 | 23 |
|
21 | 24 | @SuppressWarnings({"rawtypes", "unchecked"}) |
@@ -216,27 +219,44 @@ public void testAllowedFormatsWithFormat() throws Exception { |
216 | 219 | @Test |
217 | 220 | public void testFaceCoordinates() throws Exception { |
218 | 221 | //should allow sending face coordinates |
219 | | - Long[] coordinates = new Long[]{120L,30L,109L,150L}; |
| 222 | + Coordinates coordinates = new Coordinates(); |
| 223 | + Rectangle rect1 = new Rectangle(121,31,110,151); |
| 224 | + Rectangle rect2 = new Rectangle(120,30,109,150); |
| 225 | + coordinates.addRect(rect1); |
| 226 | + coordinates.addRect(rect2); |
220 | 227 | Map result = cloudinary.uploader().upload("src/test/resources/logo.png", Cloudinary.asMap("face_coordinates", coordinates, "faces", true)); |
221 | 228 | org.json.simple.JSONArray resultFaces = (org.json.simple.JSONArray) result.get("faces"); |
222 | | - assertEquals(1, resultFaces.size()); |
| 229 | + assertEquals(2, resultFaces.size()); |
| 230 | + |
223 | 231 | Object[] resultCoordinates = ((org.json.simple.JSONArray) resultFaces.get(0)).toArray(); |
224 | | - assertEquals(4, resultCoordinates.length); |
225 | | - for (int i=0; i < resultCoordinates.length; i++) { |
226 | | - assertEquals(coordinates[i], resultCoordinates[i]); |
227 | | - } |
228 | 232 |
|
229 | | - Long[] differentCoordinates = new Long[]{121L,31L,110L,151L}; |
| 233 | + assertEquals((long)rect1.x, resultCoordinates[0]); |
| 234 | + assertEquals((long)rect1.y, resultCoordinates[1]); |
| 235 | + assertEquals((long)rect1.width, resultCoordinates[2]); |
| 236 | + assertEquals((long)rect1.height, resultCoordinates[3]); |
| 237 | + |
| 238 | + resultCoordinates = ((org.json.simple.JSONArray) resultFaces.get(1)).toArray(); |
| 239 | + |
| 240 | + assertEquals((long)rect2.x, resultCoordinates[0]); |
| 241 | + assertEquals((long)rect2.y, resultCoordinates[1]); |
| 242 | + assertEquals((long)rect2.width, resultCoordinates[2]); |
| 243 | + assertEquals((long)rect2.height, resultCoordinates[3]); |
| 244 | + |
| 245 | + Coordinates differentCoordinates = new Coordinates(); |
| 246 | + Rectangle rect3 = new Rectangle(122,32,111,152); |
| 247 | + differentCoordinates.addRect(rect3); |
230 | 248 | cloudinary.uploader().explicit((String) result.get("public_id"), Cloudinary.asMap("face_coordinates", differentCoordinates, "faces", true, "type", "upload")); |
231 | 249 | Map info = cloudinary.api().resource((String) result.get("public_id"), Cloudinary.asMap("faces", true)); |
232 | 250 |
|
233 | 251 | resultFaces = (org.json.simple.JSONArray) info.get("faces"); |
234 | 252 | assertEquals(1, resultFaces.size()); |
235 | 253 | resultCoordinates = ((org.json.simple.JSONArray) resultFaces.get(0)).toArray(); |
236 | | - assertEquals(4, resultCoordinates.length); |
237 | | - for (int i=0; i < resultCoordinates.length; i++) { |
238 | | - assertEquals(differentCoordinates[i], resultCoordinates[i]); |
239 | | - } |
| 254 | + |
| 255 | + assertEquals((long)rect3.x, resultCoordinates[0]); |
| 256 | + assertEquals((long)rect3.y, resultCoordinates[1]); |
| 257 | + assertEquals((long)rect3.width, resultCoordinates[2]); |
| 258 | + assertEquals((long)rect3.height, resultCoordinates[3]); |
| 259 | + |
240 | 260 | } |
241 | 261 |
|
242 | 262 | @Test |
|
0 commit comments