Skip to content

Commit

Permalink
Exclude varargs from Promise.reject and Promise.resolve and their tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
riversun committed May 2, 2019
1 parent d804c10 commit 32ad141
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 28 deletions.
32 changes: 24 additions & 8 deletions src/main/java/org/riversun/promise/Promise.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 24 additions & 8 deletions src/main/java/org/riversun/promise/SyncPromise.java
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/riversun/promise/TestPromiseAllAsync.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/riversun/promise/TestPromiseAllSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
12 changes: 10 additions & 2 deletions src/test/java/org/riversun/promise/TestPromiseAllTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/riversun/promise/TestPromiseAsync.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/riversun/promise/TestPromiseSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
12 changes: 10 additions & 2 deletions src/test/java/org/riversun/promise/TestPromiseTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 32ad141

Please sign in to comment.