Path: blob/master/test/jdk/java/util/Iterator/PrimitiveIteratorDefaults.java
41149 views
/*1* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.util.PrimitiveIterator;24import java.util.function.Consumer;25import java.util.function.DoubleConsumer;26import java.util.function.IntConsumer;27import java.util.function.LongConsumer;2829import org.testng.Assert.ThrowingRunnable;30import org.testng.annotations.Test;3132import static org.testng.Assert.assertThrows;3334/**35* @test36* @run testng PrimitiveIteratorDefaults37* @summary test default methods on PrimitiveIterator38*/39@Test40public class PrimitiveIteratorDefaults {4142public void testIntForEachRemainingWithNull() {43PrimitiveIterator.OfInt i = new PrimitiveIterator.OfInt() {44@Override45public int nextInt() {46return 0;47}4849@Override50public boolean hasNext() {51return false;52}53};5455assertThrowsNPE(() -> i.forEachRemaining((IntConsumer) null));56assertThrowsNPE(() -> i.forEachRemaining((Consumer<Integer>) null));57}5859public void testLongForEachRemainingWithNull() {60PrimitiveIterator.OfLong i = new PrimitiveIterator.OfLong() {61@Override62public long nextLong() {63return 0;64}6566@Override67public boolean hasNext() {68return false;69}70};7172assertThrowsNPE(() -> i.forEachRemaining((LongConsumer) null));73assertThrowsNPE(() -> i.forEachRemaining((Consumer<Long>) null));74}7576public void testDoubleForEachRemainingWithNull() {77PrimitiveIterator.OfDouble i = new PrimitiveIterator.OfDouble() {78@Override79public double nextDouble() {80return 0;81}8283@Override84public boolean hasNext() {85return false;86}87};8889assertThrowsNPE(() -> i.forEachRemaining((DoubleConsumer) null));90assertThrowsNPE(() -> i.forEachRemaining((Consumer<Double>) null));91}9293private void assertThrowsNPE(ThrowingRunnable r) {94assertThrows(NullPointerException.class, r);95}9697}9899100