1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements.  See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License.  You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.apache.harmony.tests.java.net;
18
19import java.net.URISyntaxException;
20import java.util.Locale;
21
22public class URISyntaxExceptionTest extends junit.framework.TestCase {
23
24    /**
25     * java.net.URISyntaxException#URISyntaxException(java.lang.String,
26     *java.lang.String, int)
27     */
28    public void test_ConstructorLjava_lang_StringLjava_lang_StringI() {
29        try {
30            new URISyntaxException(null, "problem", 2);
31            fail("Expected NullPointerException");
32        } catch (NullPointerException npe) {
33            // Expected
34        }
35
36        try {
37            new URISyntaxException("str", null, 2);
38            fail("Expected NullPointerException");
39        } catch (NullPointerException npe) {
40            // Expected
41        }
42
43        try {
44            new URISyntaxException("str", "problem", -2);
45            fail("Expected IllegalArgumentException");
46        } catch (IllegalArgumentException iae) {
47            // Expected
48        }
49
50        URISyntaxException e = new URISyntaxException("str", "problem", 2);
51        assertEquals("returned incorrect reason", "problem", e.getReason());
52        assertEquals("returned incorrect input", "str", e.getInput());
53        assertEquals("returned incorrect index", 2, e.getIndex());
54    }
55
56    /**
57     * java.net.URISyntaxException#URISyntaxException(java.lang.String,
58     *java.lang.String)
59     */
60    public void test_ConstructorLjava_lang_StringLjava_lang_String() {
61        try {
62            new URISyntaxException(null, "problem");
63            fail("Expected NullPointerException");
64        } catch (NullPointerException npe) {
65            // Expected
66        }
67
68        try {
69            new URISyntaxException("str", null);
70            fail("Expected NullPointerException");
71        } catch (NullPointerException npe) {
72            // Expected
73        }
74
75        URISyntaxException e = new URISyntaxException("str", "problem");
76        assertEquals("returned incorrect reason", "problem", e.getReason());
77        assertEquals("returned incorrect input", "str", e.getInput());
78        assertEquals("returned incorrect index", -1, e.getIndex());
79    }
80
81    /**
82     * java.net.URISyntaxException#getIndex()
83     */
84    public void test_getIndex() {
85        // see constructor tests
86    }
87
88    /**
89     * java.net.URISyntaxException#getReason()
90     */
91    public void test_getReason() {
92        // see constructor tests
93    }
94
95    /**
96     * java.net.URISyntaxException#getInput()
97     */
98    public void test_getInput() {
99        // see constructor tests
100    }
101
102    /**
103     * java.net.URISyntaxException#getMessage()
104     */
105    public void test_getMessage() {
106        Locale.setDefault(Locale.US);
107        URISyntaxException e = new URISyntaxException("str", "problem", 3);
108        assertEquals("Returned incorrect message", "problem at index 3: str", e
109                .getMessage());
110
111        e = new URISyntaxException("str", "problem");
112        assertEquals("Returned incorrect message", "problem: str", e
113                .getMessage());
114    }
115}
116