Skip to content

Commit

Permalink
Add method Result.isSuccessfulNonEmpty() to verify that result is suc…
Browse files Browse the repository at this point in the history
…cessful and non empty.
  • Loading branch information
amatkivskiy committed Jul 22, 2017
1 parent b42259c commit bd33df2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions result/src/main/java/com/amatkivskiy/result/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ public abstract class Result<V, E> {
*/
public abstract boolean isEmpty();

/**
* @return true if successful non empty @{@link Result}, false otherwise.
*/
public boolean isSuccessfulNonEmpty() {
return isSuccess() && !isEmpty();
}

// Syntactic sugar

/**
Expand Down
10 changes: 10 additions & 0 deletions result/src/test/java/com/amatkivskiy/result/ResultTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ public class ResultTests {
assertThat(Result.<String, String>failure(OOOH_NOOO).or(OOOH_YEAH), is(OOOH_YEAH));
}

@Test public void testIsSuccessfulAndEmptyCorrect() throws Exception {
assertThat(Result.success(null).isSuccessfulNonEmpty(), is(false));

assertThat(Result.success(1).isSuccessfulNonEmpty(), is(true));

assertThat(Result.failure(1).isSuccessfulNonEmpty(), is(false));

assertThat(Result.failure(null).isSuccessfulNonEmpty(), is(false));
}

static class DefaultThrowerImpl<T> implements Function<T> {
@Override public T call() {
return null;
Expand Down

0 comments on commit bd33df2

Please sign in to comment.