001: /* Licensed to the Apache Software Foundation (ASF) under one or more
002: * contributor license agreements. See the NOTICE file distributed with
003: * this work for additional information regarding copyright ownership.
004: * The ASF licenses this file to You under the Apache License, Version 2.0
005: * (the "License"); you may not use this file except in compliance with
006: * the License. You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.harmony.luni.tests.java.net;
018:
019: import java.net.URISyntaxException;
020: import java.util.Locale;
021:
022: public class URISyntaxExceptionTest extends junit.framework.TestCase {
023:
024: /**
025: * @tests java.net.URISyntaxException#URISyntaxException(java.lang.String,
026: * java.lang.String, int)
027: */
028: public void test_ConstructorLjava_lang_StringLjava_lang_StringI() {
029: try {
030: new URISyntaxException(null, "problem", 2);
031: fail("Expected NullPointerException");
032: } catch (NullPointerException npe) {
033: // Expected
034: }
035:
036: try {
037: new URISyntaxException("str", null, 2);
038: fail("Expected NullPointerException");
039: } catch (NullPointerException npe) {
040: // Expected
041: }
042:
043: try {
044: new URISyntaxException("str", "problem", -2);
045: fail("Expected IllegalArgumentException");
046: } catch (IllegalArgumentException iae) {
047: // Expected
048: }
049:
050: URISyntaxException e = new URISyntaxException("str", "problem",
051: 2);
052: assertEquals("returned incorrect reason", "problem", e
053: .getReason());
054: assertEquals("returned incorrect input", "str", e.getInput());
055: assertEquals("returned incorrect index", 2, e.getIndex());
056: }
057:
058: /**
059: * @tests java.net.URISyntaxException#URISyntaxException(java.lang.String,
060: * java.lang.String)
061: */
062: public void test_ConstructorLjava_lang_StringLjava_lang_String() {
063: try {
064: new URISyntaxException(null, "problem");
065: fail("Expected NullPointerException");
066: } catch (NullPointerException npe) {
067: // Expected
068: }
069:
070: try {
071: new URISyntaxException("str", null);
072: fail("Expected NullPointerException");
073: } catch (NullPointerException npe) {
074: // Expected
075: }
076:
077: URISyntaxException e = new URISyntaxException("str", "problem");
078: assertEquals("returned incorrect reason", "problem", e
079: .getReason());
080: assertEquals("returned incorrect input", "str", e.getInput());
081: assertEquals("returned incorrect index", -1, e.getIndex());
082: }
083:
084: /**
085: * @tests java.net.URISyntaxException#getIndex()
086: */
087: public void test_getIndex() {
088: // see constructor tests
089: }
090:
091: /**
092: * @tests java.net.URISyntaxException#getReason()
093: */
094: public void test_getReason() {
095: // see constructor tests
096: }
097:
098: /**
099: * @tests java.net.URISyntaxException#getInput()
100: */
101: public void test_getInput() {
102: // see constructor tests
103: }
104:
105: /**
106: * @tests java.net.URISyntaxException#getMessage()
107: */
108: public void test_getMessage() {
109: Locale.setDefault(Locale.US);
110: URISyntaxException e = new URISyntaxException("str", "problem",
111: 3);
112: assertEquals("Returned incorrect message",
113: "problem at index 3: str", e.getMessage());
114:
115: e = new URISyntaxException("str", "problem");
116: assertEquals("Returned incorrect message", "problem: str", e
117: .getMessage());
118: }
119: }
|