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 */
17package org.apache.harmony.text.tests.java.text;
18
19import dalvik.annotation.TestTargets;
20import dalvik.annotation.TestLevel;
21import dalvik.annotation.TestTargetNew;
22import dalvik.annotation.TestTargetClass;
23
24import java.text.ParsePosition;
25
26@TestTargetClass(ParsePosition.class)
27public class ParsePositionTest extends junit.framework.TestCase {
28
29    ParsePosition pp;
30
31    /**
32     * @tests java.text.ParsePosition#ParsePosition(int)
33     */
34    @TestTargetNew(
35        level = TestLevel.COMPLETE,
36        notes = "",
37        method = "ParsePosition",
38        args = {int.class}
39    )
40    public void test_ConstructorI() {
41        // Test for method java.text.ParsePosition(int)
42        ParsePosition pp1 = new ParsePosition(Integer.MIN_VALUE);
43        assertTrue("Initialization failed.",
44                pp1.getIndex() == Integer.MIN_VALUE);
45        assertEquals("Initialization failed.", -1, pp1.getErrorIndex());
46    }
47
48    /**
49     * @tests java.text.ParsePosition#equals(java.lang.Object)
50     */
51    @TestTargetNew(
52        level = TestLevel.COMPLETE,
53        notes = "",
54        method = "equals",
55        args = {java.lang.Object.class}
56    )
57    public void test_equalsLjava_lang_Object() {
58        // Test for method boolean
59        // java.text.ParsePosition.equals(java.lang.Object)
60        ParsePosition pp2 = new ParsePosition(43);
61        pp2.setErrorIndex(56);
62        assertTrue("equals failed.", !pp.equals(pp2));
63        pp.setErrorIndex(56);
64        pp.setIndex(43);
65        assertTrue("equals failed.", pp.equals(pp2));
66    }
67
68    /**
69     * @tests java.text.ParsePosition#getErrorIndex()
70     */
71    @TestTargets({
72        @TestTargetNew(
73            level = TestLevel.COMPLETE,
74            notes = "",
75            method = "getErrorIndex",
76            args = {}
77        ),
78        @TestTargetNew(
79            level = TestLevel.COMPLETE,
80            notes = "",
81            method = "setErrorIndex",
82            args = {int.class}
83        )
84    })
85    public void test_getErrorIndex() {
86        // Test for method int java.text.ParsePosition.getErrorIndex()
87        pp.setErrorIndex(56);
88        assertEquals("getErrorIndex failed.", 56, pp.getErrorIndex());
89        pp.setErrorIndex(Integer.MAX_VALUE);
90        assertEquals("getErrorIndex failed.", Integer.MAX_VALUE,
91                pp.getErrorIndex());
92        assertEquals("getErrorIndex failed.", Integer.MAX_VALUE,
93                pp.getErrorIndex());
94    }
95
96    /**
97     * @tests java.text.ParsePosition#getIndex()
98     */
99    @TestTargetNew(
100        level = TestLevel.COMPLETE,
101        notes = "",
102        method = "getIndex",
103        args = {}
104    )
105    public void test_getIndex() {
106        // Test for method int java.text.ParsePosition.getIndex()
107        assertTrue("getIndex failed.", pp.getIndex() == Integer.MAX_VALUE);
108    }
109
110    /**
111     * @tests java.text.ParsePosition#hashCode()
112     */
113    @TestTargetNew(
114        level = TestLevel.COMPLETE,
115        notes = "",
116        method = "hashCode",
117        args = {}
118    )
119    public void test_hashCode() {
120        // Test for method int java.text.ParsePosition.hashCode()
121        ParsePosition pp1 = new ParsePosition(0);
122        ParsePosition pp2 = new ParsePosition(0);
123        assertTrue("hashCode returns non equal hash codes for equal objects.",
124                pp1.hashCode() == pp2.hashCode());
125        pp1.setIndex(Integer.MAX_VALUE);
126        assertTrue("hashCode returns equal hash codes for non equal objects.",
127                pp1.hashCode() != pp2.hashCode());
128    }
129
130    /**
131     * @tests java.text.ParsePosition#setErrorIndex(int)
132     */
133    @TestTargetNew(
134        level = TestLevel.COMPLETE,
135        notes = "",
136        method = "setErrorIndex",
137        args = {int.class}
138    )
139    public void test_setErrorIndexI() {
140        // Test for method void java.text.ParsePosition.setErrorIndex(int)
141        pp.setErrorIndex(4564);
142        assertEquals("setErrorIndex failed.", 4564, pp.getErrorIndex());
143    }
144
145    /**
146     * @tests java.text.ParsePosition#setIndex(int)
147     */
148    @TestTargetNew(
149        level = TestLevel.COMPLETE,
150        notes = "",
151        method = "setIndex",
152        args = {int.class}
153    )
154    public void test_setIndexI() {
155        // Test for method void java.text.ParsePosition.setIndex(int)
156        pp.setIndex(4564);
157        assertEquals("setErrorIndex failed.", 4564, pp.getIndex());
158    }
159
160    /**
161     * @tests java.text.ParsePosition#toString()
162     */
163    @TestTargetNew(
164        level = TestLevel.COMPLETE,
165        notes = "",
166        method = "toString",
167        args = {}
168    )
169    public void test_toString() {
170        // Test for method java.lang.String java.text.ParsePosition.toString()
171        // String format is not specified.
172        assertNotNull("toString returns null.", pp.toString());
173    }
174
175    /**
176     * Sets up the fixture, for example, open a network connection. This method
177     * is called before a test is executed.
178     */
179    protected void setUp() {
180
181        pp = new ParsePosition(Integer.MAX_VALUE);
182    }
183
184    /**
185     * Tears down the fixture, for example, close a network connection. This
186     * method is called after a test is executed.
187     */
188    protected void tearDown() {
189    }
190}
191