You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/09/20 12:10:31 UTC
[james-project] 12/15: JAMES-2894 Add equals verfier tests for
modified equals/hashcode methods
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 1574dbb9ccbdbfc5f89b1fc9fbd1a86bc81ce491
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Sep 10 09:50:50 2019 +0700
JAMES-2894 Add equals verfier tests for modified equals/hashcode methods
---
.../apache/james/mailbox/model/UpdatedFlags.java | 5 ++-
.../james/mailbox/model/UpdatedFlagsTest.java | 9 +++++
.../store/mail/model/impl/SimpleProperty.java | 30 +++++++--------
.../store/mail/model/impl/SimplePropertyTest.java | 32 ++++++++++++++++
.../james/imap/message/response/ACLResponse.java | 23 +++++------
.../imap/message/response/ListRightsResponse.java | 27 ++++++-------
.../imap/message/response/MyRightsResponse.java | 23 +++++------
.../james/imap/message/response/QuotaResponse.java | 25 ++++++------
.../imap/message/response/QuotaRootResponse.java | 23 +++++------
.../imap/message/response/ACLResponseTest.java | 32 ++++++++++++++++
.../message/response/ListRightsResponseTest.java | 32 ++++++++++++++++
.../message/response/MyRightsResponseTest.java | 32 ++++++++++++++++
.../imap/message/response/QuotaResponseTest.java | 44 ++++++++++++++++++++++
.../message/response/QuotaRootResponseTest.java | 32 ++++++++++++++++
14 files changed, 293 insertions(+), 76 deletions(-)
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/UpdatedFlags.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/UpdatedFlags.java
index b6690d2..238b23d 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/UpdatedFlags.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/UpdatedFlags.java
@@ -23,6 +23,7 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.Objects;
import java.util.Optional;
+
import javax.mail.Flags;
import org.apache.james.mailbox.MessageUid;
@@ -230,7 +231,7 @@ public class UpdatedFlags {
}
@Override
- public boolean equals(Object other) {
+ public final boolean equals(Object other) {
if (this == other) {
return true;
}
@@ -247,7 +248,7 @@ public class UpdatedFlags {
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return Objects.hash(uid, oldFlags, newFlags, modSeq);
}
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/UpdatedFlagsTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/UpdatedFlagsTest.java
index e660dbc..e79e566 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/UpdatedFlagsTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/UpdatedFlagsTest.java
@@ -26,12 +26,21 @@ import javax.mail.Flags;
import org.apache.james.mailbox.MessageUid;
import org.junit.Test;
+import nl.jqno.equalsverifier.EqualsVerifier;
+
public class UpdatedFlagsTest {
public static final MessageUid UID = MessageUid.of(45L);
public static final long MOD_SEQ = 47L;
@Test
+ public void shouldMatchBeanContract() {
+ EqualsVerifier.forClass(UpdatedFlags.class)
+ .withIgnoredFields("modifiedFlags")
+ .verify();
+ }
+
+ @Test
public void isModifiedToSetShouldReturnTrueWhenFlagOnlyInNewFlag() {
UpdatedFlags updatedFlags = UpdatedFlags.builder()
.newFlags(new Flags(Flags.Flag.RECENT))
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleProperty.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleProperty.java
index 374f6d1..aef6244 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleProperty.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleProperty.java
@@ -22,6 +22,8 @@ import java.util.Objects;
import org.apache.james.mailbox.store.mail.model.Property;
+import com.google.common.base.MoreObjects;
+
public final class SimpleProperty implements Property {
private final String namespace;
private final String localName;
@@ -88,31 +90,27 @@ public final class SimpleProperty implements Property {
* of this object.
*/
public String toString() {
- return "SimpleProperty("
- + "namespace='" + this.namespace
- + "' localName='" + this.localName
- + "' value='" + this.value
- + "')";
+ return MoreObjects.toStringHelper(this)
+ .add("namespace", namespace)
+ .add("localName", localName)
+ .add("value", value)
+ .toString();
}
@Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof SimpleProperty)) {
- return false;
- }
- SimpleProperty that = (SimpleProperty) o;
+ public final boolean equals(Object o) {
+ if (o instanceof SimpleProperty) {
+ SimpleProperty that = (SimpleProperty) o;
- return Objects.equals(namespace, that.namespace) &&
+ return Objects.equals(namespace, that.namespace) &&
Objects.equals(localName, that.localName) &&
Objects.equals(value, that.value);
-
+ }
+ return false;
}
@Override
- public int hashCode() {
+ public final int hashCode() {
return Objects.hash(namespace, localName, value);
}
}
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimplePropertyTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimplePropertyTest.java
new file mode 100644
index 0000000..5d5e979
--- /dev/null
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimplePropertyTest.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.mailbox.store.mail.model.impl;
+
+import org.junit.jupiter.api.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+class SimplePropertyTest {
+ @Test
+ void shouldMatchBeanContract() {
+ EqualsVerifier.forClass(SimpleProperty.class)
+ .verify();
+ }
+}
\ No newline at end of file
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/response/ACLResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/message/response/ACLResponse.java
index fbe53d7..29c2ae2 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/response/ACLResponse.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/response/ACLResponse.java
@@ -43,16 +43,6 @@ public final class ACLResponse implements ImapResponseMessage {
this.acl = acl;
}
- @Override
- public boolean equals(Object o) {
- if (o instanceof ACLResponse) {
- ACLResponse other = (ACLResponse) o;
- return (Objects.equals(this.acl, other.acl))
- && (Objects.equals(this.mailboxName, other.mailboxName));
- }
- return false;
- }
-
public MailboxACL getAcl() {
return acl;
}
@@ -62,7 +52,18 @@ public final class ACLResponse implements ImapResponseMessage {
}
@Override
- public int hashCode() {
+ public final boolean equals(Object o) {
+ if (o instanceof ACLResponse) {
+ ACLResponse other = (ACLResponse) o;
+
+ return Objects.equals(this.acl, other.acl)
+ && Objects.equals(this.mailboxName, other.mailboxName);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
return Objects.hash(acl, mailboxName);
}
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/response/ListRightsResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/message/response/ListRightsResponse.java
index 4e07406..0b64328 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/response/ListRightsResponse.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/response/ListRightsResponse.java
@@ -42,17 +42,6 @@ public final class ListRightsResponse implements ImapResponseMessage {
this.rights = rights;
}
- @Override
- public boolean equals(Object o) {
- if (o instanceof ListRightsResponse) {
- ListRightsResponse other = (ListRightsResponse) o;
- return (Objects.equals(this.mailboxName, other.mailboxName)) &&
- (Objects.equals(this.identifier, other.identifier)) &&
- Arrays.equals(this.rights, other.rights);
- }
- return false;
- }
-
public String getIdentifier() {
return identifier;
}
@@ -66,8 +55,20 @@ public final class ListRightsResponse implements ImapResponseMessage {
}
@Override
- public int hashCode() {
- return Objects.hash(mailboxName, identifier, rights);
+ public final boolean equals(Object o) {
+ if (o instanceof ListRightsResponse) {
+ ListRightsResponse other = (ListRightsResponse) o;
+
+ return Objects.equals(this.mailboxName, other.mailboxName) &&
+ Objects.equals(this.identifier, other.identifier) &&
+ Arrays.equals(this.rights, other.rights);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(mailboxName, identifier, Arrays.hashCode(rights));
}
@Override
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/response/MyRightsResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/message/response/MyRightsResponse.java
index 30e853c..2468cdc 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/response/MyRightsResponse.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/response/MyRightsResponse.java
@@ -38,16 +38,6 @@ public final class MyRightsResponse implements ImapResponseMessage {
this.myRights = myRights;
}
- @Override
- public boolean equals(Object o) {
- if (o instanceof MyRightsResponse) {
- MyRightsResponse other = (MyRightsResponse) o;
- return Objects.equals(this.myRights, other.myRights) &&
- Objects.equals(this.mailboxName, other.mailboxName);
- }
- return false;
- }
-
public String getMailboxName() {
return mailboxName;
}
@@ -57,7 +47,18 @@ public final class MyRightsResponse implements ImapResponseMessage {
}
@Override
- public int hashCode() {
+ public final boolean equals(Object o) {
+ if (o instanceof MyRightsResponse) {
+ MyRightsResponse other = (MyRightsResponse) o;
+
+ return Objects.equals(this.myRights, other.myRights) &&
+ Objects.equals(this.mailboxName, other.mailboxName);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
return Objects.hash(myRights, mailboxName);
}
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/response/QuotaResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/message/response/QuotaResponse.java
index 5a2e239..07b3c7a 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/response/QuotaResponse.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/response/QuotaResponse.java
@@ -39,17 +39,6 @@ public class QuotaResponse implements ImapResponseMessage {
this.quotaRoot = quotaRoot;
}
- @Override
- public boolean equals(Object o) {
- if (o instanceof QuotaResponse) {
- QuotaResponse other = (QuotaResponse) o;
- return Objects.equal(this.quotaRoot, other.quotaRoot)
- && Objects.equal(this.resourceName, other.resourceName)
- && Objects.equal(this.quota, other.quota);
- }
- return false;
- }
-
public Quota<?> getQuota() {
return quota;
}
@@ -63,7 +52,19 @@ public class QuotaResponse implements ImapResponseMessage {
}
@Override
- public int hashCode() {
+ public final boolean equals(Object o) {
+ if (o instanceof QuotaResponse) {
+ QuotaResponse other = (QuotaResponse) o;
+
+ return Objects.equal(this.quotaRoot, other.quotaRoot)
+ && Objects.equal(this.resourceName, other.resourceName)
+ && Objects.equal(this.quota, other.quota);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
return Objects.hashCode(resourceName, quotaRoot, quota);
}
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/response/QuotaRootResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/message/response/QuotaRootResponse.java
index 604b75f..8ed9498 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/response/QuotaRootResponse.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/response/QuotaRootResponse.java
@@ -35,16 +35,6 @@ public class QuotaRootResponse implements ImapResponseMessage {
this.quotaRoot = quotaRoot;
}
- @Override
- public boolean equals(Object o) {
- if (o instanceof QuotaRootResponse) {
- QuotaRootResponse other = (QuotaRootResponse) o;
- return Objects.equals(this.quotaRoot, other.quotaRoot) &&
- Objects.equals(this.mailboxName, other.mailboxName);
- }
- return false;
- }
-
public String getQuotaRoot() {
return quotaRoot;
}
@@ -54,7 +44,18 @@ public class QuotaRootResponse implements ImapResponseMessage {
}
@Override
- public int hashCode() {
+ public final boolean equals(Object o) {
+ if (o instanceof QuotaRootResponse) {
+ QuotaRootResponse other = (QuotaRootResponse) o;
+
+ return Objects.equals(this.quotaRoot, other.quotaRoot) &&
+ Objects.equals(this.mailboxName, other.mailboxName);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
return Objects.hash(quotaRoot, mailboxName);
}
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/message/response/ACLResponseTest.java b/protocols/imap/src/test/java/org/apache/james/imap/message/response/ACLResponseTest.java
new file mode 100644
index 0000000..3e069f9
--- /dev/null
+++ b/protocols/imap/src/test/java/org/apache/james/imap/message/response/ACLResponseTest.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.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+public class ACLResponseTest {
+ @Test
+ public void shouldMatchBeanContract() {
+ EqualsVerifier.forClass(ACLResponse.class)
+ .verify();
+ }
+}
\ No newline at end of file
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/message/response/ListRightsResponseTest.java b/protocols/imap/src/test/java/org/apache/james/imap/message/response/ListRightsResponseTest.java
new file mode 100644
index 0000000..7e95fdd
--- /dev/null
+++ b/protocols/imap/src/test/java/org/apache/james/imap/message/response/ListRightsResponseTest.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.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+public class ListRightsResponseTest {
+ @Test
+ public void shouldMatchBeanContract() {
+ EqualsVerifier.forClass(ListRightsResponse.class)
+ .verify();
+ }
+}
\ No newline at end of file
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/message/response/MyRightsResponseTest.java b/protocols/imap/src/test/java/org/apache/james/imap/message/response/MyRightsResponseTest.java
new file mode 100644
index 0000000..94ab1a4
--- /dev/null
+++ b/protocols/imap/src/test/java/org/apache/james/imap/message/response/MyRightsResponseTest.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.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+public class MyRightsResponseTest {
+ @Test
+ public void shouldMatchBeanContract() {
+ EqualsVerifier.forClass(MyRightsResponse.class)
+ .verify();
+ }
+}
\ No newline at end of file
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/message/response/QuotaResponseTest.java b/protocols/imap/src/test/java/org/apache/james/imap/message/response/QuotaResponseTest.java
new file mode 100644
index 0000000..cd3ffda
--- /dev/null
+++ b/protocols/imap/src/test/java/org/apache/james/imap/message/response/QuotaResponseTest.java
@@ -0,0 +1,44 @@
+/****************************************************************
+ * 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.apache.james.core.quota.QuotaCount;
+import org.apache.james.mailbox.model.Quota;
+import org.junit.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+public class QuotaResponseTest {
+ @Test
+ public void shouldMatchBeanContract() {
+ Quota<QuotaCount> red = Quota.<QuotaCount>builder()
+ .computedLimit(QuotaCount.count(36))
+ .used(QuotaCount.count(22))
+ .build();
+ Quota<QuotaCount> black = Quota.<QuotaCount>builder()
+ .computedLimit(QuotaCount.count(32))
+ .used(QuotaCount.count(24))
+ .build();
+
+ EqualsVerifier.forClass(QuotaResponse.class)
+ .withPrefabValues(Quota.class, red, black)
+ .verify();
+ }
+}
\ No newline at end of file
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/message/response/QuotaRootResponseTest.java b/protocols/imap/src/test/java/org/apache/james/imap/message/response/QuotaRootResponseTest.java
new file mode 100644
index 0000000..17bc892
--- /dev/null
+++ b/protocols/imap/src/test/java/org/apache/james/imap/message/response/QuotaRootResponseTest.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.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+public class QuotaRootResponseTest {
+ @Test
+ public void shouldMatchBeanContract() {
+ EqualsVerifier.forClass(QuotaRootResponse.class)
+ .verify();
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org