Skip to content

Commit bd33df2

Browse files
committed
Add method Result.isSuccessfulNonEmpty() to verify that result is successful and non empty.
1 parent b42259c commit bd33df2

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

result/src/main/java/com/amatkivskiy/result/Result.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ public abstract class Result<V, E> {
2323
*/
2424
public abstract boolean isEmpty();
2525

26+
/**
27+
* @return true if successful non empty @{@link Result}, false otherwise.
28+
*/
29+
public boolean isSuccessfulNonEmpty() {
30+
return isSuccess() && !isEmpty();
31+
}
32+
2633
// Syntactic sugar
2734

2835
/**

result/src/test/java/com/amatkivskiy/result/ResultTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@ public class ResultTests {
235235
assertThat(Result.<String, String>failure(OOOH_NOOO).or(OOOH_YEAH), is(OOOH_YEAH));
236236
}
237237

238+
@Test public void testIsSuccessfulAndEmptyCorrect() throws Exception {
239+
assertThat(Result.success(null).isSuccessfulNonEmpty(), is(false));
240+
241+
assertThat(Result.success(1).isSuccessfulNonEmpty(), is(true));
242+
243+
assertThat(Result.failure(1).isSuccessfulNonEmpty(), is(false));
244+
245+
assertThat(Result.failure(null).isSuccessfulNonEmpty(), is(false));
246+
}
247+
238248
static class DefaultThrowerImpl<T> implements Function<T> {
239249
@Override public T call() {
240250
return null;

0 commit comments

Comments
 (0)