From ab9b38615e1d196958e80e59bbdf762defd7241d Mon Sep 17 00:00:00 2001 From: Shy-Yauer Lin Date: Thu, 1 Oct 2015 16:48:28 -0700 Subject: [PATCH] Make OfflineQueryLogic.fetchIncludeAsync static --- .../java/com/parse/OfflineQueryLogic.java | 25 +++++++------ .../src/main/java/com/parse/OfflineStore.java | 2 +- .../java/com/parse/OfflineQueryLogicTest.java | 35 ++++++------------- 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/Parse/src/main/java/com/parse/OfflineQueryLogic.java b/Parse/src/main/java/com/parse/OfflineQueryLogic.java index aee9ed7f1..3a95f1186 100644 --- a/Parse/src/main/java/com/parse/OfflineQueryLogic.java +++ b/Parse/src/main/java/com/parse/OfflineQueryLogic.java @@ -459,7 +459,7 @@ private static boolean matchesWithinConstraint(Object constraint, Object value) /** * Returns true iff the given value matches the given operator and constraint. - * + * * @throws UnsupportedOperationException * if the operator is not one this function can handle. */ @@ -955,8 +955,11 @@ public int compare(T lhs, T rhs) { /** * Makes sure that the object specified by path, relative to container, is fetched. */ - private Task fetchIncludeAsync( - final Object container, final String path, final ParseSQLiteDatabase db) + private static Task fetchIncludeAsync( + final OfflineStore store, + final Object container, + final String path, + final ParseSQLiteDatabase db) throws ParseException { // If there's no object to include, that's fine. if (container == null) { @@ -972,7 +975,7 @@ private Task fetchIncludeAsync( task = task.onSuccessTask(new Continuation>() { @Override public Task then(Task task) throws Exception { - return fetchIncludeAsync(item, path, db); + return fetchIncludeAsync(store, item, path, db); } }); } @@ -986,7 +989,7 @@ public Task then(Task task) throws Exception { task = task.onSuccessTask(new Continuation>() { @Override public Task then(Task task) throws Exception { - return fetchIncludeAsync(array.get(index), path, db); + return fetchIncludeAsync(store, array.get(index), path, db); } }); } @@ -1020,7 +1023,7 @@ public Task then(Task task) throws Exception { public Task then(Task task) throws Exception { if (container instanceof ParseObject) { // Make sure this object is fetched before descending into it. - return fetchIncludeAsync(container, null, db).onSuccess(new Continuation() { + return fetchIncludeAsync(store, container, null, db).onSuccess(new Continuation() { @Override public Object then(Task task) throws Exception { return ((ParseObject) container).get(key); @@ -1041,7 +1044,7 @@ public Object then(Task task) throws Exception { }).onSuccessTask(new Continuation>() { @Override public Task then(Task task) throws Exception { - return fetchIncludeAsync(task.getResult(), rest, db); + return fetchIncludeAsync(store, task.getResult(), rest, db); } }); } @@ -1049,9 +1052,11 @@ public Task then(Task task) throws Exception { /** * Makes sure all of the objects included by the given query get fetched. */ - /* package */ Task fetchIncludesAsync( + /* package */ static Task fetchIncludesAsync( + final OfflineStore store, final T object, - ParseQuery.State state, final ParseSQLiteDatabase db) { + ParseQuery.State state, + final ParseSQLiteDatabase db) { Set includes = state.includes(); // We do the fetches in series because it makes it easier to fail on the first error. Task task = Task.forResult(null); @@ -1059,7 +1064,7 @@ public Task then(Task task) throws Exception { task = task.onSuccessTask(new Continuation>() { @Override public Task then(Task task) throws Exception { - return fetchIncludeAsync(object, include, db); + return fetchIncludeAsync(store, object, include, db); } }); } diff --git a/Parse/src/main/java/com/parse/OfflineStore.java b/Parse/src/main/java/com/parse/OfflineStore.java index 3cb0b0912..b79f23f5a 100644 --- a/Parse/src/main/java/com/parse/OfflineStore.java +++ b/Parse/src/main/java/com/parse/OfflineStore.java @@ -455,7 +455,7 @@ public Task> then(Task task) throws Exception { fetchedIncludesTask = fetchedIncludesTask.onSuccessTask(new Continuation>() { @Override public Task then(Task task) throws Exception { - return queryLogic.fetchIncludesAsync(object, query, db); + return OfflineQueryLogic.fetchIncludesAsync(OfflineStore.this, object, query, db); } }); } diff --git a/Parse/src/test/java/com/parse/OfflineQueryLogicTest.java b/Parse/src/test/java/com/parse/OfflineQueryLogicTest.java index 7a705cbd9..3d7a79e05 100644 --- a/Parse/src/test/java/com/parse/OfflineQueryLogicTest.java +++ b/Parse/src/test/java/com/parse/OfflineQueryLogicTest.java @@ -828,7 +828,6 @@ public void testFetchIncludesParseObject() throws ParseException { when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class))) .thenReturn(Task.forResult(null)); - OfflineQueryLogic logic = new OfflineQueryLogic(store); ParseSQLiteDatabase db = mock(ParseSQLiteDatabase.class); ParseQuery.State query = new ParseQuery.State.Builder<>("TestObject") @@ -839,7 +838,7 @@ public void testFetchIncludesParseObject() throws ParseException { ParseObject unfetchedObject = new ParseObject("TestObject"); object.put("foo", unfetchedObject); - ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, db)); + ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, db)); verify(store).fetchLocallyAsync(object, db); verify(store).fetchLocallyAsync(unfetchedObject, db); verifyNoMoreInteractions(store); @@ -851,7 +850,6 @@ public void testFetchIncludesCollection() throws ParseException { when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class))) .thenReturn(Task.forResult(null)); - OfflineQueryLogic logic = new OfflineQueryLogic(store); ParseSQLiteDatabase db = mock(ParseSQLiteDatabase.class); ParseQuery.State query = new ParseQuery.State.Builder<>("TestObject") @@ -864,7 +862,7 @@ public void testFetchIncludesCollection() throws ParseException { objects.add(unfetchedObject); when(object.get("foo")).thenReturn(objects); - ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, db)); + ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, db)); verify(store).fetchLocallyAsync(object, db); verify(store).fetchLocallyAsync(unfetchedObject, db); verifyNoMoreInteractions(store); @@ -876,7 +874,6 @@ public void testFetchIncludesJSONArray() throws ParseException { when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class))) .thenReturn(Task.forResult(null)); - OfflineQueryLogic logic = new OfflineQueryLogic(store); ParseSQLiteDatabase db = mock(ParseSQLiteDatabase.class); ParseQuery.State query = new ParseQuery.State.Builder<>("TestObject") @@ -889,7 +886,7 @@ public void testFetchIncludesJSONArray() throws ParseException { objects.put(unfetchedObject); when(object.get("foo")).thenReturn(objects); - ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, db)); + ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, db)); verify(store).fetchLocallyAsync(object, db); verify(store).fetchLocallyAsync(unfetchedObject, db); verifyNoMoreInteractions(store); @@ -901,7 +898,6 @@ public void testFetchIncludesMap() throws ParseException { when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class))) .thenReturn(Task.forResult(null)); - OfflineQueryLogic logic = new OfflineQueryLogic(store); ParseSQLiteDatabase db = mock(ParseSQLiteDatabase.class); ParseQuery.State query = new ParseQuery.State.Builder<>("TestObject") @@ -914,7 +910,7 @@ public void testFetchIncludesMap() throws ParseException { objects.put("bar", unfetchedObject); when(object.get("foo")).thenReturn(objects); - ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, db)); + ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, db)); verify(store).fetchLocallyAsync(object, db); verify(store).fetchLocallyAsync(unfetchedObject, db); verifyNoMoreInteractions(store); @@ -926,7 +922,6 @@ public void testFetchIncludesJSONObject() throws Exception { when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class))) .thenReturn(Task.forResult(null)); - OfflineQueryLogic logic = new OfflineQueryLogic(store); ParseSQLiteDatabase db = mock(ParseSQLiteDatabase.class); ParseQuery.State query = new ParseQuery.State.Builder<>("TestObject") @@ -939,7 +934,7 @@ public void testFetchIncludesJSONObject() throws Exception { objects.put("bar", unfetchedObject); when(object.get("foo")).thenReturn(objects); - ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, db)); + ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, db)); verify(store).fetchLocallyAsync(object, db); verify(store).fetchLocallyAsync(unfetchedObject, db); verifyNoMoreInteractions(store); @@ -951,8 +946,6 @@ public void testFetchIncludesNull() throws ParseException { when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class))) .thenReturn(Task.forResult(null)); - OfflineQueryLogic logic = new OfflineQueryLogic(store); - ParseQuery.State query = new ParseQuery.State.Builder<>("TestObject") .include("foo") .build(); @@ -960,7 +953,7 @@ public void testFetchIncludesNull() throws ParseException { ParseObject object = new ParseObject("TestObject"); object.put("foo", JSONObject.NULL); - ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, null)); + ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, null)); // only itself verify(store, times(1)) .fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class)); @@ -972,8 +965,6 @@ public void testFetchIncludesNonParseObject() throws ParseException { when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class))) .thenReturn(Task.forResult(null)); - OfflineQueryLogic logic = new OfflineQueryLogic(store); - ParseQuery.State query = new ParseQuery.State.Builder<>("TestObject") .include("foo") .build(); @@ -982,7 +973,7 @@ public void testFetchIncludesNonParseObject() throws ParseException { object.put("foo", 1); thrown.expect(ParseException.class); - ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, null)); + ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, null)); // only itself verify(store, times(1)) .fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class)); @@ -994,15 +985,13 @@ public void testFetchIncludesDoesNotExist() throws ParseException { when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class))) .thenReturn(Task.forResult(null)); - OfflineQueryLogic logic = new OfflineQueryLogic(store); - ParseQuery.State query = new ParseQuery.State.Builder<>("TestObject") .include("foo") .build(); ParseObject object = new ParseObject("TestObject"); - ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, null)); + ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, null)); // only itself verify(store, times(1)) .fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class)); @@ -1014,8 +1003,6 @@ public void testFetchIncludesNestedNull() throws Exception { when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class))) .thenReturn(Task.forResult(null)); - OfflineQueryLogic logic = new OfflineQueryLogic(store); - ParseQuery.State query = new ParseQuery.State.Builder<>("TestObject") .include("foo.bar") .build(); @@ -1023,7 +1010,7 @@ public void testFetchIncludesNestedNull() throws Exception { ParseObject object = new ParseObject("TestObject"); object.put("foo", JSONObject.NULL); - ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, null)); + ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, null)); // only itself verify(store, times(1)) .fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class)); @@ -1035,8 +1022,6 @@ public void testFetchIncludesNestedNonParseObject() throws Exception { when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class))) .thenReturn(Task.forResult(null)); - OfflineQueryLogic logic = new OfflineQueryLogic(store); - ParseQuery.State query = new ParseQuery.State.Builder<>("TestObject") .include("foo.bar") .build(); @@ -1045,7 +1030,7 @@ public void testFetchIncludesNestedNonParseObject() throws Exception { object.put("foo", 1); thrown.expect(IllegalStateException.class); - ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, null)); + ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, null)); // only itself verify(store, times(1)) .fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class));