|
8 | 8 | */
|
9 | 9 | package com.parse;
|
10 | 10 |
|
| 11 | +import org.json.JSONException; |
11 | 12 | import org.json.JSONObject;
|
12 | 13 | import org.junit.Test;
|
| 14 | +import org.mockito.internal.util.collections.Sets; |
13 | 15 | import org.skyscreamer.jsonassert.JSONAssert;
|
14 | 16 | import org.skyscreamer.jsonassert.JSONCompareMode;
|
15 | 17 |
|
|
20 | 22 | import java.util.Set;
|
21 | 23 |
|
22 | 24 | import static org.junit.Assert.assertEquals;
|
| 25 | +import static org.junit.Assert.assertFalse; |
| 26 | +import static org.junit.Assert.assertNotSame; |
| 27 | +import static org.junit.Assert.assertSame; |
23 | 28 | import static org.junit.Assert.assertTrue;
|
24 | 29 | import static org.junit.Assert.fail;
|
| 30 | +import static org.mockito.Mockito.mock; |
| 31 | +import static org.mockito.Mockito.when; |
25 | 32 |
|
26 | 33 | public class ParsePushStateTest {
|
27 | 34 |
|
@@ -56,6 +63,38 @@ public void testDefaultsWithData() throws Exception {
|
56 | 63 |
|
57 | 64 | //endregion
|
58 | 65 |
|
| 66 | + @Test |
| 67 | + public void testCopy() throws JSONException { |
| 68 | + ParsePush.State state = mock(ParsePush.State.class); |
| 69 | + when(state.expirationTime()).thenReturn(1L); |
| 70 | + when(state.expirationTimeInterval()).thenReturn(2L); |
| 71 | + Set channelSet = Sets.newSet("one", "two"); |
| 72 | + when(state.channelSet()).thenReturn(channelSet); |
| 73 | + JSONObject data = new JSONObject(); |
| 74 | + data.put("foo", "bar"); |
| 75 | + when(state.data()).thenReturn(data); |
| 76 | + when(state.pushToAndroid()).thenReturn(true); |
| 77 | + when(state.pushToIOS()).thenReturn(false); |
| 78 | + ParseQuery.State<ParseInstallation> queryState = |
| 79 | + new ParseQuery.State.Builder<>(ParseInstallation.class).build(); |
| 80 | + when(state.queryState()).thenReturn(queryState); |
| 81 | + |
| 82 | + ParsePush.State copy = new ParsePush.State.Builder(state).build(); |
| 83 | + assertSame(1L, copy.expirationTime()); |
| 84 | + assertSame(2L, copy.expirationTimeInterval()); |
| 85 | + Set channelSetCopy = copy.channelSet(); |
| 86 | + assertNotSame(channelSet, channelSetCopy); |
| 87 | + assertTrue(channelSetCopy.size() == 2 && channelSetCopy.contains("one")); |
| 88 | + JSONObject dataCopy = copy.data(); |
| 89 | + assertNotSame(data, dataCopy); |
| 90 | + assertEquals("bar", dataCopy.get("foo")); |
| 91 | + assertTrue(copy.pushToAndroid()); |
| 92 | + assertFalse(copy.pushToIOS()); |
| 93 | + ParseQuery.State<ParseInstallation> queryStateCopy = copy.queryState(); |
| 94 | + assertNotSame(queryState, queryStateCopy); |
| 95 | + assertEquals("_Installation", queryStateCopy.className()); |
| 96 | + } |
| 97 | + |
59 | 98 | //region testExpirationTime
|
60 | 99 |
|
61 | 100 | @Test
|
|
0 commit comments