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
18package org.apache.harmony.archive.tests.java.util.jar;
19
20import dalvik.annotation.TestTargetClass;
21import dalvik.annotation.TestTargets;
22import dalvik.annotation.TestLevel;
23import dalvik.annotation.TestTargetNew;
24
25import java.util.jar.Attributes;
26import junit.framework.TestCase;
27
28@TestTargetClass(Attributes.Name.class)
29public class AttributesNameTest extends TestCase {
30
31    /**
32     * @tests java.util.jar.Attributes.Name#Name(java.lang.String)
33     */
34    @TestTargetNew(
35        level = TestLevel.COMPLETE,
36        notes = "",
37        method = "Name",
38        args = {java.lang.String.class}
39    )
40    public void test_AttributesName_Constructor() {
41        // Regression for HARMONY-85
42        try {
43            new Attributes.Name(
44                    "01234567890123456789012345678901234567890123456789012345678901234567890");
45            fail("Assert 0: should have thrown IllegalArgumentException");
46        } catch (IllegalArgumentException e) {
47            // expected
48        }
49
50        try {
51            new Attributes.Name((String) null);
52            fail("NullPointerException expected");
53        } catch (NullPointerException ee) {
54            // expected
55        }
56
57        assertNotNull(new Attributes.Name("Attr"));
58    }
59
60    @TestTargetNew(
61        level = TestLevel.COMPLETE,
62        notes = "",
63        method = "equals",
64        args = {java.lang.Object.class}
65    )
66    public void test_equalsLjava_lang_Object() {
67        Attributes.Name attr1 = new Attributes.Name("Attr");
68        Attributes.Name attr2 = new Attributes.Name("Attr");
69
70        assertTrue(attr1.equals(attr2));
71        attr2 = new Attributes.Name("Attr1");
72        assertFalse(attr1.equals(attr2));
73    }
74
75    @TestTargetNew(
76        level = TestLevel.COMPLETE,
77        notes = "",
78        method = "hashCode",
79        args = {}
80    )
81    public void test_hashCode() {
82        Attributes.Name attr1 = new Attributes.Name("Attr1");
83        Attributes.Name attr2 = new Attributes.Name("Attr2");
84
85        assertNotSame(attr1.hashCode(), attr2.hashCode());
86    }
87
88    @TestTargetNew(
89        level = TestLevel.COMPLETE,
90        notes = "",
91        method = "toString",
92        args = {}
93    )
94    public void test_toString() {
95        String str1 = "Attr1";
96        String str2 = "Attr2";
97        Attributes.Name attr1 = new Attributes.Name(str1);
98        Attributes.Name attr2 = new Attributes.Name("Attr2");
99
100        assertTrue(attr1.toString().equals(str1));
101        assertTrue(attr2.toString().equals(str2));
102        assertFalse(attr2.toString().equals(str1));
103    }
104}
105