< prev index next >

test/java/util/Spliterator/SpliteratorLateBindingFailFastTest.java

Print this page


   1 /*
   2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  35 import java.util.LinkedHashSet;
  36 import java.util.LinkedList;
  37 import java.util.List;
  38 import java.util.Map;
  39 import java.util.PriorityQueue;
  40 import java.util.Set;
  41 import java.util.Spliterator;
  42 import java.util.Stack;
  43 import java.util.TreeMap;
  44 import java.util.TreeSet;
  45 import java.util.Vector;
  46 import java.util.WeakHashMap;
  47 import java.util.function.Consumer;
  48 import java.util.function.Function;
  49 import java.util.function.Supplier;
  50 
  51 import static org.testng.Assert.*;
  52 
  53 /**
  54  * @test

  55  * @summary Spliterator last-binding and fail-fast tests
  56  * @run testng SpliteratorLateBindingFailFastTest
  57  */
  58 
  59 @Test
  60 public class SpliteratorLateBindingFailFastTest {
  61 
  62     private interface Source<T> {
  63         Collection<T> asCollection();
  64         void update();
  65     }
  66 
  67     private static class SpliteratorDataBuilder<T> {
  68         final List<Object[]> data;
  69 
  70         final T newValue;
  71 
  72         final List<T> exp;
  73 
  74         final Map<T, T> mExp;


 103                     this.updater = updater;
 104                 }
 105 
 106                 @Override
 107                 public Collection<T> asCollection() {
 108                     return c;
 109                 }
 110 
 111                 @Override
 112                 public void update() {
 113                     updater.accept(c);
 114                 }
 115             }
 116 
 117             String description = "new " + f.apply(Collections.<T>emptyList()).getClass().getName() + ".spliterator() ";
 118             add(description + "ADD", () -> new CollectionSource(c -> c.add(newValue)));
 119             add(description + "REMOVE", () -> new CollectionSource(c -> c.remove(c.iterator().next())));
 120         }
 121 
 122         void addList(Function<Collection<T>, ? extends List<T>> l) {
 123             // @@@ If collection is instance of List then add sub-list tests
 124             addCollection(l);

 125         }
 126 
 127         void addMap(Function<Map<T, T>, ? extends Map<T, T>> mapConstructor) {
 128             class MapSource<U> implements Source<U> {
 129                 final Map<T, T> m = mapConstructor.apply(mExp);
 130 
 131                 final Collection<U> c;
 132 
 133                 final Consumer<Map<T, T>> updater;
 134 
 135                 MapSource(Function<Map<T, T>, Collection<U>> f, Consumer<Map<T, T>> updater) {
 136                     this.c = f.apply(m);
 137                     this.updater = updater;
 138                 }
 139 
 140                 @Override
 141                 public Collection<U> asCollection() {
 142                     return c;
 143                 }
 144 


   1 /*
   2  * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  35 import java.util.LinkedHashSet;
  36 import java.util.LinkedList;
  37 import java.util.List;
  38 import java.util.Map;
  39 import java.util.PriorityQueue;
  40 import java.util.Set;
  41 import java.util.Spliterator;
  42 import java.util.Stack;
  43 import java.util.TreeMap;
  44 import java.util.TreeSet;
  45 import java.util.Vector;
  46 import java.util.WeakHashMap;
  47 import java.util.function.Consumer;
  48 import java.util.function.Function;
  49 import java.util.function.Supplier;
  50 
  51 import static org.testng.Assert.*;
  52 
  53 /**
  54  * @test
  55  * @bug 8148748
  56  * @summary Spliterator last-binding and fail-fast tests
  57  * @run testng SpliteratorLateBindingFailFastTest
  58  */
  59 
  60 @Test
  61 public class SpliteratorLateBindingFailFastTest {
  62 
  63     private interface Source<T> {
  64         Collection<T> asCollection();
  65         void update();
  66     }
  67 
  68     private static class SpliteratorDataBuilder<T> {
  69         final List<Object[]> data;
  70 
  71         final T newValue;
  72 
  73         final List<T> exp;
  74 
  75         final Map<T, T> mExp;


 104                     this.updater = updater;
 105                 }
 106 
 107                 @Override
 108                 public Collection<T> asCollection() {
 109                     return c;
 110                 }
 111 
 112                 @Override
 113                 public void update() {
 114                     updater.accept(c);
 115                 }
 116             }
 117 
 118             String description = "new " + f.apply(Collections.<T>emptyList()).getClass().getName() + ".spliterator() ";
 119             add(description + "ADD", () -> new CollectionSource(c -> c.add(newValue)));
 120             add(description + "REMOVE", () -> new CollectionSource(c -> c.remove(c.iterator().next())));
 121         }
 122 
 123         void addList(Function<Collection<T>, ? extends List<T>> l) {

 124             addCollection(l);
 125             addCollection(l.andThen(list -> list.subList(0, list.size())));
 126         }
 127 
 128         void addMap(Function<Map<T, T>, ? extends Map<T, T>> mapConstructor) {
 129             class MapSource<U> implements Source<U> {
 130                 final Map<T, T> m = mapConstructor.apply(mExp);
 131 
 132                 final Collection<U> c;
 133 
 134                 final Consumer<Map<T, T>> updater;
 135 
 136                 MapSource(Function<Map<T, T>, Collection<U>> f, Consumer<Map<T, T>> updater) {
 137                     this.c = f.apply(m);
 138                     this.updater = updater;
 139                 }
 140 
 141                 @Override
 142                 public Collection<U> asCollection() {
 143                     return c;
 144                 }
 145 


< prev index next >