001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020 package javax.mail.internet; 021 022 import junit.framework.TestCase; 023 024 /** 025 * @version $Rev: 467553 $ $Date: 2006-10-25 00:01:51 -0400 (Wed, 25 Oct 2006) $ 026 */ 027 public class ParameterListTest extends TestCase { 028 public ParameterListTest(String arg0) { 029 super(arg0); 030 } 031 public void testParameters() throws ParseException { 032 ParameterList list = 033 new ParameterList(";thing=value;thong=vulue;thung=git"); 034 assertEquals("value", list.get("thing")); 035 assertEquals("vulue", list.get("thong")); 036 assertEquals("git", list.get("thung")); 037 } 038 039 public void testQuotedParameter() throws ParseException { 040 ParameterList list = new ParameterList(";foo=one;bar=\"two\""); 041 assertEquals("one", list.get("foo")); 042 assertEquals("two", list.get("bar")); 043 } 044 045 public void testEncodeDecode() throws Exception { 046 047 System.setProperty("mail.mime.encodeparameters", "true"); 048 System.setProperty("mail.mime.decodeparameters", "true"); 049 050 String value = " '*% abc \u0081\u0082\r\n\t"; 051 String encodedTest = "; one*=UTF-8''%20%27%2A%25%20abc%20%C2%81%C2%82%0D%0A%09"; 052 053 ParameterList list = new ParameterList(); 054 list.set("one", value, "UTF-8"); 055 056 assertEquals(value, list.get("one")); 057 058 String encoded = list.toString(); 059 060 assertEquals(encoded, encodedTest); 061 062 ParameterList list2 = new ParameterList(encoded); 063 assertEquals(value, list.get("one")); 064 assertEquals(list2.toString(), encodedTest); 065 } 066 067 }