Skip to content

Commit

Permalink
API: Align error messages in CloseableIterable and CloseableIterator (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nastra authored Aug 7, 2022
1 parent f309de0 commit ef9b770
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
public interface CloseableIterable<T> extends Iterable<T>, Closeable {

/**
* Returns an closeable iterator over elements of type {@code T}.
* Returns a closeable iterator over elements of type {@code T}.
*
* @return an {@link CloseableIterator}.
*/
Expand Down Expand Up @@ -85,8 +85,7 @@ public CloseableIterator<E> iterator() {
*/
static <E> CloseableIterable<E> whenComplete(
CloseableIterable<E> iterable, Runnable onCompletionRunnable) {
Preconditions.checkNotNull(
onCompletionRunnable, "Cannot execute a null Runnable after completion");
Preconditions.checkNotNull(onCompletionRunnable, "Invalid runnable: null");
return new CloseableIterable<E>() {
@Override
public void close() throws IOException {
Expand Down Expand Up @@ -177,7 +176,7 @@ public void close() throws IOException {

static <I, O> CloseableIterable<O> transform(
CloseableIterable<I> iterable, Function<I, O> transform) {
Preconditions.checkNotNull(transform, "Cannot apply a null transform");
Preconditions.checkNotNull(transform, "Invalid transform: null");

return new CloseableIterable<O>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public E next() {

static <I, O> CloseableIterator<O> transform(
CloseableIterator<I> iterator, Function<I, O> transform) {
Preconditions.checkNotNull(transform, "Cannot apply a null transform");
Preconditions.checkNotNull(transform, "Invalid transform: null");

return new CloseableIterator<O>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void testWithCompletionRunnable() throws IOException {
Assertions.assertThatThrownBy(
() -> CloseableIterable.whenComplete(CloseableIterable.combine(items, () -> {}), null))
.isInstanceOf(NullPointerException.class)
.hasMessage("Cannot execute a null Runnable after completion");
.hasMessage("Invalid runnable: null");

try (CloseableIterable<Integer> iter =
CloseableIterable.whenComplete(
Expand Down Expand Up @@ -260,4 +260,12 @@ public void countSkippedNullCheck() {
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Invalid predicate: null");
}

@Test
public void transformNullCheck() {
Assertions.assertThatThrownBy(
() -> CloseableIterable.transform(CloseableIterable.empty(), null))
.isInstanceOf(NullPointerException.class)
.hasMessage("Invalid transform: null");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.assertj.core.api.Assertions;
import org.junit.Test;

public class TestClosingIterator {
Expand Down Expand Up @@ -67,4 +68,12 @@ public void testCloseCalledOnceForMultipleHasNextCalls() throws Exception {
assertFalse(closingIterator.hasNext());
verify(underlying, times(1)).close();
}

@Test
public void transformNullCheck() {
Assertions.assertThatThrownBy(
() -> CloseableIterator.transform(CloseableIterator.empty(), null))
.isInstanceOf(NullPointerException.class)
.hasMessage("Invalid transform: null");
}
}

0 comments on commit ef9b770

Please sign in to comment.