URISyntaxExceptionTest.java revision 2ad60cfc28e14ee8f0bb038720836a4696c478ad
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 tests.api.java.net;
18
19import java.net.URISyntaxException;
20import java.util.Locale;
21
22public class URISyntaxExceptionTest extends junit.framework.TestCase {
23
24	/**
25	 * @tests java.net.URISyntaxException#URISyntaxException(java.lang.String,
26	 *        java.lang.String, int)
27	 */
28	public void test_ConstructorLjava_lang_StringLjava_lang_StringI() {
29		// test for Constructor(String str, String problem, int index);
30		try {
31			new URISyntaxException(null, "problem", 2);
32			fail("Expected NullPointerException");
33		} catch (NullPointerException npe) {
34		}
35
36		try {
37			new URISyntaxException("str", null, 2);
38			fail("Expected NullPointerException");
39		} catch (NullPointerException npe) {
40		}
41
42		try {
43			new URISyntaxException("str", "problem", -2);
44			fail("Expected IllegalArgumentException");
45		} catch (IllegalArgumentException iae) {
46		}
47
48		URISyntaxException e = new URISyntaxException("str", "problem", 2);
49		assertEquals("returned incorrect reason", "problem", e.getReason());
50		assertEquals("returned incorrect input", "str", e.getInput());
51		assertEquals("returned incorrect index", 2, e.getIndex());
52	}
53
54	/**
55	 * @tests java.net.URISyntaxException#URISyntaxException(java.lang.String,
56	 *        java.lang.String)
57	 */
58	public void test_ConstructorLjava_lang_StringLjava_lang_String() {
59		// test for Constructor(String str, String problem);
60		try {
61			new URISyntaxException(null, "problem");
62			fail("Expected NullPointerException");
63		} catch (NullPointerException npe) {
64		}
65
66		try {
67			new URISyntaxException("str", null);
68			fail("Expected NullPointerException");
69		} catch (NullPointerException npe) {
70		}
71
72		URISyntaxException e = new URISyntaxException("str", "problem");
73		assertEquals("returned incorrect reason", "problem", e.getReason());
74		assertEquals("returned incorrect input", "str", e.getInput());
75		assertEquals("returned incorrect index", -1, e.getIndex());
76	}
77
78	/**
79	 * @tests java.net.URISyntaxException#getIndex()
80	 */
81	public void test_getIndex() {
82		// see constructor tests
83	}
84
85	/**
86	 * @tests java.net.URISyntaxException#getReason()
87	 */
88	public void test_getReason() {
89		// see constructor tests
90	}
91
92	/**
93	 * @tests java.net.URISyntaxException#getInput()
94	 */
95	public void test_getInput() {
96		// see constructor tests
97	}
98
99	/**
100	 * @tests java.net.URISyntaxException#getMessage()
101	 */
102	public void test_getMessage() {
103		// tests for java.lang.String getMessage()
104		Locale.setDefault(Locale.US);
105		URISyntaxException e = new URISyntaxException("str", "problem", 3);
106		assertEquals("Returned incorrect message", "problem at index 3: str", e
107				.getMessage());
108
109		e = new URISyntaxException("str", "problem");
110		assertEquals("Returned incorrect message", "problem: str", e
111				.getMessage());
112	}
113
114	protected void setUp() {
115	}
116
117	protected void tearDown() {
118	}
119
120	protected void doneSuite() {
121	}
122}
123