Browse Source

fixed promise reject not called when mapped

tags/v0.2.1
Robin Thoni 8 years ago
parent
commit
66b99bbe38

+ 4
- 9
luticateutils/src/main/java/com/luticate/utils/business/LuPromise.java View File

94
             public void execute(T data) {
94
             public void execute(T data) {
95
                 promise.resolve(converter.convert(data));
95
                 promise.resolve(converter.convert(data));
96
             }
96
             }
97
-        }, getRejectConsumer());
98
-        return promise;
99
-    }
100
-
101
-    public LuConsumer<LuPromiseError> getRejectConsumer()
102
-    {
103
-        return new LuConsumer<LuPromiseError>() {
97
+        },new LuConsumer<LuPromiseError>() {
104
             @Override
98
             @Override
105
             public void execute(LuPromiseError error) {
99
             public void execute(LuPromiseError error) {
106
-                reject(error);
100
+                promise.reject(error);
107
             }
101
             }
108
-        };
102
+        });
103
+        return promise;
109
     }
104
     }
110
 
105
 
111
     protected void onSuccess()
106
     protected void onSuccess()

+ 27
- 2
luticateutils/src/test/java/com/luticate/utils/PromiseTest.java View File

155
     }
155
     }
156
 
156
 
157
     @Test
157
     @Test
158
-    public void mapTest()
158
+    public void mapTestResolve()
159
     {
159
     {
160
         LuPromise<Integer> promise = new LuPromise<>();
160
         LuPromise<Integer> promise = new LuPromise<>();
161
         final int[] result = new int[1];
161
         final int[] result = new int[1];
176
             }
176
             }
177
         });
177
         });
178
         promise.resolve(42);
178
         promise.resolve(42);
179
-        assertEquals(result[0], 4242);
179
+        assertEquals(4242, result[0]);
180
+    }
181
+
182
+    @Test
183
+    public void mapTestReject()
184
+    {
185
+        LuPromise<Integer> promise = new LuPromise<>();
186
+        final int[] result = new int[1];
187
+        promise.map(new LuConverter<Integer, Boolean>() {
188
+            @Override
189
+            public Boolean convert(Integer data) {
190
+                return data == 42;
191
+            }
192
+        }).then(new LuConsumer<Boolean>() {
193
+            @Override
194
+            public void execute(Boolean data) {
195
+                result[0] = data ? 4242 : 2424;
196
+            }
197
+        }, new LuConsumer<LuPromiseError>() {
198
+            @Override
199
+            public void execute(LuPromiseError data) {
200
+                result[0] = 2442;
201
+            }
202
+        });
203
+        promise.reject(null);
204
+        assertEquals(2442, result[0]);
180
     }
205
     }
181
 }
206
 }

Loading…
Cancel
Save