1b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson/*
2b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one or more
3b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson * contributor license agreements.  See the NOTICE file distributed with
4b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson * this work for additional information regarding copyright ownership.
5b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson * The ASF licenses this file to You under the Apache License, Version 2.0
6b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson * (the "License"); you may not use this file except in compliance with
7b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson * the License.  You may obtain a copy of the License at
8b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson *
9b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson *     http://www.apache.org/licenses/LICENSE-2.0
10b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson *
11b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson * Unless required by applicable law or agreed to in writing, software
12b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS,
13b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson * See the License for the specific language governing permissions and
15b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson * limitations under the License.
16b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson */
17b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson
18b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilsonpackage libcore.java.util.jar;
19b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson
20b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilsonimport java.util.jar.Attributes;
21b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilsonimport junit.framework.TestCase;
22b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson
23b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilsonpublic class OldAttributesTest extends TestCase {
24b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson    private Attributes a;
25b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson
26b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson    @Override
27b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson    protected void setUp() {
28b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        a = new Attributes();
29b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        a.putValue("1", "one");
30b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        a.putValue("2", "two");
31b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        a.putValue("3", "three");
32b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        a.putValue("4", "four");
33b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson    }
34b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson
35b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson    public void test_getLjava_lang_Object() {
36b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson
37b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        try {
38b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson            a.getValue("IllegalArgumentException expected");
39b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        } catch (IllegalArgumentException ee) {
40b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson            // expected
41b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        }
42b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson    }
43b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson
44b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson    public void test_Constructor() {
45b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        Attributes attr = new Attributes();
46b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        assertTrue(attr.size() >= 0);
47b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson    }
48b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson
49b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson    public void test_ConstructorI() {
50b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        Attributes attr = new Attributes(10);
51b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        assertTrue(attr.size() >= 0);
52b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson    }
53b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson
54b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson    public void test_getLjava_lang_Object_true() {
55b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        assertEquals("a) Incorrect value returned", "one", a
56b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson                .get(new Attributes.Name("1")));
57b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        assertNull("b) Incorrect value returned", a.get("0"));
58b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        assertNull("b) Incorrect value returned", a.get("1"));
59b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson    }
60b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson
61b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson    public void test_getValueLjava_util_jar_Attributes_Name() {
62b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        assertEquals("a) Incorrect value returned", "one", a
63b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson                .getValue(new Attributes.Name("1")));
64b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        assertNull("b) Incorrect value returned", a
65b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson                .getValue(new Attributes.Name("0")));
66b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson    }
67b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson
68b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson    public void test_hashCode() {
69b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        Attributes b = (Attributes) a.clone();
70b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        b.putValue("33", "Thirty three");
71b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        assertNotSame(a.hashCode(), b.hashCode());
72b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        b = (Attributes) a.clone();
73b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        b.clear();
74b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        assertNotSame(a.hashCode(), b.hashCode());
75b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson    }
76b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson
77b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson    public void test_putValueLjava_lang_StringLjava_lang_String() {
78b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        Attributes b = new Attributes();
79b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        b.put(new Attributes.Name("1"), "one");
80b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        b.putValue("2", "two");
81b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        b.put(new Attributes.Name("3"), "three");
82b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        b.putValue("4", "four");
83b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson
84b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        assertTrue(a.equals(b));
85b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson
86b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        try {
87b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson            b.putValue(null, "null");
88b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson            fail("NullPointerException expected");
89b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        } catch (NullPointerException ee) {
90b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson            // expected
91b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        }
92b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson
93b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        StringBuffer sb = new StringBuffer();
94b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        for (int i = 0; i < 0x10000; i++) {
95b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson            sb.append('3');
96b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        }
97b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        try {
98b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson            b.putValue(new String(sb), "wrong name");
99b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson            fail("IllegalArgumentException expected");
100b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        } catch (IllegalArgumentException ee) {
101b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson            // expected
102b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson        }
103b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson    }
104b18d7a024d28fcce3497e2cd8d78642b5d057d45Jesse Wilson}
105