Home | History | Annotate | Download | only in jar
      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.jar;
     19 
     20 import java.util.jar.Attributes;
     21 import junit.framework.TestCase;
     22 
     23 public class OldAttributesTest extends TestCase {
     24     private Attributes a;
     25 
     26     @Override
     27     protected void setUp() {
     28         a = new Attributes();
     29         a.putValue("1", "one");
     30         a.putValue("2", "two");
     31         a.putValue("3", "three");
     32         a.putValue("4", "four");
     33     }
     34 
     35     public void test_getLjava_lang_Object() {
     36 
     37         try {
     38             a.getValue("IllegalArgumentException expected");
     39         } catch (IllegalArgumentException ee) {
     40             // expected
     41         }
     42     }
     43 
     44     public void test_Constructor() {
     45         Attributes attr = new Attributes();
     46         assertTrue(attr.size() >= 0);
     47     }
     48 
     49     public void test_ConstructorI() {
     50         Attributes attr = new Attributes(10);
     51         assertTrue(attr.size() >= 0);
     52     }
     53 
     54     public void test_getLjava_lang_Object_true() {
     55         assertEquals("a) Incorrect value returned", "one", a
     56                 .get(new Attributes.Name("1")));
     57         assertNull("b) Incorrect value returned", a.get("0"));
     58         assertNull("b) Incorrect value returned", a.get("1"));
     59     }
     60 
     61     public void test_getValueLjava_util_jar_Attributes_Name() {
     62         assertEquals("a) Incorrect value returned", "one", a
     63                 .getValue(new Attributes.Name("1")));
     64         assertNull("b) Incorrect value returned", a
     65                 .getValue(new Attributes.Name("0")));
     66     }
     67 
     68     public void test_hashCode() {
     69         Attributes b = (Attributes) a.clone();
     70         b.putValue("33", "Thirty three");
     71         assertNotSame(a.hashCode(), b.hashCode());
     72         b = (Attributes) a.clone();
     73         b.clear();
     74         assertNotSame(a.hashCode(), b.hashCode());
     75     }
     76 
     77     public void test_putValueLjava_lang_StringLjava_lang_String() {
     78         Attributes b = new Attributes();
     79         b.put(new Attributes.Name("1"), "one");
     80         b.putValue("2", "two");
     81         b.put(new Attributes.Name("3"), "three");
     82         b.putValue("4", "four");
     83 
     84         assertTrue(a.equals(b));
     85 
     86         try {
     87             b.putValue(null, "null");
     88             fail("NullPointerException expected");
     89         } catch (NullPointerException ee) {
     90             // expected
     91         }
     92 
     93         StringBuffer sb = new StringBuffer();
     94         for (int i = 0; i < 0x10000; i++) {
     95             sb.append('3');
     96         }
     97         try {
     98             b.putValue(new String(sb), "wrong name");
     99             fail("IllegalArgumentException expected");
    100         } catch (IllegalArgumentException ee) {
    101             // expected
    102         }
    103     }
    104 }
    105