[COLLECTIONS-737]: Return 0 immeditaly if the given iterable is null in IterableUtils#size. Update tests.
This commit is contained in:
parent
e20e373fe0
commit
3d8d96c7d2
|
@ -797,6 +797,9 @@ public class IterableUtils {
|
|||
* @return the number of elements contained in the iterable
|
||||
*/
|
||||
public static int size(final Iterable<?> iterable) {
|
||||
if (iterable == null) {
|
||||
return 0;
|
||||
}
|
||||
if (iterable instanceof Collection<?>) {
|
||||
return ((Collection<?>) iterable).size();
|
||||
}
|
||||
|
|
|
@ -416,12 +416,6 @@ public class FluentIterableTest {
|
|||
|
||||
@Test
|
||||
public void size() {
|
||||
try {
|
||||
FluentIterable.of((Iterable<?>) null).size();
|
||||
fail("expecting NullPointerException");
|
||||
} catch (final NullPointerException npe) {
|
||||
// expected
|
||||
}
|
||||
assertEquals(0, FluentIterable.of(emptyIterable).size());
|
||||
assertEquals(IterableUtils.toList(iterableOdd).size(), FluentIterable.of(iterableOdd).size());
|
||||
}
|
||||
|
|
|
@ -579,4 +579,9 @@ public class IterableUtilsTest {
|
|||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void size() {
|
||||
assertEquals(0, IterableUtils.size(null));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue