1561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes/* 2561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * Licensed to the Apache Software Foundation (ASF) under one or more 3561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * contributor license agreements. See the NOTICE file distributed with 4561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * this work for additional information regarding copyright ownership. 5561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * The ASF licenses this file to You under the Apache License, Version 2.0 6561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * (the "License"); you may not use this file except in compliance with 7561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * the License. You may obtain a copy of the License at 8561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * 9561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 10561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * 11561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * Unless required by applicable law or agreed to in writing, software 12561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 13561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * See the License for the specific language governing permissions and 15561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * limitations under the License. 16561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes */ 17561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 18561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughespackage org.apache.harmony.luni.tests.java.net; 19561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 20561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.io.UnsupportedEncodingException; 21561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.net.URLDecoder; 22561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport java.net.URLEncoder; 23561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 24561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport junit.framework.TestCase; 25561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughesimport tests.support.Support_Configuration; 26561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 27561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughespublic class URLEncoderTest extends TestCase { 28561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 29561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes /** 30561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * @tests java.net.URLEncoder#encode(java.lang.String) 31561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes */ 32561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes @SuppressWarnings("deprecation") 33561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes public void test_encodeLjava_lang_String() { 34561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes final String URL = "http://" + Support_Configuration.HomeAddress; 35561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes final String URL2 = "telnet://justWantToHaveFun.com:400"; 36561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes final String URL3 = "file://myServer.org/a file with spaces.jpg"; 37561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 38561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertTrue("1. Incorrect encoding/decoding", URLDecoder.decode( 39561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes URLEncoder.encode(URL)).equals(URL)); 40561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertTrue("2. Incorrect encoding/decoding", URLDecoder.decode( 41561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes URLEncoder.encode(URL2)).equals(URL2)); 42561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes assertTrue("3. Incorrect encoding/decoding", URLDecoder.decode( 43561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes URLEncoder.encode(URL3)).equals(URL3)); 44561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 45561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 46561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes /** 47561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes * @tests URLEncoder#encode(String, String) 48561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes */ 49561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes public void test_encodeLjava_lang_StringLjava_lang_String() 50561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes throws Exception { 51561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes // Regression for HARMONY-24 52561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes try { 53561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes URLEncoder.encode("str", "unknown_enc"); 54561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes fail("Assert 0: Should throw UEE for invalid encoding"); 55561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } catch (UnsupportedEncodingException e) { 56561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes // expected 57561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 58561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes 59561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes // Regression for HARMONY-1233 60561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes try { 61561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes URLEncoder.encode(null, "harmony"); 62561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes fail("NullPointerException expected"); 63561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } catch (NullPointerException e) { 64561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes // expected 65561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 66561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes } 67561ee011997c6c2f1befbfaa9d5f0a99771c1d63Elliott Hughes} 68