/** * Set the {@link ParseACL} governing this object. */ public void setACL(ParseACL acl) { put(KEY_ACL, acl); }
@Override public void put(@NonNull String key, @NonNull Object value) { synchronized (mutex) { if (KEY_USERNAME.equals(key)) { // When the username is set, remove any semblance of anonymity. stripAnonymity(); } super.put(key, value); } }
@Test public void testGetList() { ParseObject object = new ParseObject("Test"); JSONArray array = new JSONArray(); array.put("value"); array.put("valueAgain"); object.put("key", array); List list = object.getList("key"); assertEquals(2, list.size()); assertTrue(list.contains("value")); assertTrue(list.contains("valueAgain")); }
@Test public void testGetJSONObject() throws Exception { ParseObject object = new ParseObject("Test"); Map<String, String> map = new HashMap<>(); map.put("key", "value"); map.put("keyAgain", "valueAgain"); object.put("key", map); JSONObject json = object.getJSONObject("key"); assertEquals(2, json.length()); assertEquals("value", json.getString("key")); assertEquals("valueAgain", json.getString("keyAgain")); }
@Test public void testGetMap() throws Exception { ParseObject object = new ParseObject("Test"); JSONObject json = new JSONObject(); json.put("key", "value"); json.put("keyAgain", "valueAgain"); object.put("key", json); Map map = object.getMap("key"); assertEquals(2, map.size()); assertEquals("value", map.get("key")); assertEquals("valueAgain", map.get("keyAgain")); }
@Test public void testGetDate() { ParseObject object = new ParseObject("Test"); Date date = new Date(); object.put("key", date); assertEquals(date, object.getDate("key")); }
@Test public void testGetParsePolygon() { ParseObject object = new ParseObject("Test"); List<ParseGeoPoint> points = new ArrayList<>(); points.add(new ParseGeoPoint(0, 0)); points.add(new ParseGeoPoint(0, 1)); points.add(new ParseGeoPoint(1, 1)); points.add(new ParseGeoPoint(1, 0)); ParsePolygon polygon = new ParsePolygon(points); object.put("key", polygon); assertEquals(polygon, object.getParsePolygon("key")); }
@Test public void testGetDoubleWithWrongValue() { ParseObject object = new ParseObject("Test"); object.put("key", "str"); assertEquals(0.0, object.getDouble("key"), 0.00001); }
@Test public void testGetDouble() { ParseObject object = new ParseObject("Test"); object.put("key", 1.1); assertEquals(1.1, object.getDouble("key"), 0.00001); }
@Test public void testGetLong() { ParseObject object = new ParseObject("Test"); object.put("key", 10L); assertEquals(10L, object.getLong("key")); }
@Test public void testGetLongWithWrongValue() { ParseObject object = new ParseObject("Test"); object.put("key", "str"); assertEquals(0, object.getLong("key")); }
@Test public void testGetJsonObjectWithWrongValue() { ParseObject object = new ParseObject("Test"); object.put("key", 1); assertNull(object.getJSONObject("key")); }
@Test public void testGetBoolean() { ParseObject object = new ParseObject("Test"); object.put("key", true); assertTrue(object.getBoolean("key")); }
@Test public void testGetDateWithWrongValue() { ParseObject object = new ParseObject("Test"); object.put("key", 1); assertNull(object.getDate("key")); }
@Test public void testGetParseGeoPointWithWrongValue() { ParseObject object = new ParseObject("Test"); object.put("key", 1); assertNull(object.getParseGeoPoint("key")); }
@Test public void testGetBooleanWithWrongValue() { ParseObject object = new ParseObject("Test"); object.put("key", 1); assertFalse(object.getBoolean("key")); }
@Test public void testGetParsePolygonWithWrongValue() { ParseObject object = new ParseObject("Test"); object.put("key", 1); assertNull(object.getParsePolygon("key")); }
@Test public void testGetParseFileWithWrongValue() { ParseObject object = new ParseObject("Test"); object.put("key", 1); assertNull(object.getParseFile("key")); }
@Test public void testGetParseGeoPoint() { ParseObject object = new ParseObject("Test"); ParseGeoPoint point = new ParseGeoPoint(10, 10); object.put("key", point); assertEquals(point, object.getParseGeoPoint("key")); }
@Test public void testGetACLWithSharedACL() { ParseObject object = new ParseObject("Test"); ParseACL acl = new ParseACL(); acl.setShared(true); acl.setPublicReadAccess(true); object.put("ACL", acl); ParseACL aclAgain = object.getACL(); assertTrue(aclAgain.getPublicReadAccess()); }