    1   /*
    2    * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/TestNVP.java,v 1.5 2004/02/22 18:08:49 olegk Exp $
    3    * $Revision: 480424 $
    4    * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
    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   */
    29
    30  package org.apache.commons.httpclient;
    31
    32  import junit.framework.*;
    33
    34  /**
    35   * Simple tests for {@link NameValuePair}.
    36   *
    37   * @author Rodney Waldhoff
    38   * @version $Id: TestNVP.java 480424 2006-11-29 05:56:49Z bayard $
    39   */
    40  public class TestNVP extends TestCase {
    41
    42      // ------------------------------------------------------------ Constructor
    43      public TestNVP(String testName) {
    44          super(testName);
    45      }
    46
    47      // ------------------------------------------------------------------- Main
    48      public static void main(String args[]) {
    49          String[] testCaseName = { TestNVP.class.getName() };
    50          junit.textui.TestRunner.main(testCaseName);
    51      }
    52
    53      // ------------------------------------------------------- TestCase Methods
    54
    55      public static Test suite() {
    56          return new TestSuite(TestNVP.class);
    57      }
    58
    59      // ------------------------------------------------------ Protected Methods
    60
    61      protected NameValuePair makePair() {
    62          return new NameValuePair();
    63      }
    64
    65      protected NameValuePair makePair(String name, String value) {
    66          return new NameValuePair(name,value);
    67      }
    68
    69
    70      // ----------------------------------------------------------- Test Methods
    71
    72      public void testGet() {
    73          NameValuePair pair = makePair("name 1","value 1");
    74          assertEquals("name 1",pair.getName());
    75          assertEquals("value 1",pair.getValue());
    76      }
    77
    78      public void testSet() {
    79          NameValuePair pair = makePair();
    80          assertTrue(null == pair.getName());
    81          assertTrue(null == pair.getValue());
    82          pair.setName("name");
    83          assertEquals("name",pair.getName());
    84          pair.setValue("value");
    85          assertEquals("value",pair.getValue());
    86      }
    87
    88      public void testHashCode() {
    89          NameValuePair param1 = new NameValuePair("name1", "value1");
    90          NameValuePair param2 = new NameValuePair("name2", "value2");
    91          NameValuePair param3 = new NameValuePair("name1", "value1");
    92          assertTrue(param1.hashCode() != param2.hashCode());
    93          assertTrue(param1.hashCode() == param3.hashCode());
    94      }
    95
    96      public void testEquals() {
    97          NameValuePair param1 = new NameValuePair("name1", "value1");
    98          NameValuePair param2 = new NameValuePair("name2", "value2");
    99          NameValuePair param3 = new NameValuePair("name1", "value1");
    100         assertFalse(param1.equals(param2));
    101         assertFalse(param1.equals(null));
    102         assertFalse(param1.equals("name1 = value1"));
    103         assertTrue(param1.equals(param1));
    104         assertTrue(param2.equals(param2));
    105         assertTrue(param1.equals(param3));
    106     }
    107
    108 }