test/java/util/Collection/MOAT.java

Print this page
rev 7461 : 7129185: Add Collections.{checked|empty|unmodifiable}Navigable{Map|Set}
Reviewed-by: dmocek, martin, smarks


  54 import java.io.*;
  55 import java.util.*;
  56 import java.util.concurrent.*;
  57 import static java.util.Collections.*;
  58 
  59 public class MOAT {
  60     public static void realMain(String[] args) {
  61 
  62         testCollection(new NewAbstractCollection<Integer>());
  63         testCollection(new NewAbstractSet<Integer>());
  64         testCollection(new LinkedHashSet<Integer>());
  65         testCollection(new HashSet<Integer>());
  66         testCollection(new Vector<Integer>());
  67         testCollection(new Vector<Integer>().subList(0,0));
  68         testCollection(new ArrayDeque<Integer>());
  69         testCollection(new ArrayList<Integer>());
  70         testCollection(new ArrayList<Integer>().subList(0,0));
  71         testCollection(new LinkedList<Integer>());
  72         testCollection(new LinkedList<Integer>().subList(0,0));
  73         testCollection(new TreeSet<Integer>());








  74 
  75         testCollection(new CopyOnWriteArrayList<Integer>());
  76         testCollection(new CopyOnWriteArrayList<Integer>().subList(0,0));
  77         testCollection(new CopyOnWriteArraySet<Integer>());
  78         testCollection(new PriorityQueue<Integer>());
  79         testCollection(new PriorityBlockingQueue<Integer>());
  80         testCollection(new ArrayBlockingQueue<Integer>(20));
  81         testCollection(new LinkedBlockingQueue<Integer>(20));
  82         testCollection(new LinkedBlockingDeque<Integer>(20));
  83         testCollection(new ConcurrentLinkedDeque<Integer>());
  84         testCollection(new ConcurrentLinkedQueue<Integer>());
  85         testCollection(new LinkedTransferQueue<Integer>());
  86         testCollection(new ConcurrentSkipListSet<Integer>());
  87         testCollection(Arrays.asList(new Integer(42)));
  88         testCollection(Arrays.asList(1,2,3));
  89         testCollection(nCopies(25,1));
  90         testImmutableList(nCopies(25,1));
  91         testImmutableList(unmodifiableList(Arrays.asList(1,2,3)));
  92 
  93         testMap(new HashMap<Integer,Integer>());
  94         testMap(new LinkedHashMap<Integer,Integer>());
  95         testMap(new WeakHashMap<Integer,Integer>());
  96         testMap(new IdentityHashMap<Integer,Integer>());
  97         testMap(new TreeMap<Integer,Integer>());
  98         testMap(new Hashtable<Integer,Integer>());
  99         testMap(new ConcurrentHashMap<Integer,Integer>(10, 0.5f));
 100         testMap(new ConcurrentSkipListMap<Integer,Integer>());






 101 
 102         // Empty collections
 103         final List<Integer> emptyArray = Arrays.asList(new Integer[]{});
 104         testCollection(emptyArray);
 105         testEmptyList(emptyArray);
 106         THROWS(IndexOutOfBoundsException.class,
 107                new Fun(){void f(){ emptyArray.set(0,1); }});
 108         THROWS(UnsupportedOperationException.class,
 109                new Fun(){void f(){ emptyArray.add(0,1); }});
 110 
 111         List<Integer> noOne = nCopies(0,1);
 112         testCollection(noOne);
 113         testEmptyList(noOne);
 114         testImmutableList(noOne);
 115 
 116         Set<Integer> emptySet = emptySet();
 117         testCollection(emptySet);
 118         testEmptySet(emptySet);
 119         testEmptySet(EMPTY_SET);



 120         testImmutableSet(emptySet);
 121 
 122         List<Integer> emptyList = emptyList();
 123         testCollection(emptyList);
 124         testEmptyList(emptyList);
 125         testEmptyList(EMPTY_LIST);

 126         testImmutableList(emptyList);
 127 
 128         Map<Integer,Integer> emptyMap = emptyMap();
 129         testMap(emptyMap);
 130         testEmptyMap(emptyMap);
 131         testEmptyMap(EMPTY_MAP);



 132         testImmutableMap(emptyMap);



 133 
 134         // Singleton collections
 135         Set<Integer> singletonSet = singleton(1);
 136         equal(singletonSet.size(), 1);
 137         testCollection(singletonSet);
 138         testImmutableSet(singletonSet);
 139 
 140         List<Integer> singletonList = singletonList(1);
 141         equal(singletonList.size(), 1);
 142         testCollection(singletonList);
 143         testImmutableList(singletonList);
 144         testImmutableList(singletonList.subList(0,1));
 145         testImmutableList(singletonList.subList(0,1).subList(0,1));
 146         testEmptyList(singletonList.subList(0,0));
 147         testEmptyList(singletonList.subList(0,0).subList(0,0));
 148 
 149         Map<Integer,Integer> singletonMap = singletonMap(1,2);
 150         equal(singletonMap.size(), 1);
 151         testMap(singletonMap);
 152         testImmutableMap(singletonMap);




  54 import java.io.*;
  55 import java.util.*;
  56 import java.util.concurrent.*;
  57 import static java.util.Collections.*;
  58 
  59 public class MOAT {
  60     public static void realMain(String[] args) {
  61 
  62         testCollection(new NewAbstractCollection<Integer>());
  63         testCollection(new NewAbstractSet<Integer>());
  64         testCollection(new LinkedHashSet<Integer>());
  65         testCollection(new HashSet<Integer>());
  66         testCollection(new Vector<Integer>());
  67         testCollection(new Vector<Integer>().subList(0,0));
  68         testCollection(new ArrayDeque<Integer>());
  69         testCollection(new ArrayList<Integer>());
  70         testCollection(new ArrayList<Integer>().subList(0,0));
  71         testCollection(new LinkedList<Integer>());
  72         testCollection(new LinkedList<Integer>().subList(0,0));
  73         testCollection(new TreeSet<Integer>());
  74         testCollection(Collections.checkedList(new ArrayList<Integer>(), Integer.class));
  75         testCollection(Collections.synchronizedList(new ArrayList<Integer>()));
  76         testCollection(Collections.checkedSet(new HashSet<Integer>(), Integer.class));
  77         testCollection(Collections.checkedSortedSet(new TreeSet<Integer>(), Integer.class));
  78         testCollection(Collections.checkedNavigableSet(new TreeSet<Integer>(), Integer.class));
  79         testCollection(Collections.synchronizedSet(new HashSet<Integer>()));
  80         testCollection(Collections.synchronizedSortedSet(new TreeSet<Integer>()));
  81         testCollection(Collections.synchronizedNavigableSet(new TreeSet<Integer>()));
  82 
  83         testCollection(new CopyOnWriteArrayList<Integer>());
  84         testCollection(new CopyOnWriteArrayList<Integer>().subList(0,0));
  85         testCollection(new CopyOnWriteArraySet<Integer>());
  86         testCollection(new PriorityQueue<Integer>());
  87         testCollection(new PriorityBlockingQueue<Integer>());
  88         testCollection(new ArrayBlockingQueue<Integer>(20));
  89         testCollection(new LinkedBlockingQueue<Integer>(20));
  90         testCollection(new LinkedBlockingDeque<Integer>(20));
  91         testCollection(new ConcurrentLinkedDeque<Integer>());
  92         testCollection(new ConcurrentLinkedQueue<Integer>());
  93         testCollection(new LinkedTransferQueue<Integer>());
  94         testCollection(new ConcurrentSkipListSet<Integer>());
  95         testCollection(Arrays.asList(new Integer(42)));
  96         testCollection(Arrays.asList(1,2,3));
  97         testCollection(nCopies(25,1));
  98         testImmutableList(nCopies(25,1));
  99         testImmutableList(unmodifiableList(Arrays.asList(1,2,3)));
 100 
 101         testMap(new HashMap<Integer,Integer>());
 102         testMap(new LinkedHashMap<Integer,Integer>());
 103         testMap(new WeakHashMap<Integer,Integer>());
 104         testMap(new IdentityHashMap<Integer,Integer>());
 105         testMap(new TreeMap<Integer,Integer>());
 106         testMap(new Hashtable<Integer,Integer>());
 107         testMap(new ConcurrentHashMap<Integer,Integer>(10, 0.5f));
 108         testMap(new ConcurrentSkipListMap<Integer,Integer>());
 109         testMap(Collections.checkedMap(new HashMap<Integer,Integer>(), Integer.class, Integer.class));
 110         testMap(Collections.checkedSortedMap(new TreeMap<Integer,Integer>(), Integer.class, Integer.class));
 111         testMap(Collections.checkedNavigableMap(new TreeMap<Integer,Integer>(), Integer.class, Integer.class));
 112         testMap(Collections.synchronizedMap(new HashMap<Integer,Integer>()));
 113         testMap(Collections.synchronizedSortedMap(new TreeMap<Integer,Integer>()));
 114         testMap(Collections.synchronizedNavigableMap(new TreeMap<Integer,Integer>()));
 115 
 116         // Empty collections
 117         final List<Integer> emptyArray = Arrays.asList(new Integer[]{});
 118         testCollection(emptyArray);
 119         testEmptyList(emptyArray);
 120         THROWS(IndexOutOfBoundsException.class,
 121                new Fun(){void f(){ emptyArray.set(0,1); }});
 122         THROWS(UnsupportedOperationException.class,
 123                new Fun(){void f(){ emptyArray.add(0,1); }});
 124 
 125         List<Integer> noOne = nCopies(0,1);
 126         testCollection(noOne);
 127         testEmptyList(noOne);
 128         testImmutableList(noOne);
 129 
 130         Set<Integer> emptySet = emptySet();
 131         testCollection(emptySet);
 132         testEmptySet(emptySet);
 133         testEmptySet(EMPTY_SET);
 134         testEmptySet(Collections.emptySet());
 135         testEmptySet(Collections.emptySortedSet());
 136         testEmptySet(Collections.emptyNavigableSet());
 137         testImmutableSet(emptySet);
 138 
 139         List<Integer> emptyList = emptyList();
 140         testCollection(emptyList);
 141         testEmptyList(emptyList);
 142         testEmptyList(EMPTY_LIST);
 143         testEmptyList(Collections.emptyList());
 144         testImmutableList(emptyList);
 145 
 146         Map<Integer,Integer> emptyMap = emptyMap();
 147         testMap(emptyMap);
 148         testEmptyMap(emptyMap);
 149         testEmptyMap(EMPTY_MAP);
 150         testEmptyMap(Collections.emptyMap());
 151         testEmptyMap(Collections.emptySortedMap());
 152         testEmptyMap(Collections.emptyNavigableMap());
 153         testImmutableMap(emptyMap);
 154         testImmutableMap(Collections.emptyMap());
 155         testImmutableMap(Collections.emptySortedMap());
 156         testImmutableMap(Collections.emptyNavigableMap());
 157 
 158         // Singleton collections
 159         Set<Integer> singletonSet = singleton(1);
 160         equal(singletonSet.size(), 1);
 161         testCollection(singletonSet);
 162         testImmutableSet(singletonSet);
 163 
 164         List<Integer> singletonList = singletonList(1);
 165         equal(singletonList.size(), 1);
 166         testCollection(singletonList);
 167         testImmutableList(singletonList);
 168         testImmutableList(singletonList.subList(0,1));
 169         testImmutableList(singletonList.subList(0,1).subList(0,1));
 170         testEmptyList(singletonList.subList(0,0));
 171         testEmptyList(singletonList.subList(0,0).subList(0,0));
 172 
 173         Map<Integer,Integer> singletonMap = singletonMap(1,2);
 174         equal(singletonMap.size(), 1);
 175         testMap(singletonMap);
 176         testImmutableMap(singletonMap);