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 b4d98b1daf9059475b7a61beb625cc8becd1a242 Author: Benoit Tellier <btell...@linagora.com> AuthorDate: Mon Nov 25 11:14:29 2019 +0700 JAMES-2989 Rework equals & hashcode for MimePathImpl --- .../apache/james/mailbox/model/MimePathImpl.java | 28 +++++------ .../james/mailbox/model/MimePathImplTest.java} | 56 +++------------------- 2 files changed, 18 insertions(+), 66 deletions(-) diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java index d75020d..66c5fcf 100644 --- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java +++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java @@ -37,25 +37,19 @@ public class MimePathImpl implements MessageResult.MimePath { return positions; } - public int hashCode() { - return positions.length; - } + @Override + public final boolean equals(Object o) { + if (o instanceof MimePathImpl) { + MimePathImpl mimePath = (MimePathImpl) o; - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; + return Arrays.equals(this.positions, mimePath.positions); } - final MimePathImpl other = (MimePathImpl) obj; - if (!Arrays.equals(positions, other.positions)) { - return false; - } - return true; + return false; + } + + @Override + public final int hashCode() { + return Arrays.hashCode(positions); } public String toString() { diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MimePathImplTest.java similarity index 50% copy from mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java copy to mailbox/api/src/test/java/org/apache/james/mailbox/model/MimePathImplTest.java index d75020d..0b1caf9 100644 --- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MimePathImplTest.java @@ -17,58 +17,16 @@ * under the License. * ****************************************************************/ -/** - * - */ package org.apache.james.mailbox.model; -import java.util.Arrays; +import org.junit.jupiter.api.Test; -public class MimePathImpl implements MessageResult.MimePath { - private final int[] positions; +import nl.jqno.equalsverifier.EqualsVerifier; - public MimePathImpl(int[] positions) { - super(); - this.positions = positions; - } - - @Override - public int[] getPositions() { - return positions; - } - - public int hashCode() { - return positions.length; - } - - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final MimePathImpl other = (MimePathImpl) obj; - if (!Arrays.equals(positions, other.positions)) { - return false; - } - return true; - } - - public String toString() { - final StringBuilder builder = new StringBuilder("MIMEPath:"); - boolean isFirst = false; - for (int position : positions) { - if (isFirst) { - isFirst = false; - } else { - builder.append('.'); - } - builder.append(position); - } - return builder.toString(); +class MimePathImplTest { + @Test + void shouldMatchBeanContract() { + EqualsVerifier.forClass(MimePathImpl.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