1   /*
2    * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/oac.hc3x/trunk/src/test/org/apache/commons/httpclient/TestHeader.java $
3    * $Revision: 1425331 $
4    * $Date: 2012-12-22 18:29:41 +0000 (Sat, 22 Dec 2012) $
5    * ====================================================================
6    *
7    *  Licensed to the Apache Software Foundation (ASF) under one or more
8    *  contributor license agreements.  See the NOTICE file distributed with
9    *  this work for additional information regarding copyright ownership.
10   *  The ASF licenses this file to You under the Apache License, Version 2.0
11   *  (the "License"); you may not use this file except in compliance with
12   *  the License.  You may obtain a copy of the License at
13   *
14   *      http://www.apache.org/licenses/LICENSE-2.0
15   *
16   *  Unless required by applicable law or agreed to in writing, software
17   *  distributed under the License is distributed on an "AS IS" BASIS,
18   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   *  See the License for the specific language governing permissions and
20   *  limitations under the License.
21   * ====================================================================
22   *
23   * This software consists of voluntary contributions made by many
24   * individuals on behalf of the Apache Software Foundation.  For more
25   * information on the Apache Software Foundation, please see
26   * <http://www.apache.org/>.
27   *
28   * [Additional notices, if required by prior licensing conditions]
29   *
30   */
31  
32  package org.apache.commons.httpclient;
33  
34  import junit.framework.*;
35  
36  /***
37   * Simple tests for {@link NameValuePair}.
38   *
39   * @author Rodney Waldhoff
40   * @version $Id: TestHeader.java 608014 2008-01-02 05:48:53Z rolandw $
41   */
42  public class TestHeader extends TestNVP {
43  
44      // ------------------------------------------------------------ Constructor
45      public TestHeader(String testName) {
46          super(testName);
47      }
48  
49      // ------------------------------------------------------------------- Main
50      public static void main(String args[]) {
51          String[] testCaseName = { TestHeader.class.getName() };
52          junit.textui.TestRunner.main(testCaseName);
53      }
54  
55      // ------------------------------------------------------- TestCase Methods
56  
57      public static Test suite() {
58          return new TestSuite(TestHeader.class);
59      }
60  
61      // ------------------------------------------------------ Protected Methods
62  
63      protected NameValuePair makePair() {
64          return new Header();
65      }
66  
67      protected NameValuePair makePair(String name, String value) {
68          return new Header(name,value);
69      }
70  
71  
72      // ----------------------------------------------------------- Test Methods
73  
74      public void testToExternalFormNull() {
75          Header header = (Header)makePair();
76          assertEquals(": \r\n",header.toExternalForm());
77      }
78  
79      public void testToExternalFormNullName() {
80          Header header = (Header)makePair(null,"value");
81          assertEquals(": value\r\n",header.toExternalForm());
82      }
83  
84      public void testToExternalFormNullValue() {
85          Header header = (Header)makePair("name",null);
86          assertEquals("name: \r\n",header.toExternalForm());
87      }
88  
89      public void testToExternalForm() {
90          Header header = (Header)makePair("a","b");
91          assertEquals("a: b\r\n",header.toExternalForm());
92      }
93  
94      public void testEqualToNVP() {
95          NameValuePair header = makePair("a","b");
96          NameValuePair pair = new NameValuePair("a","b");
97          assertTrue(header.equals(pair));
98          assertTrue(pair.equals(header));
99      }
100 }