URLEncoderTest.java revision 89c1feb0a69a7707b271086e749975b3f7acacf7
1/* Licensed to the Apache Software Foundation (ASF) under one or more 2 * contributor license agreements. See the NOTICE file distributed with 3 * this work for additional information regarding copyright ownership. 4 * The ASF licenses this file to You under the Apache License, Version 2.0 5 * (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package org.apache.harmony.luni.tests.java.net; 18 19import dalvik.annotation.TestTargetClass; 20import dalvik.annotation.TestInfo; 21import dalvik.annotation.TestLevel; 22import dalvik.annotation.TestTarget; 23 24import java.io.UnsupportedEncodingException; 25import java.net.URLEncoder; 26 27import junit.framework.TestCase; 28 29@TestTargetClass(URLEncoder.class) 30public class URLEncoderTest extends TestCase { 31 32 /** 33 * @tests URLEncoder#encode(String, String) 34 */ 35@TestInfo( 36 level = TestLevel.PARTIAL, 37 purpose = "Regression test. Checks UnsupportedEncodingException & NullPointerException", 38 targets = { 39 @TestTarget( 40 methodName = "encode", 41 methodArgs = {String.class, String.class} 42 ) 43 }) 44 public void test_encodeLjava_lang_StringLjava_lang_String() throws Exception { 45 // Regression for HARMONY-24 46 try { 47 URLEncoder.encode("str","unknown_enc"); 48 fail("Assert 0: Should throw UEE for invalid encoding"); 49 } catch (UnsupportedEncodingException e) { 50 // expected 51 } 52 //Regression for HARMONY-1233 53 try { 54 URLEncoder.encode(null, "harmony"); 55 fail("NullPointerException expected"); 56 } catch (NullPointerException e) { 57 //expected 58 } 59 } 60} 61