From 32ad141de4ab68cd459aaae4023b46a826e46b2b Mon Sep 17 00:00:00 2001 From: riversun Date: Thu, 2 May 2019 18:55:43 +0900 Subject: [PATCH] Exclude varargs from Promise.reject and Promise.resolve and their tests. --- .../java/org/riversun/promise/Promise.java | 32 ++++++++++++++----- .../org/riversun/promise/SyncPromise.java | 32 ++++++++++++++----- .../riversun/promise/TestPromiseAllAsync.java | 4 +-- .../riversun/promise/TestPromiseAllSync.java | 4 +-- .../promise/TestPromiseAllTestCase.java | 12 +++++-- .../riversun/promise/TestPromiseAsync.java | 4 +-- .../org/riversun/promise/TestPromiseSync.java | 4 +-- .../riversun/promise/TestPromiseTestCase.java | 12 +++++-- 8 files changed, 76 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/riversun/promise/Promise.java b/src/main/java/org/riversun/promise/Promise.java index fad91db..d71e7e5 100644 --- a/src/main/java/org/riversun/promise/Promise.java +++ b/src/main/java/org/riversun/promise/Promise.java @@ -361,30 +361,46 @@ public Object getValue() { * @param data * @return */ - public static Promise resolve(Object... data) { + public static Promise resolve(Object data) { final Promise promise = new Promise(); promise.mStatus = Status.FULFILLED; - if (data != null && data.length > 0) { - promise.mResult = data[0]; - } + promise.mResult = data; return promise; } + /** + * Returns a Promise object that is resolved with null value + * + * @param data + * @return + */ + public static Promise resolve() { + return resolve(null); + } + /** * Returns a Promise object that is rejected with a given reason. * * @param reason * @return */ - public static Promise reject(Object... reason) { + public static Promise reject(Object reason) { final Promise promise = new Promise(); promise.mStatus = Status.REJECTED; - if (reason != null && reason.length > 0) { - promise.mResult = reason[0]; - } + promise.mResult = reason; return promise; } + /** + * Returns a Promise object that is rejected with null reason. + * + * @param reason + * @return + */ + public static Promise reject() { + return reject(null); + } + private static final class Holder { public Object result; public boolean rejected = false; diff --git a/src/main/java/org/riversun/promise/SyncPromise.java b/src/main/java/org/riversun/promise/SyncPromise.java index f842fa1..e631f2b 100644 --- a/src/main/java/org/riversun/promise/SyncPromise.java +++ b/src/main/java/org/riversun/promise/SyncPromise.java @@ -285,30 +285,46 @@ public Object getValue() { * @param data * @return */ - public static SyncPromise resolve(Object... data) { + public static SyncPromise resolve(Object data) { final SyncPromise promise = new SyncPromise(); promise.mStatus = Status.FULFILLED; - if (data != null && data.length > 0) { - promise.mResult = data[0]; - } + promise.mResult = data; return promise; } + /** + * Returns a Promise object that is resolved with null value + * + * @param data + * @return + */ + public static SyncPromise resolve() { + return resolve(null); + } + /** * Returns a Promise object that is rejected with a given reason. * * @param reason * @return */ - public static SyncPromise reject(Object... reason) { + public static SyncPromise reject(Object reason) { final SyncPromise promise = new SyncPromise(); promise.mStatus = Status.REJECTED; - if (reason != null && reason.length > 0) { - promise.mResult = reason[0]; - } + promise.mResult = reason; return promise; } + /** + * Returns a Promise object that is rejected with null reason. + * + * @param reason + * @return + */ + public static SyncPromise reject() { + return reject(null); + } + /** * Promise.all waits for all fulfillments (or the first rejection). * diff --git a/src/test/java/org/riversun/promise/TestPromiseAllAsync.java b/src/test/java/org/riversun/promise/TestPromiseAllAsync.java index 1ac6e1b..6d1922e 100644 --- a/src/test/java/org/riversun/promise/TestPromiseAllAsync.java +++ b/src/test/java/org/riversun/promise/TestPromiseAllAsync.java @@ -41,12 +41,12 @@ public Thennable PromiseAll(Func... funcs) { } @Override - public Thennable PromiseResolve(Object... data) { + public Thennable PromiseResolve(Object data) { return Promise.resolve(data); } @Override - public Thennable PromiseReject(Object... data) { + public Thennable PromiseReject(Object data) { return Promise.reject(data); } diff --git a/src/test/java/org/riversun/promise/TestPromiseAllSync.java b/src/test/java/org/riversun/promise/TestPromiseAllSync.java index 05a0f60..11423e2 100644 --- a/src/test/java/org/riversun/promise/TestPromiseAllSync.java +++ b/src/test/java/org/riversun/promise/TestPromiseAllSync.java @@ -27,12 +27,12 @@ public Thennable PromiseAll(Func... funcs) { } @Override - public Thennable PromiseResolve(Object... data) { + public Thennable PromiseResolve(Object data) { return SyncPromise.resolve(data); } @Override - public Thennable PromiseReject(Object... data) { + public Thennable PromiseReject(Object data) { return SyncPromise.reject(data); } diff --git a/src/test/java/org/riversun/promise/TestPromiseAllTestCase.java b/src/test/java/org/riversun/promise/TestPromiseAllTestCase.java index 88b9ef8..7e8745c 100644 --- a/src/test/java/org/riversun/promise/TestPromiseAllTestCase.java +++ b/src/test/java/org/riversun/promise/TestPromiseAllTestCase.java @@ -20,9 +20,17 @@ public abstract class TestPromiseAllTestCase { public abstract Thennable PromiseAll(Func... funcs); - public abstract Thennable PromiseResolve(Object... data); + public abstract Thennable PromiseResolve(Object data); - public abstract Thennable PromiseReject(Object... data); + public Thennable PromiseResolve() { + return PromiseResolve(null); + } + + public abstract Thennable PromiseReject(Object data); + + public Thennable PromiseReject() { + return PromiseReject(null); + } public abstract void sync(Integer... counter); diff --git a/src/test/java/org/riversun/promise/TestPromiseAsync.java b/src/test/java/org/riversun/promise/TestPromiseAsync.java index 63a1ca7..6eb5ad4 100644 --- a/src/test/java/org/riversun/promise/TestPromiseAsync.java +++ b/src/test/java/org/riversun/promise/TestPromiseAsync.java @@ -10,12 +10,12 @@ public class TestPromiseAsync extends TestPromiseTestCase { @Override - public Thennable PromiseResolve(Object... value) { + public Thennable PromiseResolve(Object value) { return Promise.resolve(value); } @Override - public Thennable PromiseReject(Object... value) { + public Thennable PromiseReject(Object value) { return Promise.reject(value); } diff --git a/src/test/java/org/riversun/promise/TestPromiseSync.java b/src/test/java/org/riversun/promise/TestPromiseSync.java index 58624c6..5f762ae 100644 --- a/src/test/java/org/riversun/promise/TestPromiseSync.java +++ b/src/test/java/org/riversun/promise/TestPromiseSync.java @@ -8,13 +8,13 @@ public class TestPromiseSync extends TestPromiseTestCase { @Override - public Thennable PromiseResolve(Object... value) { + public Thennable PromiseResolve(Object value) { return SyncPromise.resolve(value); } @Override - public Thennable PromiseReject(Object... value) { + public Thennable PromiseReject(Object value) { return SyncPromise.reject(value); } diff --git a/src/test/java/org/riversun/promise/TestPromiseTestCase.java b/src/test/java/org/riversun/promise/TestPromiseTestCase.java index 7fb2b65..d459d72 100644 --- a/src/test/java/org/riversun/promise/TestPromiseTestCase.java +++ b/src/test/java/org/riversun/promise/TestPromiseTestCase.java @@ -11,9 +11,17 @@ */ public abstract class TestPromiseTestCase { - public abstract Thennable PromiseResolve(Object... value); + public abstract Thennable PromiseResolve(Object value); - public abstract Thennable PromiseReject(Object... value); + public Thennable PromiseResolve() { + return PromiseResolve(null); + } + + public abstract Thennable PromiseReject(Object value); + + public Thennable PromiseReject() { + return PromiseReject(null); + } public abstract void sync(Integer... counter);