01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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:
18: package org.apache.harmony.luni.tests.java.net;
19:
20: import java.io.UnsupportedEncodingException;
21: import java.net.URLDecoder;
22: import java.net.URLEncoder;
23:
24: import junit.framework.TestCase;
25: import tests.support.Support_Configuration;
26:
27: public class URLEncoderTest extends TestCase {
28:
29: /**
30: * @tests java.net.URLEncoder#encode(java.lang.String)
31: */
32: @SuppressWarnings("deprecation")
33: public void test_encodeLjava_lang_String() {
34: final String URL = "http://"
35: + Support_Configuration.HomeAddress;
36: final String URL2 = "telnet://justWantToHaveFun.com:400";
37: final String URL3 = "file://myServer.org/a file with spaces.jpg";
38:
39: assertTrue("1. Incorrect encoding/decoding", URLDecoder.decode(
40: URLEncoder.encode(URL)).equals(URL));
41: assertTrue("2. Incorrect encoding/decoding", URLDecoder.decode(
42: URLEncoder.encode(URL2)).equals(URL2));
43: assertTrue("3. Incorrect encoding/decoding", URLDecoder.decode(
44: URLEncoder.encode(URL3)).equals(URL3));
45: }
46:
47: /**
48: * @tests URLEncoder#encode(String, String)
49: */
50: public void test_encodeLjava_lang_StringLjava_lang_String()
51: throws Exception {
52: // Regression for HARMONY-24
53: try {
54: URLEncoder.encode("str", "unknown_enc");
55: fail("Assert 0: Should throw UEE for invalid encoding");
56: } catch (UnsupportedEncodingException e) {
57: // expected
58: }
59:
60: // Regression for HARMONY-1233
61: try {
62: URLEncoder.encode(null, "harmony");
63: fail("NullPointerException expected");
64: } catch (NullPointerException e) {
65: // expected
66: }
67: }
68: }
|