Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Dec 28, 2020
2 parents 5580372 + e88a65a commit 82b728a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main/java/org/cactoos/list/ListIteratorNoNulls.java
Expand Up @@ -33,8 +33,6 @@
*
* @param <T> Element type
* @since 0.39
* @todo #1247:30min Add also some null checks both to the `set` and
* the `add` methods, then also add some tests to validate this behaviour.
*/
public final class ListIteratorNoNulls<T> implements ListIterator<T> {

Expand Down Expand Up @@ -97,11 +95,21 @@ public void remove() {

@Override
public void set(final T item) {
if (item == null) {
throw new IllegalArgumentException(
"Item can't be NULL in #set(T)"
);
}
this.listiterator.set(item);
}

@Override
public void add(final T item) {
if (item == null) {
throw new IllegalArgumentException(
"Item can't be NULL in #add(T)"
);
}
this.listiterator.add(item);
}

Expand Down
34 changes: 34 additions & 0 deletions src/test/java/org/cactoos/list/ListIteratorNoNullsTest.java
Expand Up @@ -135,4 +135,38 @@ void mustSetValueListIterator() {
new ScalarHasValue<>(4)
).affirm();
}

@Test
void mustThrowsErrorIfAddANullItem() {
new Assertion<>(
"must throw error if add a null item",
() -> {
new ListIteratorNoNulls<>(
new ListOf<>(1, 2, 3).listIterator()
).add(null);
return 0;
},
new Throws<>(
"Item can't be NULL in #add(T)",
IllegalArgumentException.class
)
).affirm();
}

@Test
void mustThrowsErrorIfSetANullItem() {
new Assertion<>(
"must throw error if set a null item",
() -> {
new ListIteratorNoNulls<>(
new ListOf<>(1, 2, 3).listIterator()
).set(null);
return 0;
},
new Throws<>(
"Item can't be NULL in #set(T)",
IllegalArgumentException.class
)
).affirm();
}
}

1 comment on commit 82b728a

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 82b728a Dec 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1247-25d91c9c disappeared from src/main/java/org/cactoos/list/ListIteratorNoNulls.java, that's why I closed #1459. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.