diff --git a/src/main/java/org/cactoos/list/Max.java b/src/main/java/org/cactoos/list/Max.java index 94ca78c6d0..53404d9efa 100644 --- a/src/main/java/org/cactoos/list/Max.java +++ b/src/main/java/org/cactoos/list/Max.java @@ -23,8 +23,8 @@ */ package org.cactoos.list; -import java.io.IOException; import java.util.Iterator; +import java.util.NoSuchElementException; import org.cactoos.Scalar; /** @@ -65,7 +65,9 @@ public Max(final Iterable> items) { public T value() throws Exception { final Iterator> iter = this.items.iterator(); if (!iter.hasNext()) { - throw new IOException("Iterable is empty"); + throw new NoSuchElementException( + "Can't find greater element in an empty iterable" + ); } T max = iter.next().value(); while (iter.hasNext()) { diff --git a/src/main/java/org/cactoos/list/Min.java b/src/main/java/org/cactoos/list/Min.java index 9c5590e77b..540b7e6d15 100644 --- a/src/main/java/org/cactoos/list/Min.java +++ b/src/main/java/org/cactoos/list/Min.java @@ -23,8 +23,8 @@ */ package org.cactoos.list; -import java.io.IOException; import java.util.Iterator; +import java.util.NoSuchElementException; import org.cactoos.Scalar; /** @@ -65,7 +65,9 @@ public Min(final Iterable> items) { public T value() throws Exception { final Iterator> iter = this.items.iterator(); if (!iter.hasNext()) { - throw new IOException("Iterable is empty"); + throw new NoSuchElementException( + "Can't find smaller element in an empty iterable" + ); } T min = iter.next().value(); while (iter.hasNext()) { diff --git a/src/test/java/org/cactoos/list/MaxTest.java b/src/test/java/org/cactoos/list/MaxTest.java index 682b95117d..ed247b42fd 100644 --- a/src/test/java/org/cactoos/list/MaxTest.java +++ b/src/test/java/org/cactoos/list/MaxTest.java @@ -23,8 +23,8 @@ */ package org.cactoos.list; -import java.io.IOException; import java.util.Collections; +import java.util.NoSuchElementException; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; @@ -39,7 +39,7 @@ */ public final class MaxTest { - @Test(expected = IOException.class) + @Test(expected = NoSuchElementException.class) public void maxAmongEmptyTest() throws Exception { new Max<>(() -> Collections.emptyIterator()).value(); } diff --git a/src/test/java/org/cactoos/list/MinTest.java b/src/test/java/org/cactoos/list/MinTest.java index f1da4818a7..8cfa43c61d 100644 --- a/src/test/java/org/cactoos/list/MinTest.java +++ b/src/test/java/org/cactoos/list/MinTest.java @@ -23,8 +23,8 @@ */ package org.cactoos.list; -import java.io.IOException; import java.util.Collections; +import java.util.NoSuchElementException; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; @@ -39,7 +39,7 @@ */ public final class MinTest { - @Test(expected = IOException.class) + @Test(expected = NoSuchElementException.class) public void minAmongEmptyTest() throws Exception { new Min<>(() -> Collections.emptyIterator()).value(); }