1 /* 2 * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestNVP.java,v 1.4 2003/01/23 22:48:27 jsdever Exp $ 3 * $Revision: 1.4 $ 4 * $Date: 2003/01/23 22:48:27 $ 5 * ==================================================================== 6 * 7 * The Apache Software License, Version 1.1 8 * 9 * Copyright (c) 1999-2003 The Apache Software Foundation. All rights 10 * reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in 21 * the documentation and/or other materials provided with the 22 * distribution. 23 * 24 * 3. The end-user documentation included with the redistribution, if 25 * any, must include the following acknowlegement: 26 * "This product includes software developed by the 27 * Apache Software Foundation (http://www.apache.org/)." 28 * Alternately, this acknowlegement may appear in the software itself, 29 * if and wherever such third-party acknowlegements normally appear. 30 * 31 * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software 32 * Foundation" must not be used to endorse or promote products derived 33 * from this software without prior written permission. For written 34 * permission, please contact apache@apache.org. 35 * 36 * 5. Products derived from this software may not be called "Apache" 37 * nor may "Apache" appear in their names without prior written 38 * permission of the Apache Group. 39 * 40 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 41 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 42 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 43 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 47 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 48 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 49 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 50 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 * SUCH DAMAGE. 52 * ==================================================================== 53 * 54 * This software consists of voluntary contributions made by many 55 * individuals on behalf of the Apache Software Foundation. For more 56 * information on the Apache Software Foundation, please see 57 * <http://www.apache.org/>. 58 * 59 * [Additional notices, if required by prior licensing conditions] 60 * 61 */ 62 63 package org.apache.commons.httpclient; 64 65 import junit.framework.*; 66 67 /*** 68 * Simple tests for {@link NameValuePair}. 69 * 70 * @author Rodney Waldhoff 71 * @version $Id: TestNVP.java,v 1.4 2003/01/23 22:48:27 jsdever Exp $ 72 */ 73 public class TestNVP extends TestCase { 74 75 // ------------------------------------------------------------ Constructor 76 public TestNVP(String testName) { 77 super(testName); 78 } 79 80 // ------------------------------------------------------------------- Main 81 public static void main(String args[]) { 82 String[] testCaseName = { TestNVP.class.getName() }; 83 junit.textui.TestRunner.main(testCaseName); 84 } 85 86 // ------------------------------------------------------- TestCase Methods 87 88 public static Test suite() { 89 return new TestSuite(TestNVP.class); 90 } 91 92 // ------------------------------------------------------ Protected Methods 93 94 protected NameValuePair makePair() { 95 return new NameValuePair(); 96 } 97 98 protected NameValuePair makePair(String name, String value) { 99 return new NameValuePair(name,value); 100 } 101 102 103 // ----------------------------------------------------------- Test Methods 104 105 public void testGet() { 106 NameValuePair pair = makePair("name 1","value 1"); 107 assertEquals("name 1",pair.getName()); 108 assertEquals("value 1",pair.getValue()); 109 } 110 111 public void testSet() { 112 NameValuePair pair = makePair(); 113 assertTrue(null == pair.getName()); 114 assertTrue(null == pair.getValue()); 115 pair.setName("name"); 116 assertEquals("name",pair.getName()); 117 pair.setValue("value"); 118 assertEquals("value",pair.getValue()); 119 } 120 121 public void testEqualsAndHashCode() { 122 NameValuePair pair1 = makePair(); 123 NameValuePair pair2 = makePair(); 124 125 assertEquals(pair1,pair1); 126 assertEquals(pair1.hashCode(),pair1.hashCode()); 127 assertEquals(pair2,pair2); 128 assertEquals(pair2.hashCode(),pair2.hashCode()); 129 assertEquals(pair1,pair2); 130 assertEquals(pair1.hashCode(),pair2.hashCode()); 131 assertEquals(pair2,pair1); 132 133 pair1.setName("name"); 134 pair1.setValue("value"); 135 136 assertEquals(pair1,pair1); 137 assertEquals(pair1.hashCode(),pair1.hashCode()); 138 assertTrue(!pair1.equals(pair2)); 139 assertTrue(!pair2.equals(pair1)); 140 141 pair2.setName("name"); 142 143 assertEquals(pair1,pair1); 144 assertEquals(pair1.hashCode(),pair1.hashCode()); 145 assertEquals(pair2,pair2); 146 assertEquals(pair2.hashCode(),pair2.hashCode()); 147 assertTrue(!pair1.equals(pair2)); 148 assertTrue(!pair2.equals(pair1)); 149 150 151 pair2.setValue("value"); 152 153 assertEquals(pair1,pair1); 154 assertEquals(pair1.hashCode(),pair1.hashCode()); 155 assertEquals(pair2,pair2); 156 assertEquals(pair2.hashCode(),pair2.hashCode()); 157 assertEquals(pair1,pair2); 158 assertEquals(pair1.hashCode(),pair2.hashCode()); 159 assertEquals(pair2,pair1); 160 } 161 }

This page was automatically generated by Maven