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 package org.apache.harmony.tests.java.text; 18 19 import java.text.ParsePosition; 20 21 public class ParsePositionTest extends junit.framework.TestCase { 22 23 ParsePosition pp; 24 25 /** 26 * @tests java.text.ParsePosition#ParsePosition(int) 27 */ 28 public void test_ConstructorI() { 29 // Test for method java.text.ParsePosition(int) 30 ParsePosition pp1 = new ParsePosition(Integer.MIN_VALUE); 31 assertTrue("Initialization failed.", pp1.getIndex() == Integer.MIN_VALUE); 32 assertEquals("Initialization failed.", -1, pp1.getErrorIndex()); 33 } 34 35 /** 36 * @tests java.text.ParsePosition#equals(java.lang.Object) 37 */ 38 public void test_equalsLjava_lang_Object() { 39 // Test for method boolean 40 // java.text.ParsePosition.equals(java.lang.Object) 41 ParsePosition pp2 = new ParsePosition(43); 42 pp2.setErrorIndex(56); 43 assertTrue("equals failed.", !pp.equals(pp2)); 44 pp.setErrorIndex(56); 45 pp.setIndex(43); 46 assertTrue("equals failed.", pp.equals(pp2)); 47 } 48 49 /** 50 * @tests java.text.ParsePosition#getErrorIndex() 51 */ 52 public void test_getErrorIndex() { 53 // Test for method int java.text.ParsePosition.getErrorIndex() 54 pp.setErrorIndex(56); 55 assertEquals("getErrorIndex failed.", 56, pp.getErrorIndex()); 56 } 57 58 /** 59 * @tests java.text.ParsePosition#getIndex() 60 */ 61 public void test_getIndex() { 62 // Test for method int java.text.ParsePosition.getIndex() 63 assertTrue("getIndex failed.", pp.getIndex() == Integer.MAX_VALUE); 64 } 65 66 /** 67 * @tests java.text.ParsePosition#hashCode() 68 */ 69 public void test_hashCode() { 70 ParsePosition pp2 = new ParsePosition(Integer.MAX_VALUE); 71 // Test for method int java.text.ParsePosition.hashCode() 72 // Test that the hashcode is stable (and not the identity hashCode). 73 assertEquals(pp.hashCode(), pp2.hashCode()); 74 } 75 76 /** 77 * @tests java.text.ParsePosition#setErrorIndex(int) 78 */ 79 public void test_setErrorIndexI() { 80 // Test for method void java.text.ParsePosition.setErrorIndex(int) 81 pp.setErrorIndex(4564); 82 assertEquals("setErrorIndex failed.", 4564, pp.getErrorIndex()); 83 } 84 85 /** 86 * @tests java.text.ParsePosition#setIndex(int) 87 */ 88 public void test_setIndexI() { 89 // Test for method void java.text.ParsePosition.setIndex(int) 90 pp.setIndex(4564); 91 assertEquals("setErrorIndex failed.", 4564, pp.getIndex()); 92 } 93 94 /** 95 * @tests java.text.ParsePosition#toString() 96 */ 97 public void test_toString() { 98 // Test for method java.lang.String java.text.ParsePosition.toString() 99 assertEquals("toString failed.", 100 "java.text.ParsePosition[index=2147483647,errorIndex=-1]", pp.toString()); 101 } 102 103 /** 104 * Sets up the fixture, for example, open a network connection. This method 105 * is called before a test is executed. 106 */ 107 protected void setUp() { 108 109 pp = new ParsePosition(Integer.MAX_VALUE); 110 } 111 112 /** 113 * Tears down the fixture, for example, close a network connection. This 114 * method is called after a test is executed. 115 */ 116 protected void tearDown() { 117 } 118 } 119