This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit f9c4e179b0b092895ec2e54ad31b5203733b83f3
Author: Benoit Tellier <[email protected]>
AuthorDate: Fri Dec 13 06:56:48 2019 +0100

    [Refactoring] SearchResponse: simplify & test equals & hashCode
---
 .../imap/message/response/SearchResponse.java      | 33 ++++++++--------------
 .../imap/message/response/SearchResponseTest.java  | 32 +++++++++++++++++++++
 2 files changed, 43 insertions(+), 22 deletions(-)

diff --git 
a/protocols/imap/src/main/java/org/apache/james/imap/message/response/SearchResponse.java
 
b/protocols/imap/src/main/java/org/apache/james/imap/message/response/SearchResponse.java
index e11f8bb..422bf41 100644
--- 
a/protocols/imap/src/main/java/org/apache/james/imap/message/response/SearchResponse.java
+++ 
b/protocols/imap/src/main/java/org/apache/james/imap/message/response/SearchResponse.java
@@ -20,6 +20,7 @@
 package org.apache.james.imap.message.response;
 
 import java.util.Arrays;
+import java.util.Objects;
 
 import org.apache.james.imap.api.message.response.ImapResponseMessage;
 import org.apache.james.mailbox.ModSeq;
@@ -35,10 +36,8 @@ public class SearchResponse implements ImapResponseMessage {
      * Constructs a <code>SEARCH</code> response.
      * 
      * @param ids ids, not null
-     * @param highestModSeq
      */
     public SearchResponse(long[] ids, ModSeq highestModSeq) {
-        super();
         this.ids = ids;
         this.highestModSeq = highestModSeq;
     }
@@ -63,29 +62,19 @@ public class SearchResponse implements ImapResponseMessage {
     }
 
     @Override
-    public int hashCode() {
-        return ids.length;
+    public final boolean equals(Object o) {
+        if (o instanceof SearchResponse) {
+            SearchResponse that = (SearchResponse) o;
+
+            return Arrays.equals(this.ids, that.ids)
+                && Objects.equals(this.highestModSeq, that.highestModSeq);
+        }
+        return false;
     }
 
     @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        final SearchResponse other = (SearchResponse) obj;
-        if (!Arrays.equals(ids, other.ids)) {
-            return false;
-        }
-        if (highestModSeq != other.highestModSeq) {
-            return false;
-        }
-        return true;
+    public final int hashCode() {
+        return Objects.hash(Arrays.hashCode(ids), highestModSeq);
     }
 
     /**
diff --git 
a/protocols/imap/src/test/java/org/apache/james/imap/message/response/SearchResponseTest.java
 
b/protocols/imap/src/test/java/org/apache/james/imap/message/response/SearchResponseTest.java
new file mode 100644
index 0000000..fb97581
--- /dev/null
+++ 
b/protocols/imap/src/test/java/org/apache/james/imap/message/response/SearchResponseTest.java
@@ -0,0 +1,32 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.imap.message.response;
+
+import org.junit.jupiter.api.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+class SearchResponseTest {
+    @Test
+    void shouldMatchBeanContract() {
+        EqualsVerifier.forClass(SearchResponse.class)
+            .verify();
+    }
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to