diff --git a/result/src/main/java/com/amatkivskiy/result/Result.java b/result/src/main/java/com/amatkivskiy/result/Result.java index e10b90d..1afb59b 100644 --- a/result/src/main/java/com/amatkivskiy/result/Result.java +++ b/result/src/main/java/com/amatkivskiy/result/Result.java @@ -23,6 +23,13 @@ public abstract class Result { */ public abstract boolean isEmpty(); + /** + * @return true if successful non empty @{@link Result}, false otherwise. + */ + public boolean isSuccessfulNonEmpty() { + return isSuccess() && !isEmpty(); + } + // Syntactic sugar /** diff --git a/result/src/test/java/com/amatkivskiy/result/ResultTests.java b/result/src/test/java/com/amatkivskiy/result/ResultTests.java index 537458f..646411b 100644 --- a/result/src/test/java/com/amatkivskiy/result/ResultTests.java +++ b/result/src/test/java/com/amatkivskiy/result/ResultTests.java @@ -235,6 +235,16 @@ public class ResultTests { assertThat(Result.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 implements Function { @Override public T call() { return null;