|
12 | 12 |
|
13 | 13 | import org.junit.Test;
|
14 | 14 |
|
| 15 | +import java.util.ArrayList; |
| 16 | +import java.util.Collection; |
| 17 | +import java.util.Iterator; |
| 18 | + |
15 | 19 | import static org.junit.Assert.assertEquals;
|
16 | 20 | import static org.junit.Assert.assertFalse;
|
17 | 21 | import static org.junit.Assert.assertNull;
|
@@ -57,4 +61,60 @@ public void testNetworkInterceptors() {
|
57 | 61 | // Expected
|
58 | 62 | }
|
59 | 63 | }
|
| 64 | + |
| 65 | + @Test |
| 66 | + public void testSetNetworkInterceptors() { |
| 67 | + final ParseNetworkInterceptor interceptorA = mock(ParseNetworkInterceptor.class); |
| 68 | + final ParseNetworkInterceptor interceptorB = mock(ParseNetworkInterceptor.class); |
| 69 | + |
| 70 | + Collection<ParseNetworkInterceptor> collectionA = new ArrayList<ParseNetworkInterceptor>() {{ |
| 71 | + add(interceptorA); |
| 72 | + add(interceptorB); |
| 73 | + }}; |
| 74 | + |
| 75 | + Collection<ParseNetworkInterceptor> collectionB = new ArrayList<ParseNetworkInterceptor>() {{ |
| 76 | + add(interceptorB); |
| 77 | + add(interceptorA); |
| 78 | + }}; |
| 79 | + |
| 80 | + Parse.Configuration.Builder builder = new Parse.Configuration.Builder(null); |
| 81 | + |
| 82 | + builder.setNetworkInterceptors(collectionA); |
| 83 | + Parse.Configuration configurationA = builder.build(); |
| 84 | + |
| 85 | + builder.setNetworkInterceptors(collectionB); |
| 86 | + Parse.Configuration configurationB = builder.build(); |
| 87 | + |
| 88 | + assertTrue(collectionsEqual(configurationA.interceptors, collectionA)); |
| 89 | + assertTrue(collectionsEqual(configurationB.interceptors, collectionB)); |
| 90 | + } |
| 91 | + |
| 92 | + private static <T> boolean collectionsEqual(Collection<T> a, Collection<T> b) { |
| 93 | + if (a.size() != b.size()) { |
| 94 | + return false; |
| 95 | + } |
| 96 | + |
| 97 | + Iterator<T> iteratorA = a.iterator(); |
| 98 | + Iterator<T> iteratorB = b.iterator(); |
| 99 | + for (; iteratorA.hasNext() && iteratorB.hasNext();) { |
| 100 | + T objectA = iteratorA.next(); |
| 101 | + T objectB = iteratorB.next(); |
| 102 | + |
| 103 | + if (objectA == null || objectB == null) { |
| 104 | + if (objectA != objectB) { |
| 105 | + return false; |
| 106 | + } |
| 107 | + continue; |
| 108 | + } |
| 109 | + |
| 110 | + if (!objectA.equals(objectB)) { |
| 111 | + return false; |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + if (iteratorA.hasNext() || iteratorB.hasNext()) { |
| 116 | + return false; |
| 117 | + } |
| 118 | + return true; |
| 119 | + } |
60 | 120 | }
|
0 commit comments