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 org.apache.harmony.luni.tests.java.net;
19
20import java.io.UnsupportedEncodingException;
21import java.net.URLDecoder;
22import java.net.URLEncoder;
23
24import junit.framework.TestCase;
25import tests.support.Support_Configuration;
26
27public 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://" + Support_Configuration.HomeAddress;
42        final String URL2 = "telnet://justWantToHaveFun.com:400";
43        final String URL3 = "file://myServer.org/a file with spaces.jpg";
44        assertTrue("1. Incorrect encoding/decoding", URLDecoder.decode(
45                URLEncoder.encode(URL)).equals(URL));
46        assertTrue("2. Incorrect encoding/decoding", URLDecoder.decode(
47                URLEncoder.encode(URL2)).equals(URL2));
48        assertTrue("3. Incorrect encoding/decoding", URLDecoder.decode(
49                URLEncoder.encode(URL3)).equals(URL3));
50    }
51
52    /**
53     * @tests java.net.URLDecoder#decode(java.lang.String, java.lang.String)
54     */
55    public void test_decodeLjava_lang_String_Ljava_lang_String() {
56        // Regression for HARMONY-467
57        try {
58            URLDecoder.decode("", "");
59            fail("UnsupportedEncodingException expected");
60        } catch (UnsupportedEncodingException e) {
61            // Expected
62        }
63    }
64}
65