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 c56f2bed648ab0678a5bc67ea13f06d5f7dc31cf Author: Benoit Tellier <btell...@linagora.com> AuthorDate: Mon Dec 9 14:07:18 2019 +0700 [Refactoring] BodyFetchElement should match bean contract Use standard template for this. Note that numerous EqualsVerifier issues were solved along the way... --- .../james/imap/api/message/BodyFetchElement.java | 73 +++++----------------- .../imap/api/message/BodyFetchElementTest.java | 32 ++++++++++ 2 files changed, 49 insertions(+), 56 deletions(-) diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/message/BodyFetchElement.java b/protocols/imap/src/main/java/org/apache/james/imap/api/message/BodyFetchElement.java index fe7531b..3990ed9 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/api/message/BodyFetchElement.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/api/message/BodyFetchElement.java @@ -20,6 +20,7 @@ package org.apache.james.imap.api.message; import java.util.Arrays; import java.util.Collection; +import java.util.Objects; import java.util.Optional; import org.apache.james.imap.api.ImapConstants; @@ -131,64 +132,24 @@ public class BodyFetchElement { return numberOfOctets; } - public int hashCode() { - final int PRIME = 31; - int result = 1; - result = PRIME * result + ((fieldNames == null) ? 0 : fieldNames.hashCode()); - result = PRIME * result + ((firstOctet == null) ? 0 : firstOctet.hashCode()); - result = PRIME * result + ((name == null) ? 0 : name.hashCode()); - result = PRIME * result + ((numberOfOctets == null) ? 0 : numberOfOctets.hashCode()); - result = PRIME * result + ((path == null) ? 0 : path.length); - result = PRIME * result + sectionType; - return result; + @Override + public final boolean equals(Object o) { + if (o instanceof BodyFetchElement) { + BodyFetchElement that = (BodyFetchElement) o; + + return Objects.equals(this.sectionType, that.sectionType) + && Objects.equals(this.firstOctet, that.firstOctet) + && Objects.equals(this.numberOfOctets, that.numberOfOctets) + && Objects.equals(this.name, that.name) + && Arrays.equals(this.path, that.path) + && Objects.equals(this.fieldNames, that.fieldNames); + } + return false; } - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final BodyFetchElement other = (BodyFetchElement) obj; - if (fieldNames == null) { - if (other.fieldNames != null) { - return false; - } - } else if (!fieldNames.equals(other.fieldNames)) { - return false; - } - if (firstOctet == null) { - if (other.firstOctet != null) { - return false; - } - } else if (!firstOctet.equals(other.firstOctet)) { - return false; - } - if (name == null) { - if (other.name != null) { - return false; - } - } else if (!name.equals(other.name)) { - return false; - } - if (numberOfOctets == null) { - if (other.numberOfOctets != null) { - return false; - } - } else if (!numberOfOctets.equals(other.numberOfOctets)) { - return false; - } - if (!Arrays.equals(path, other.path)) { - return false; - } - if (sectionType != other.sectionType) { - return false; - } - return true; + @Override + public final int hashCode() { + return Objects.hash(firstOctet, numberOfOctets, name, sectionType, Arrays.hashCode(path), fieldNames); } @Override diff --git a/protocols/imap/src/test/java/org/apache/james/imap/api/message/BodyFetchElementTest.java b/protocols/imap/src/test/java/org/apache/james/imap/api/message/BodyFetchElementTest.java new file mode 100644 index 0000000..2a5bad9 --- /dev/null +++ b/protocols/imap/src/test/java/org/apache/james/imap/api/message/BodyFetchElementTest.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.api.message; + +import org.junit.jupiter.api.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +class BodyFetchElementTest { + @Test + void shouldMatchBeanContract() { + EqualsVerifier.forClass(BodyFetchElement.class) + .verify(); + } +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org