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 c5994dfc98d449e447e1da5b8fce87ba49cded92 Author: Benoit Tellier <[email protected]> AuthorDate: Fri Dec 13 06:59:07 2019 +0100 [Refactoring] FlagsResponse: simplify & test equals & hashCode --- .../james/imap/message/response/FlagsResponse.java | 46 +++++++---------- .../imap/message/response/FlagsResponseTest.java} | 57 +++------------------- 2 files changed, 25 insertions(+), 78 deletions(-) diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/response/FlagsResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/message/response/FlagsResponse.java index 7c58a93..1925c4b 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/message/response/FlagsResponse.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/message/response/FlagsResponse.java @@ -19,6 +19,8 @@ package org.apache.james.imap.message.response; +import java.util.Objects; + import javax.mail.Flags; import org.apache.james.imap.api.message.response.ImapResponseMessage; @@ -30,44 +32,30 @@ public class FlagsResponse implements ImapResponseMessage { private final Flags flags; public FlagsResponse(Flags flags) { - super(); this.flags = flags; } - public String toString() { - return "Flags: " + flags; - } - public Flags getFlags() { return flags; } - public int hashCode() { - final int PRIME = 31; - int result = 1; - result = PRIME * result + ((flags == null) ? 0 : flags.hashCode()); - return result; - } + @Override + public final boolean equals(Object o) { + if (o instanceof FlagsResponse) { + FlagsResponse that = (FlagsResponse) o; - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; + return Objects.equals(this.flags, that.flags); } - if (getClass() != obj.getClass()) { - return false; - } - final FlagsResponse other = (FlagsResponse) obj; - if (flags == null) { - if (other.flags != null) { - return false; - } - } else if (!flags.equals(other.flags)) { - return false; - } - return true; + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(flags); } + @Override + public String toString() { + return "Flags: " + flags; + } } diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/response/FlagsResponse.java b/protocols/imap/src/test/java/org/apache/james/imap/message/response/FlagsResponseTest.java similarity index 51% copy from protocols/imap/src/main/java/org/apache/james/imap/message/response/FlagsResponse.java copy to protocols/imap/src/test/java/org/apache/james/imap/message/response/FlagsResponseTest.java index 7c58a93..650079d 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/message/response/FlagsResponse.java +++ b/protocols/imap/src/test/java/org/apache/james/imap/message/response/FlagsResponseTest.java @@ -19,55 +19,14 @@ package org.apache.james.imap.message.response; -import javax.mail.Flags; +import org.junit.jupiter.api.Test; -import org.apache.james.imap.api.message.response.ImapResponseMessage; +import nl.jqno.equalsverifier.EqualsVerifier; -/** - * Carries a RFC3501 <code>Flags</code> response. - */ -public class FlagsResponse implements ImapResponseMessage { - private final Flags flags; - - public FlagsResponse(Flags flags) { - super(); - this.flags = flags; - } - - public String toString() { - return "Flags: " + flags; - } - - public Flags getFlags() { - return flags; +class FlagsResponseTest { + @Test + void shouldMatchBeanContract() { + EqualsVerifier.forClass(FlagsResponse.class) + .verify(); } - - public int hashCode() { - final int PRIME = 31; - int result = 1; - result = PRIME * result + ((flags == null) ? 0 : flags.hashCode()); - return result; - } - - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final FlagsResponse other = (FlagsResponse) obj; - if (flags == null) { - if (other.flags != null) { - return false; - } - } else if (!flags.equals(other.flags)) { - return false; - } - return true; - } - -} +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
