1 30 31 package org.apache.commons.httpclient; 32 33 import junit.framework.*; 34 35 41 public class TestNVP extends TestCase { 42 43 public TestNVP(String testName) { 45 super(testName); 46 } 47 48 public static void main(String args[]) { 50 String [] testCaseName = { TestNVP.class.getName() }; 51 junit.textui.TestRunner.main(testCaseName); 52 } 53 54 56 public static Test suite() { 57 return new TestSuite(TestNVP.class); 58 } 59 60 62 protected NameValuePair makePair() { 63 return new NameValuePair(); 64 } 65 66 protected NameValuePair makePair(String name, String value) { 67 return new NameValuePair(name,value); 68 } 69 70 71 73 public void testGet() { 74 NameValuePair pair = makePair("name 1","value 1"); 75 assertEquals("name 1",pair.getName()); 76 assertEquals("value 1",pair.getValue()); 77 } 78 79 public void testSet() { 80 NameValuePair pair = makePair(); 81 assertTrue(null == pair.getName()); 82 assertTrue(null == pair.getValue()); 83 pair.setName("name"); 84 assertEquals("name",pair.getName()); 85 pair.setValue("value"); 86 assertEquals("value",pair.getValue()); 87 } 88 89 public void testEqualsAndHashCode() { 90 NameValuePair pair1 = makePair(); 91 NameValuePair pair2 = makePair(); 92 93 assertEquals(pair1,pair1); 94 assertEquals(pair1.hashCode(),pair1.hashCode()); 95 assertEquals(pair2,pair2); 96 assertEquals(pair2.hashCode(),pair2.hashCode()); 97 assertEquals(pair1,pair2); 98 assertEquals(pair1.hashCode(),pair2.hashCode()); 99 assertEquals(pair2,pair1); 100 101 pair1.setName("name"); 102 pair1.setValue("value"); 103 104 assertEquals(pair1,pair1); 105 assertEquals(pair1.hashCode(),pair1.hashCode()); 106 assertTrue(!pair1.equals(pair2)); 107 assertTrue(!pair2.equals(pair1)); 108 109 pair2.setName("name"); 110 111 assertEquals(pair1,pair1); 112 assertEquals(pair1.hashCode(),pair1.hashCode()); 113 assertEquals(pair2,pair2); 114 assertEquals(pair2.hashCode(),pair2.hashCode()); 115 assertTrue(!pair1.equals(pair2)); 116 assertTrue(!pair2.equals(pair1)); 117 118 119 pair2.setValue("value"); 120 121 assertEquals(pair1,pair1); 122 assertEquals(pair1.hashCode(),pair1.hashCode()); 123 assertEquals(pair2,pair2); 124 assertEquals(pair2.hashCode(),pair2.hashCode()); 125 assertEquals(pair1,pair2); 126 assertEquals(pair1.hashCode(),pair2.hashCode()); 127 assertEquals(pair2,pair1); 128 } 129 } 130 | Popular Tags |