Quellcode durchsuchen

fixed promise reject not called when mapped

tags/v0.2.1
Robin Thoni vor 8 Jahren
Ursprung
Commit
66b99bbe38

+ 4
- 9
luticateutils/src/main/java/com/luticate/utils/business/LuPromise.java Datei anzeigen

@@ -94,18 +94,13 @@ public class LuPromise<T> {
94 94
             public void execute(T data) {
95 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 98
             @Override
105 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 106
     protected void onSuccess()

+ 27
- 2
luticateutils/src/test/java/com/luticate/utils/PromiseTest.java Datei anzeigen

@@ -155,7 +155,7 @@ public class PromiseTest {
155 155
     }
156 156
 
157 157
     @Test
158
-    public void mapTest()
158
+    public void mapTestResolve()
159 159
     {
160 160
         LuPromise<Integer> promise = new LuPromise<>();
161 161
         final int[] result = new int[1];
@@ -176,6 +176,31 @@ public class PromiseTest {
176 176
             }
177 177
         });
178 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
 }

Laden…
Abbrechen
Speichern