Home | History | Annotate | Download | only in util
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 package libcore.java.util;
     19 
     20 import java.util.ConcurrentModificationException;
     21 import java.util.Iterator;
     22 import java.util.LinkedHashMap;
     23 import junit.framework.TestCase;
     24 
     25 public class OldLinkedHashMapTest extends TestCase {
     26 
     27     public void testLinkedHashMap() {
     28         // we want to test the LinkedHashMap in access ordering mode.
     29         LinkedHashMap map = new LinkedHashMap<String, String>(10, 0.75f, true);
     30 
     31         map.put("key1", "value1");
     32         map.put("key2", "value2");
     33         map.put("key3", "value3");
     34 
     35         Iterator iterator = map.keySet().iterator();
     36         String id = (String) iterator.next();
     37         map.get(id);
     38         try {
     39             iterator.next();
     40             // A LinkedHashMap is supposed to throw this Exception when a
     41             // iterator.next() Operation takes place after a get
     42             // Operation. This is because the get Operation is considered
     43             // a structural modification if the LinkedHashMap is in
     44             // access order mode.
     45             fail("expected ConcurrentModificationException was not thrown.");
     46         } catch(ConcurrentModificationException expected) {
     47         }
     48 
     49         LinkedHashMap mapClone = (LinkedHashMap) map.clone();
     50 
     51         iterator = map.keySet().iterator();
     52         id = (String) iterator.next();
     53         mapClone.get(id);
     54         iterator.next();
     55 
     56         try {
     57             new LinkedHashMap<String, String>(-10, 0.75f, true);
     58             fail("IllegalArgumentException expected");
     59         } catch (IllegalArgumentException expected) {
     60         }
     61 
     62         try {
     63             new LinkedHashMap<String, String>(10, -0.75f, true);
     64             fail("IllegalArgumentException expected");
     65         } catch (IllegalArgumentException expected) {
     66         }
     67     }
     68 }
     69