Skip to content

Commit

Permalink
rename asLeftOptional to optionalList
Browse files Browse the repository at this point in the history
  • Loading branch information
h908714124 committed Jul 19, 2021
1 parent 2827d2c commit 19253b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/io/jbock/util/Either.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static <L, R> Either<L, R> right(R value) {
* @return an {@code Optional} which is empty if and only if {@code failures}
* is empty
*/
public static <L> Optional<List<L>> asLeftOptional(List<? extends L> failures) {
public static <L> Optional<List<L>> optionalList(List<? extends L> failures) {
if (failures.isEmpty()) {
return Optional.empty();
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/io/jbock/util/EitherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

Expand Down Expand Up @@ -134,4 +135,11 @@ void testOrElseThrow() {
Either<String, String> right = Either.right("2");
assertEquals("2", right.orElseThrow(IllegalArgumentException::new));
}

@Test
void testOptionalList() {
assertEquals(Optional.empty(), Either.optionalList(List.of()));
assertEquals(Optional.of(List.of(1)), Either.optionalList(List.of(1)));
assertEquals(Optional.of(List.of("1", "2")), Either.optionalList(List.of("1", "2")));
}
}

0 comments on commit 19253b7

Please sign in to comment.