1cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath/* 2cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * Licensed to the Apache Software Foundation (ASF) under one or more 3cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * contributor license agreements. See the NOTICE file distributed with 4cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * this work for additional information regarding copyright ownership. 5cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * The ASF licenses this file to You under the Apache License, Version 2.0 6cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * (the "License"); you may not use this file except in compliance with 7cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * the License. You may obtain a copy of the License at 8cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * 9cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * http://www.apache.org/licenses/LICENSE-2.0 10cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * 11cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * Unless required by applicable law or agreed to in writing, software 12cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * distributed under the License is distributed on an "AS IS" BASIS, 13cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * See the License for the specific language governing permissions and 15cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * limitations under the License. 16cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 17cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 18ab762bb740405d0fefcccf4a0899a234f995be13Narayan Kamathpackage org.apache.harmony.tests.java.net; 19cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 20cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport java.io.UnsupportedEncodingException; 21cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport java.net.URLDecoder; 22cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport java.net.URLEncoder; 23cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 24cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport junit.framework.TestCase; 25cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport tests.support.Support_Configuration; 26cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 27cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathpublic class URLDecoderTest extends TestCase { 28cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 29cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 30cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.net.URLDecoder#URLDecoder() 31cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 32cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_Constructor() throws Exception { 33cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath URLDecoder ud = new URLDecoder(); 34cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertNotNull("Constructor failed.", ud); 35cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 36cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 37cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 38cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.net.URLDecoder#decode(java.lang.String) 39cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 40cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_decodeLjava_lang_String() throws Exception { 41cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final String URL = "http://" + Support_Configuration.HomeAddress; 42cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final String URL2 = "telnet://justWantToHaveFun.com:400"; 43cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath final String URL3 = "file://myServer.org/a file with spaces.jpg"; 44cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("1. Incorrect encoding/decoding", URLDecoder.decode( 45cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath URLEncoder.encode(URL)).equals(URL)); 46cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("2. Incorrect encoding/decoding", URLDecoder.decode( 47cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath URLEncoder.encode(URL2)).equals(URL2)); 48cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("3. Incorrect encoding/decoding", URLDecoder.decode( 49cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath URLEncoder.encode(URL3)).equals(URL3)); 50cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 51cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 52cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 53cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.net.URLDecoder#decode(java.lang.String, java.lang.String) 54cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 55cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_decodeLjava_lang_String_Ljava_lang_String() { 56cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Regression for HARMONY-467 57cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 58cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath URLDecoder.decode("", ""); 59cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("UnsupportedEncodingException expected"); 60cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (UnsupportedEncodingException e) { 61cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 62cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 63cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 64cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath} 65