james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [02/10] james-project git commit: JAMES-2557 Correct MailAddress equality support for nullSender
Date Wed, 24 Oct 2018 01:51:28 GMT
JAMES-2557 Correct MailAddress equality support for nullSender

Comparing a nullSender address with a non null sender address was throwing.


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/ebb74946
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/ebb74946
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/ebb74946

Branch: refs/heads/master
Commit: ebb749461b5c00f8e77290a2e08dc24c9f4eac34
Parents: cfca550
Author: Benoit Tellier <btellier@linagora.com>
Authored: Thu Oct 18 18:10:47 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Oct 24 08:47:34 2018 +0700

----------------------------------------------------------------------
 .../main/java/org/apache/james/core/MailAddress.java  | 14 ++++++++++----
 .../java/org/apache/james/core/MailAddressTest.java   | 12 ++++++++++++
 2 files changed, 22 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/ebb74946/core/src/main/java/org/apache/james/core/MailAddress.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/james/core/MailAddress.java b/core/src/main/java/org/apache/james/core/MailAddress.java
index 02b5ce6..78db46c 100644
--- a/core/src/main/java/org/apache/james/core/MailAddress.java
+++ b/core/src/main/java/org/apache/james/core/MailAddress.java
@@ -381,12 +381,18 @@ public class MailAddress implements java.io.Serializable {
             String theString = (String) obj;
             return toString().equalsIgnoreCase(theString);
         } else if (obj instanceof MailAddress) {
-            MailAddress addr = (MailAddress) obj;
-            if (isNullSender() && addr.isNullSender()) {
+            MailAddress that = (MailAddress) obj;
+            boolean bothNullSender = this.isNullSender() && that.isNullSender();
+            boolean onlyOneIsNullSender = isNullSender() ^ that.isNullSender();
+
+            if (bothNullSender) {
                 return true;
             }
-            return equalsIgnoreCase(getLocalPart(), addr.getLocalPart())
-                && Objects.equals(getDomain(), addr.getDomain());
+            if (onlyOneIsNullSender) {
+                return false;
+            }
+            return equalsIgnoreCase(getLocalPart(), that.getLocalPart())
+                && Objects.equals(getDomain(), that.getDomain());
         }
         return false;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/ebb74946/core/src/test/java/org/apache/james/core/MailAddressTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/james/core/MailAddressTest.java b/core/src/test/java/org/apache/james/core/MailAddressTest.java
index b8f6986..16e9a5b 100644
--- a/core/src/test/java/org/apache/james/core/MailAddressTest.java
+++ b/core/src/test/java/org/apache/james/core/MailAddressTest.java
@@ -245,6 +245,18 @@ public class MailAddressTest {
     }
 
     @Test
+    public void equalsShouldReturnFalseWhenOnlyFirstMemberIsANullSender() {
+        assertThat(MailAddress.getMailSender(GOOD_ADDRESS))
+            .isNotEqualTo(MailAddress.nullSender());
+    }
+
+    @Test
+    public void equalsShouldReturnFalseWhenOnlySecondMemberIsANullSender() {
+        assertThat(MailAddress.nullSender())
+            .isNotEqualTo(MailAddress.getMailSender(GOOD_ADDRESS));
+    }
+
+    @Test
     public void shouldMatchBeanContract() {
         EqualsVerifier.forClass(MailAddress.class)
             .verify();


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message