< prev index next > test/jdk/java/util/Collections/SingletonIterator.java
Print this page
/*
! * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
/*
! * Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*/
/*
* @test
* @bug 8024500 8166446
+ * @library /test/lib
* @run testng SingletonIterator
*/
+ import jdk.test.lib.valueclass.VClass;
import java.util.Collections;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.concurrent.atomic.AtomicInteger;
import org.testng.annotations.Test;
assertIteratorExhausted(it);
}
static class SingletonException extends RuntimeException { }
+ @Test
+ public void testValueSingletonIterator() {
+ Iterator<VClass> it = Collections.singleton(new VClass(42, new int[] { 42 })).iterator();
+ AtomicInteger cnt = new AtomicInteger(0);
+ it.forEachRemaining(v -> {
+ if (!v.equals(new VClass(42, new int[] { 42 }))) throw new RuntimeException("wrong value");
+ cnt.incrementAndGet();
+ });
+ assertEquals(cnt.get(), 1);
+ assertIteratorExhausted(it);
+ }
+
public void testThrowFromForEachRemaining() {
Iterator<String> it = Collections.singleton("TheOne").iterator();
try {
it.forEachRemaining(s -> { throw new SingletonException(); });
< prev index next >