hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject [2/2] httpcomponents-core git commit: Removed #equals and #hashCode methods from BasicHeader added by HTTPCORE-439; HeaderGroup#removeHeader to remove the first header matching the header name / value passed as a parameter.
Date Mon, 18 Dec 2017 14:53:44 GMT
Removed #equals and #hashCode methods from BasicHeader added by HTTPCORE-439; HeaderGroup#removeHeader
to remove the first header matching the header name / value passed as a parameter.


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/a564f2a9
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/a564f2a9
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/a564f2a9

Branch: refs/heads/master
Commit: a564f2a9c5205547ed184871108aa35be0ace752
Parents: 496f5bf
Author: Oleg Kalnichevski <olegk@apache.org>
Authored: Thu Dec 14 23:01:11 2017 +0100
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Mon Dec 18 15:51:00 2017 +0100

----------------------------------------------------------------------
 .../hc/core5/http/message/BasicHeader.java      |  22 ---
 .../hc/core5/http/message/HeaderGroup.java      |  10 +-
 .../hc/core5/http/message/TestBasicHeader.java  | 136 +++----------------
 .../core5/http/message/TestNameValuePair.java   | 120 ++++++++++++++++
 4 files changed, 145 insertions(+), 143 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/a564f2a9/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHeader.java b/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
index f229ee4..36ca08c 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
@@ -28,14 +28,12 @@
 package org.apache.hc.core5.http.message;
 
 import java.io.Serializable;
-import java.util.Locale;
 import java.util.Objects;
 
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.util.Args;
-import org.apache.hc.core5.util.LangUtils;
 
 /**
  * Immutable {@link Header}.
@@ -78,18 +76,6 @@ public class BasicHeader implements Header, Cloneable, Serializable {
     }
 
     @Override
-    public boolean equals(final Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj instanceof BasicHeader) {
-            final BasicHeader that = (BasicHeader) obj;
-            return this.name.equalsIgnoreCase(that.name) && LangUtils.equals(this.value,
that.value);
-        }
-        return false;
-    }
-
-    @Override
     public String getName() {
         return name;
     }
@@ -100,14 +86,6 @@ public class BasicHeader implements Header, Cloneable, Serializable {
     }
 
     @Override
-    public int hashCode() {
-        int hash = LangUtils.HASH_SEED;
-        hash = LangUtils.hashCode(hash, this.name.toLowerCase(Locale.ROOT));
-        hash = LangUtils.hashCode(hash, this.value);
-        return hash;
-    }
-
-    @Override
     public boolean isSensitive() {
         return this.sensitive;
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/a564f2a9/httpcore5/src/main/java/org/apache/hc/core5/http/message/HeaderGroup.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/message/HeaderGroup.java b/httpcore5/src/main/java/org/apache/hc/core5/http/message/HeaderGroup.java
index aeffc27..e000649 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/message/HeaderGroup.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/message/HeaderGroup.java
@@ -38,6 +38,7 @@ import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.MessageHeaders;
 import org.apache.hc.core5.http.ProtocolException;
 import org.apache.hc.core5.util.CharArrayBuffer;
+import org.apache.hc.core5.util.LangUtils;
 
 /**
  * A class for combining a set of headers.
@@ -96,7 +97,14 @@ public class HeaderGroup implements MessageHeaders, Serializable {
         if (header == null) {
             return;
         }
-        headers.remove(header);
+        for (int i = 0; i < this.headers.size(); i++) {
+            final Header current = this.headers.get(i);
+            if (current == header || current.getName().equalsIgnoreCase(header.getName())
+                    && LangUtils.equals(header.getValue(), current.getValue())) {
+                this.headers.remove(current);
+                return;
+            }
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/a564f2a9/httpcore5/src/test/java/org/apache/hc/core5/http/message/TestBasicHeader.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/message/TestBasicHeader.java
b/httpcore5/src/test/java/org/apache/hc/core5/http/message/TestBasicHeader.java
index db837ff..032ae9e 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/message/TestBasicHeader.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/message/TestBasicHeader.java
@@ -36,132 +36,28 @@ import org.junit.Test;
 public class TestBasicHeader {
 
     @Test
-    public void testNullNotEqual() throws Exception {
-        final Header header = new BasicHeader("name", "value");
-
-        Assert.assertFalse(header.equals(null));
-    }
-
-    @Test
-    public void testObjectNotEqual() throws Exception {
-        final Header header = new BasicHeader("name", "value");
-
-        Assert.assertFalse(header.equals(new Object()));
-    }
-
-    @Test
-    public void testNameEquals() throws Exception {
-        final Header header = new BasicHeader("name", "value");
-        final Header header2 = new BasicHeader("NAME", "value");
-
-        Assert.assertEquals(header, header2);
-        Assert.assertEquals(header.hashCode(), header2.hashCode());
-
-        final Header header3 = new BasicHeader("NAME", "value");
-        final Header header4 = new BasicHeader("name", "value");
-
-        Assert.assertEquals(header3, header4);
-        Assert.assertEquals(header3.hashCode(), header4.hashCode());
-    }
-
-    @Test
-    public void testValueEquals() throws Exception {
-        final Header header = new BasicHeader("name", "value");
-        final Header header2 = new BasicHeader("name", "value");
-
-        Assert.assertEquals(header, header2);
-        Assert.assertEquals(header.hashCode(), header2.hashCode());
-    }
-
-    @Test
-    public void testNameNotEqual() throws Exception {
-        final Header header = new BasicHeader("name", "value");
-        final Header header2 = new BasicHeader("name2", "value");
-
-        Assert.assertNotEquals(header, header2);
-    }
-
-    @Test
-    public void testValueNotEqual() throws Exception {
-        final Header header = new BasicHeader("name", "value");
-        final Header header2 = new BasicHeader("name", "value2");
-
-        Assert.assertNotEquals(header, header2);
-
-        final Header header3 = new BasicHeader("name", "value");
-        final Header header4 = new BasicHeader("name", "VALUE");
-
-        Assert.assertNotEquals(header3, header4);
-
-        final Header header5 = new BasicHeader("name", "VALUE");
-        final Header header6 = new BasicHeader("name", "value");
-
-        Assert.assertNotEquals(header5, header6);
-    }
-
-    @Test
-    public void testNullValuesEquals() throws Exception {
-        final Header header = new BasicHeader("name", null);
-        final Header header2 = new BasicHeader("name", null);
-
-        Assert.assertEquals(header, header2);
-        Assert.assertEquals(header.hashCode(), header2.hashCode());
-    }
-
-    @Test
-    public void testNullValueNotEqual() throws Exception {
-        final Header header = new BasicHeader("name", null);
-        final Header header2 = new BasicHeader("name", "value");
-
-        Assert.assertNotEquals(header, header2);
-    }
-
-    @Test
-    public void testNullValue2NotEqual() throws Exception {
-        final Header header = new BasicHeader("name", "value");
-        final Header header2 = new BasicHeader("name", null);
-
-        Assert.assertNotEquals(header, header2);
+    public void testConstructor() {
+        final Header param = new BasicHeader("name", "value");
+        Assert.assertEquals("name", param.getName());
+        Assert.assertEquals("value", param.getValue());
     }
 
     @Test
-    public void testEquals() throws Exception {
-        final Header header = new BasicHeader("name", "value");
-        final Header header2 = new BasicHeader("name", "value");
-
-        Assert.assertEquals(header, header);
-        Assert.assertEquals(header.hashCode(), header.hashCode());
-        Assert.assertEquals(header2, header2);
-        Assert.assertEquals(header2.hashCode(), header2.hashCode());
-        Assert.assertEquals(header, header2);
-        Assert.assertEquals(header.hashCode(), header2.hashCode());
+    public void testInvalidName() {
+        try {
+            new BasicHeader(null, null);
+            Assert.fail("IllegalArgumentException should have been thrown");
+        } catch (final IllegalArgumentException ex) {
+            //expected
+        }
     }
 
     @Test
-    public void testHashCode() throws Exception {
-        final Header header = new BasicHeader("name", null);
-        final Header header2 = new BasicHeader("name2", null);
-
-        Assert.assertNotEquals(header.hashCode(), header2.hashCode());
-
-        final Header header3 = new BasicHeader("name", "value");
-        final Header header4 = new BasicHeader("name", "value2");
-
-        Assert.assertNotEquals(header3.hashCode(), header4.hashCode());
-
-        final Header header5 = new BasicHeader("name", "value");
-        final Header header6 = new BasicHeader("name", null);
-
-        Assert.assertNotEquals(header5.hashCode(), header6.hashCode());
+    public void testToString() {
+        final Header param1 = new BasicHeader("name1", "value1");
+        Assert.assertEquals("name1: value1", param1.toString());
+        final Header param2 = new BasicHeader("name1", null);
+        Assert.assertEquals("name1: ", param2.toString());
     }
 
-    @Test
-    public void testSensitive() throws Exception {
-        // sensitivity has no affect on equality.
-        final Header header = new BasicHeader("name", "value", true);
-        final Header header2 = new BasicHeader("name", "value", false);
-
-        Assert.assertEquals(header, header2);
-        Assert.assertEquals(header.hashCode(), header2.hashCode());
-    }
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/a564f2a9/httpcore5/src/test/java/org/apache/hc/core5/http/message/TestNameValuePair.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/message/TestNameValuePair.java
b/httpcore5/src/test/java/org/apache/hc/core5/http/message/TestNameValuePair.java
index a7eaabf..a3729f4 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/message/TestNameValuePair.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/message/TestNameValuePair.java
@@ -62,4 +62,124 @@ public class TestNameValuePair {
         Assert.assertEquals("name1", param2.toString());
     }
 
+    @Test
+    public void testNullNotEqual() throws Exception {
+        final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
+
+        Assert.assertFalse(NameValuePair.equals(null));
+    }
+
+    @Test
+    public void testObjectNotEqual() throws Exception {
+        final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
+
+        Assert.assertFalse(NameValuePair.equals(new Object()));
+    }
+
+    @Test
+    public void testNameEquals() throws Exception {
+        final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
+        final NameValuePair NameValuePair2 = new BasicNameValuePair("NAME", "value");
+
+        Assert.assertEquals(NameValuePair, NameValuePair2);
+        Assert.assertEquals(NameValuePair.hashCode(), NameValuePair2.hashCode());
+
+        final NameValuePair NameValuePair3 = new BasicNameValuePair("NAME", "value");
+        final NameValuePair NameValuePair4 = new BasicNameValuePair("name", "value");
+
+        Assert.assertEquals(NameValuePair3, NameValuePair4);
+        Assert.assertEquals(NameValuePair3.hashCode(), NameValuePair4.hashCode());
+    }
+
+    @Test
+    public void testValueEquals() throws Exception {
+        final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
+        final NameValuePair NameValuePair2 = new BasicNameValuePair("name", "value");
+
+        Assert.assertEquals(NameValuePair, NameValuePair2);
+        Assert.assertEquals(NameValuePair.hashCode(), NameValuePair2.hashCode());
+    }
+
+    @Test
+    public void testNameNotEqual() throws Exception {
+        final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
+        final NameValuePair NameValuePair2 = new BasicNameValuePair("name2", "value");
+
+        Assert.assertNotEquals(NameValuePair, NameValuePair2);
+    }
+
+    @Test
+    public void testValueNotEqual() throws Exception {
+        final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
+        final NameValuePair NameValuePair2 = new BasicNameValuePair("name", "value2");
+
+        Assert.assertNotEquals(NameValuePair, NameValuePair2);
+
+        final NameValuePair NameValuePair3 = new BasicNameValuePair("name", "value");
+        final NameValuePair NameValuePair4 = new BasicNameValuePair("name", "VALUE");
+
+        Assert.assertNotEquals(NameValuePair3, NameValuePair4);
+
+        final NameValuePair NameValuePair5 = new BasicNameValuePair("name", "VALUE");
+        final NameValuePair NameValuePair6 = new BasicNameValuePair("name", "value");
+
+        Assert.assertNotEquals(NameValuePair5, NameValuePair6);
+    }
+
+    @Test
+    public void testNullValuesEquals() throws Exception {
+        final NameValuePair NameValuePair = new BasicNameValuePair("name", null);
+        final NameValuePair NameValuePair2 = new BasicNameValuePair("name", null);
+
+        Assert.assertEquals(NameValuePair, NameValuePair2);
+        Assert.assertEquals(NameValuePair.hashCode(), NameValuePair2.hashCode());
+    }
+
+    @Test
+    public void testNullValueNotEqual() throws Exception {
+        final NameValuePair NameValuePair = new BasicNameValuePair("name", null);
+        final NameValuePair NameValuePair2 = new BasicNameValuePair("name", "value");
+
+        Assert.assertNotEquals(NameValuePair, NameValuePair2);
+    }
+
+    @Test
+    public void testNullValue2NotEqual() throws Exception {
+        final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
+        final NameValuePair NameValuePair2 = new BasicNameValuePair("name", null);
+
+        Assert.assertNotEquals(NameValuePair, NameValuePair2);
+    }
+
+    @Test
+    public void testEquals() throws Exception {
+        final NameValuePair NameValuePair = new BasicNameValuePair("name", "value");
+        final NameValuePair NameValuePair2 = new BasicNameValuePair("name", "value");
+
+        Assert.assertEquals(NameValuePair, NameValuePair);
+        Assert.assertEquals(NameValuePair.hashCode(), NameValuePair.hashCode());
+        Assert.assertEquals(NameValuePair2, NameValuePair2);
+        Assert.assertEquals(NameValuePair2.hashCode(), NameValuePair2.hashCode());
+        Assert.assertEquals(NameValuePair, NameValuePair2);
+        Assert.assertEquals(NameValuePair.hashCode(), NameValuePair2.hashCode());
+    }
+
+    @Test
+    public void testHashCode() throws Exception {
+        final NameValuePair NameValuePair = new BasicNameValuePair("name", null);
+        final NameValuePair NameValuePair2 = new BasicNameValuePair("name2", null);
+
+        Assert.assertNotEquals(NameValuePair.hashCode(), NameValuePair2.hashCode());
+
+        final NameValuePair NameValuePair3 = new BasicNameValuePair("name", "value");
+        final NameValuePair NameValuePair4 = new BasicNameValuePair("name", "value2");
+
+        Assert.assertNotEquals(NameValuePair3.hashCode(), NameValuePair4.hashCode());
+
+        final NameValuePair NameValuePair5 = new BasicNameValuePair("name", "value");
+        final NameValuePair NameValuePair6 = new BasicNameValuePair("name", null);
+
+        Assert.assertNotEquals(NameValuePair5.hashCode(), NameValuePair6.hashCode());
+    }
+
 }


Mime
View raw message