01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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:
18: package org.apache.harmony.luni.tests.java.net;
19:
20: import java.io.UnsupportedEncodingException;
21: import java.net.URLDecoder;
22: import java.net.URLEncoder;
23:
24: import junit.framework.TestCase;
25: import tests.support.Support_Configuration;
26:
27: public class URLDecoderTest extends TestCase {
28:
29: /**
30: * @tests java.net.URLDecoder#URLDecoder()
31: */
32: public void test_Constructor() throws Exception {
33: URLDecoder ud = new URLDecoder();
34: assertNotNull("Constructor failed.", ud);
35: }
36:
37: /**
38: * @tests java.net.URLDecoder#decode(java.lang.String)
39: */
40: public void test_decodeLjava_lang_String() throws Exception {
41: final String URL = "http://"
42: + Support_Configuration.HomeAddress;
43: final String URL2 = "telnet://justWantToHaveFun.com:400";
44: final String URL3 = "file://myServer.org/a file with spaces.jpg";
45: assertTrue("1. Incorrect encoding/decoding", URLDecoder.decode(
46: URLEncoder.encode(URL)).equals(URL));
47: assertTrue("2. Incorrect encoding/decoding", URLDecoder.decode(
48: URLEncoder.encode(URL2)).equals(URL2));
49: assertTrue("3. Incorrect encoding/decoding", URLDecoder.decode(
50: URLEncoder.encode(URL3)).equals(URL3));
51: }
52:
53: /**
54: * @tests java.net.URLDecoder#decode(java.lang.String, java.lang.String)
55: */
56: public void test_decodeLjava_lang_String_Ljava_lang_String() {
57: // Regression for HARMONY-467
58: try {
59: URLDecoder.decode("", "");
60: fail("UnsupportedEncodingException expected");
61: } catch (UnsupportedEncodingException e) {
62: // Expected
63: }
64: }
65: }
|