URLDecoderTest.java revision 2ad60cfc28e14ee8f0bb038720836a4696c478ad
1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     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
18package tests.api.java.net;
19
20import java.io.UnsupportedEncodingException;
21import java.net.URLDecoder;
22import java.net.URLEncoder;
23
24import tests.support.Support_Configuration;
25
26public class URLDecoderTest extends junit.framework.TestCase {
27
28	/**
29     * @tests java.net.URLDecoder#URLDecoder()
30     */
31    public void test_Constructor() throws Exception {
32        URLDecoder ud = new URLDecoder();
33        assertNotNull("Constructor failed.", ud);
34    }
35
36	/**
37	 * @tests java.net.URLDecoder#decode(java.lang.String)
38	 */
39	public void test_decodeLjava_lang_String() throws Exception {
40		// Test for method java.lang.String
41		// java.net.URLDecoder.decode(java.lang.String)
42		final String URL = "http://" + 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        }
63    }
64}
65