|
29 | 29 | import bolts.Task;
|
30 | 30 |
|
31 | 31 | import static org.junit.Assert.assertEquals;
|
| 32 | +import static org.junit.Assert.assertNotNull; |
32 | 33 | import static org.junit.Assert.assertNull;
|
33 | 34 | import static org.junit.Assert.assertTrue;
|
34 | 35 | import static org.mockito.Matchers.any;
|
| 36 | +import static org.mockito.Matchers.eq; |
35 | 37 | import static org.mockito.Mockito.doReturn;
|
36 | 38 | import static org.mockito.Mockito.mock;
|
37 | 39 | import static org.mockito.Mockito.spy;
|
@@ -108,6 +110,50 @@ public void testImmutableKeys() {
|
108 | 110 | }
|
109 | 111 | }
|
110 | 112 |
|
| 113 | + @Test |
| 114 | + public void testSaveAsync() throws Exception { |
| 115 | + String sessionToken = "sessionToken"; |
| 116 | + Task<Void> toAwait = Task.forResult(null); |
| 117 | + |
| 118 | + ParseCurrentInstallationController controller = |
| 119 | + mock(ParseCurrentInstallationController.class); |
| 120 | + ParseInstallation currentInstallation = new ParseInstallation(); |
| 121 | + when(controller.getAsync()) |
| 122 | + .thenReturn(Task.forResult(currentInstallation)); |
| 123 | + ParseCorePlugins.getInstance() |
| 124 | + .registerCurrentInstallationController(controller); |
| 125 | + ParseObject.State state = new ParseObject.State.Builder("_Installation") |
| 126 | + .put("deviceToken", "deviceToken") |
| 127 | + .build(); |
| 128 | + ParseInstallation installation = ParseInstallation.getCurrentInstallation(); |
| 129 | + assertNotNull(installation); |
| 130 | + installation.setState(state); |
| 131 | + |
| 132 | + ParseObjectController objController = mock(ParseObjectController.class); |
| 133 | + // mock return task when Installation was deleted on the server |
| 134 | + Task<ParseObject.State> taskError = Task.forError(new ParseException(ParseException.OBJECT_NOT_FOUND, "")); |
| 135 | + // mock return task when Installation was re-saved to the server |
| 136 | + Task<ParseObject.State> task = Task.forResult(null); |
| 137 | + when(objController.saveAsync( |
| 138 | + any(ParseObject.State.class), |
| 139 | + any(ParseOperationSet.class), |
| 140 | + eq(sessionToken), |
| 141 | + any(ParseDecoder.class))) |
| 142 | + .thenReturn(taskError) |
| 143 | + .thenReturn(task); |
| 144 | + ParseCorePlugins.getInstance() |
| 145 | + .registerObjectController(objController); |
| 146 | + |
| 147 | + installation.saveAsync(sessionToken, toAwait); |
| 148 | + |
| 149 | + verify(controller, times(1)).getAsync(); |
| 150 | + verify(objController, times(2)).saveAsync( |
| 151 | + any(ParseObject.State.class), |
| 152 | + any(ParseOperationSet.class), |
| 153 | + eq(sessionToken), |
| 154 | + any(ParseDecoder.class)); |
| 155 | + } |
| 156 | + |
111 | 157 | @Test
|
112 | 158 | public void testHandleSaveResultAsync() throws Exception {
|
113 | 159 | // Mock currentInstallationController to make setAsync work
|
|
0 commit comments