URLDecoderTest.java revision 89c1feb0a69a7707b271086e749975b3f7acacf7
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 dalvik.annotation.TestTargetClass;
21import dalvik.annotation.TestInfo;
22import dalvik.annotation.TestLevel;
23import dalvik.annotation.TestTarget;
24
25import java.io.UnsupportedEncodingException;
26import java.net.URLDecoder;
27import java.net.URLEncoder;
28
29import tests.support.Support_Configuration;
30
31@TestTargetClass(URLDecoder.class)
32public class URLDecoderTest extends junit.framework.TestCase {
33
34    /**
35     * @tests java.net.URLDecoder#URLDecoder()
36     */
37@TestInfo(
38      level = TestLevel.COMPLETE,
39      purpose = "",
40      targets = {
41        @TestTarget(
42          methodName = "URLDecoder",
43          methodArgs = {}
44        )
45    })
46    public void test_Constructor() throws Exception {
47        URLDecoder ud = new URLDecoder();
48        assertNotNull("Constructor failed.", ud);
49    }
50
51    /**
52     * @tests java.net.URLDecoder#decode(java.lang.String)
53     */
54@TestInfo(
55      level = TestLevel.COMPLETE,
56      purpose = "",
57      targets = {
58        @TestTarget(
59          methodName = "decode",
60          methodArgs = {java.lang.String.class}
61        )
62    })
63    public void test_decodeLjava_lang_String() throws Exception {
64        // Test for method java.lang.String
65        // java.net.URLDecoder.decode(java.lang.String)
66        final String URL = "http://" + Support_Configuration.HomeAddress;
67        final String URL2 = "telnet://justWantToHaveFun.com:400";
68        final String URL3 = "file://myServer.org/a file with spaces.jpg";
69        assertTrue("1. Incorrect encoding/decoding", URLDecoder.decode(
70                URLEncoder.encode(URL)).equals(URL));
71        assertTrue("2. Incorrect encoding/decoding", URLDecoder.decode(
72                URLEncoder.encode(URL2)).equals(URL2));
73        assertTrue("3. Incorrect encoding/decoding", URLDecoder.decode(
74                URLEncoder.encode(URL3)).equals(URL3));
75    }
76
77    /**
78     * @tests java.net.URLDecoder#decode(java.lang.String, java.lang.String)
79     */
80@TestInfo(
81      level = TestLevel.PARTIAL,
82      purpose = "Regression test",
83      targets = {
84        @TestTarget(
85          methodName = "decode",
86          methodArgs = {java.lang.String.class, java.lang.String.class}
87        )
88    })
89    public void test_decodeLjava_lang_String_Ljava_lang_String() {
90        // Regression for HARMONY-467
91        try {
92            URLDecoder.decode("", "");
93            fail("UnsupportedEncodingException expected");
94        } catch (UnsupportedEncodingException e) {
95        }
96    }
97}
98