summaryrefslogtreecommitdiffstats
path: root/luni/src/test/java/libcore/java/text/OldFieldPositionTest.java
blob: b6fbd98b8e19aecbcb63d2894770b91d6ebf63e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package libcore.java.text;

import java.text.DateFormat;
import java.text.FieldPosition;

public class OldFieldPositionTest extends junit.framework.TestCase {

    public void test_hashCode() {
        // Test for method int java.text.FieldPosition.hashCode()
        FieldPosition fpos1 = new FieldPosition(1);
        FieldPosition fpos2 = new FieldPosition(1);
        assertTrue("test 1: hash codes are not equal for equal objects.",
                fpos1.hashCode() == fpos2.hashCode());
        fpos1.setBeginIndex(5);
        fpos1.setEndIndex(110);
        assertTrue("test 2: hash codes are equal for non equal objects.",
                fpos1.hashCode() != fpos2.hashCode());
        fpos2.setBeginIndex(5);
        fpos2.setEndIndex(110);
        assertTrue("test 3: hash codes are not equal for equal objects.",
                fpos1.hashCode() == fpos2.hashCode());

        FieldPosition fpos3 = new FieldPosition(
                DateFormat.Field.DAY_OF_WEEK_IN_MONTH);

        assertTrue("test 4: hash codes are equal for non equal objects.",
                fpos2.hashCode() != fpos3.hashCode());
    }

    public void test_setBeginIndexI() {
        // Test for method void java.text.FieldPosition.setBeginIndex(int)
        FieldPosition fpos = new FieldPosition(1);
        fpos.setBeginIndex(2);
        fpos.setEndIndex(3);
        assertEquals("beginIndex should have been set to 2", 2, fpos
                .getBeginIndex());

        fpos.setBeginIndex(Integer.MAX_VALUE);
        assertEquals("beginIndex should have been set to Integer.MAX_VALUE",
                Integer.MAX_VALUE, fpos.getBeginIndex());

        fpos.setBeginIndex(-1);
        assertEquals("beginIndex should have been set to -1",
                -1, fpos.getBeginIndex());
    }

    public void test_setEndIndexI() {
        // Test for method void java.text.FieldPosition.setEndIndex(int)
        FieldPosition fpos = new FieldPosition(1);
        fpos.setEndIndex(3);
        fpos.setBeginIndex(2);
        assertEquals("EndIndex should have been set to 3", 3, fpos
                .getEndIndex());

        fpos.setEndIndex(Integer.MAX_VALUE);
        assertEquals("endIndex should have been set to Integer.MAX_VALUE",
                Integer.MAX_VALUE, fpos.getEndIndex());

        fpos.setEndIndex(-1);
        assertEquals("endIndex should have been set to -1",
                -1, fpos.getEndIndex());
    }
}