james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [7/8] james-project git commit: structural refactoring from assert{, Not}Null to assertj assertThat().withFailMessage().is{, Not}Null
Date Thu, 06 Sep 2018 12:34:51 GMT
structural refactoring from assert{,Not}Null to assertj assertThat().withFailMessage().is{,Not}Null


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

Branch: refs/heads/master
Commit: 137d6c79e3201f0a57298ad2144abd7553bbb407
Parents: bf6b9d0
Author: Matthieu Baechler <matthieu@apache.org>
Authored: Thu May 31 21:40:35 2018 +0200
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Thu Sep 6 14:34:19 2018 +0200

----------------------------------------------------------------------
 .../HBaseMailboxSessionMapperFactoryTest.java   |  1 -
 .../apache/mailet/base/MatcherInverterTest.java |  7 +++----
 .../AbstractTestForStatusResponseFactory.java   |  1 -
 .../smtp/core/fastfail/DNSRBLHandlerTest.java   | 20 +++++++++-----------
 .../fastfail/ResolvableEhloHeloHandlerTest.java | 14 +++++++-------
 .../core/MimeMessageCopyOnWriteProxyTest.java   |  2 --
 .../dnsservice/dnsjava/DNSJavaServiceTest.java  |  3 +--
 .../lib/AbstractStateMailetProcessorTest.java   |  2 --
 .../smtpserver/SpamAssassinHandlerTest.java     |  9 +++++----
 9 files changed, 25 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/137d6c79/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxSessionMapperFactoryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxSessionMapperFactoryTest.java
b/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxSessionMapperFactoryTest.java
index aa84956..a387445 100644
--- a/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxSessionMapperFactoryTest.java
+++ b/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxSessionMapperFactoryTest.java
@@ -31,7 +31,6 @@ import static org.apache.james.mailbox.hbase.HBaseNames.SUBSCRIPTIONS_TABLE;
 import static org.apache.james.mailbox.hbase.HBaseNames.SUBSCRIPTION_CF;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 
 import java.io.IOException;
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/137d6c79/mailet/base/src/test/java/org/apache/mailet/base/MatcherInverterTest.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/test/java/org/apache/mailet/base/MatcherInverterTest.java b/mailet/base/src/test/java/org/apache/mailet/base/MatcherInverterTest.java
index d95001c..0701484 100644
--- a/mailet/base/src/test/java/org/apache/mailet/base/MatcherInverterTest.java
+++ b/mailet/base/src/test/java/org/apache/mailet/base/MatcherInverterTest.java
@@ -19,9 +19,8 @@
 
 package org.apache.mailet.base;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
 
 import java.util.Arrays;
 import java.util.Collection;
@@ -48,7 +47,7 @@ public class MatcherInverterTest {
                 .recipient(new MailAddress("user", "domain"))
                 .build();
 
-        assertNotNull("Should match all recipients", inverter.match(mail));
+        assertThat(inverter.match(mail)).withFailMessage("Should match all recipients").isNotNull();
     }
 
     @Test
@@ -67,7 +66,7 @@ public class MatcherInverterTest {
                 .recipients(address1, address2)
                 .build();
 
-        assertNull("Should match all recipients", inverter.match(mail));
+        assertThat(inverter.match(mail)).withFailMessage("Should match all recipients").isNull();
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/137d6c79/protocols/imap/src/test/java/org/apache/james/imap/api/message/response/AbstractTestForStatusResponseFactory.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/api/message/response/AbstractTestForStatusResponseFactory.java
b/protocols/imap/src/test/java/org/apache/james/imap/api/message/response/AbstractTestForStatusResponseFactory.java
index 7dd771f..628d44e 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/api/message/response/AbstractTestForStatusResponseFactory.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/api/message/response/AbstractTestForStatusResponseFactory.java
@@ -21,7 +21,6 @@ package org.apache.james.imap.api.message.response;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.display.HumanReadableText;

http://git-wip-us.apache.org/repos/asf/james-project/blob/137d6c79/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/core/fastfail/DNSRBLHandlerTest.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/core/fastfail/DNSRBLHandlerTest.java
b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/core/fastfail/DNSRBLHandlerTest.java
index af425d4..82b3180 100644
--- a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/core/fastfail/DNSRBLHandlerTest.java
+++ b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/core/fastfail/DNSRBLHandlerTest.java
@@ -23,8 +23,6 @@ package org.apache.james.protocols.smtp.core.fastfail;
 import static org.apache.james.protocols.api.ProtocolSession.State.Connection;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
 
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
@@ -189,7 +187,7 @@ public class DNSRBLHandlerTest {
         rbl.doRcpt(mockedSMTPSession, null, new MailAddress("test@localhost"));
         assertEquals("Details","Blocked - see http://www.spamcop.net/bl.shtml?127.0.0.2",
                mockedSMTPSession.getAttachment(RBL_DETAIL_MAIL_ATTRIBUTE_NAME, State.Connection));
-        assertNotNull("Blocked",mockedSMTPSession.getAttachment(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME,
State.Connection));
+        assertThat(mockedSMTPSession.getAttachment(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME, Connection)).withFailMessage("Blocked").isNotNull();
     }
 
     // ip is blacklisted and has txt details but we don'T want to retrieve the txt record
@@ -201,8 +199,8 @@ public class DNSRBLHandlerTest {
         rbl.setBlacklist(new String[] { "bl.spamcop.net." });
         rbl.setGetDetail(false);
         rbl.doRcpt(mockedSMTPSession, null, new MailAddress("test@localhost"));
-        assertNull("No details",mockedSMTPSession.getAttachment(RBL_DETAIL_MAIL_ATTRIBUTE_NAME,
State.Connection));
-        assertNotNull("Blocked",mockedSMTPSession.getAttachment(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME,
State.Connection));
+        assertThat(mockedSMTPSession.getAttachment(RBL_DETAIL_MAIL_ATTRIBUTE_NAME, Connection)).withFailMessage("No
details").isNull();
+        assertThat(mockedSMTPSession.getAttachment(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME, Connection)).withFailMessage("Blocked").isNotNull();
     }
 
     // ip is allowed to relay
@@ -215,8 +213,8 @@ public class DNSRBLHandlerTest {
         rbl.setBlacklist(new String[] { "bl.spamcop.net." });
         rbl.setGetDetail(true);
         rbl.doRcpt(mockedSMTPSession, null, new MailAddress("test@localhost"));
-        assertNull("No details", mockedSMTPSession.getAttachment(RBL_DETAIL_MAIL_ATTRIBUTE_NAME,
State.Connection));
-        assertNull("Not blocked", mockedSMTPSession.getAttachment(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME,
State.Connection));
+        assertThat(mockedSMTPSession.getAttachment(RBL_DETAIL_MAIL_ATTRIBUTE_NAME, Connection)).withFailMessage("No
details").isNull();
+        assertThat(mockedSMTPSession.getAttachment(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME, Connection)).withFailMessage("Not
blocked").isNull();
     }
 
     // ip not on blacklist
@@ -230,8 +228,8 @@ public class DNSRBLHandlerTest {
         rbl.setBlacklist(new String[] { "bl.spamcop.net." });
         rbl.setGetDetail(true);
         rbl.doRcpt(mockedSMTPSession, null, new MailAddress("test@localhost"));
-        assertNull("No details", mockedSMTPSession.getAttachment(RBL_DETAIL_MAIL_ATTRIBUTE_NAME,
State.Connection));
-        assertNull("Not blocked", mockedSMTPSession.getAttachment(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME,
State.Connection));
+        assertThat(mockedSMTPSession.getAttachment(RBL_DETAIL_MAIL_ATTRIBUTE_NAME, Connection)).withFailMessage("No
details").isNull();
+        assertThat(mockedSMTPSession.getAttachment(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME, Connection)).withFailMessage("Not
blocked").isNull();
     }
 
     // ip on blacklist without txt details
@@ -246,7 +244,7 @@ public class DNSRBLHandlerTest {
         rbl.setGetDetail(true);
         rbl.doRcpt(mockedSMTPSession, null, new MailAddress("test@localhost"));
         assertThat(mockedSMTPSession.getAttachment(RBL_DETAIL_MAIL_ATTRIBUTE_NAME, Connection)).isNull();
-        assertNotNull("Blocked", mockedSMTPSession.getAttachment(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME,
State.Connection));
+        assertThat(mockedSMTPSession.getAttachment(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME, Connection)).withFailMessage("Blocked").isNotNull();
     }
 
     // ip on whitelist
@@ -261,7 +259,7 @@ public class DNSRBLHandlerTest {
         rbl.setGetDetail(true);
         rbl.doRcpt(mockedSMTPSession, null, new MailAddress("test@localhost"));
         assertThat(mockedSMTPSession.getAttachment(RBL_DETAIL_MAIL_ATTRIBUTE_NAME, Connection)).isNull();
-        assertNull("Not blocked", mockedSMTPSession.getAttachment(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME,
State.Connection));
+        assertThat(mockedSMTPSession.getAttachment(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME, Connection)).withFailMessage("Not
blocked").isNull();
     }
    
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/137d6c79/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/core/fastfail/ResolvableEhloHeloHandlerTest.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/core/fastfail/ResolvableEhloHeloHandlerTest.java
b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/core/fastfail/ResolvableEhloHeloHandlerTest.java
index 13682b7..85dfeef 100644
--- a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/core/fastfail/ResolvableEhloHeloHandlerTest.java
+++ b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/core/fastfail/ResolvableEhloHeloHandlerTest.java
@@ -19,9 +19,10 @@
 
 package org.apache.james.protocols.smtp.core.fastfail;
 
+import static org.apache.james.protocols.api.ProtocolSession.State.Transaction;
+import static org.apache.james.protocols.smtp.core.fastfail.ResolvableEhloHeloHandler.BAD_EHLO_HELO;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;
@@ -29,7 +30,6 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.james.core.MailAddress;
-import org.apache.james.protocols.api.ProtocolSession.State;
 import org.apache.james.protocols.smtp.SMTPSession;
 import org.apache.james.protocols.smtp.hook.HookReturnCode;
 import org.apache.james.protocols.smtp.utils.BaseFakeSMTPSession;
@@ -125,7 +125,7 @@ public class ResolvableEhloHeloHandlerTest {
         ResolvableEhloHeloHandler handler = createHandler();
         
         handler.doHelo(session, INVALID_HOST);
-        assertNotNull("Invalid HELO",session.getAttachment(ResolvableEhloHeloHandler.BAD_EHLO_HELO,
State.Transaction));
+        assertThat(session.getAttachment(BAD_EHLO_HELO, Transaction)).withFailMessage("Invalid
HELO").isNotNull();
 
         HookReturnCode result = handler.doRcpt(session,null, mailAddress).getResult();
         assertEquals("Reject", result,HookReturnCode.deny());
@@ -139,7 +139,7 @@ public class ResolvableEhloHeloHandlerTest {
 
   
         handler.doHelo(session, VALID_HOST);
-        assertNull("Valid HELO",session.getAttachment(ResolvableEhloHeloHandler.BAD_EHLO_HELO,
State.Transaction));
+        assertThat(session.getAttachment(BAD_EHLO_HELO, Transaction)).withFailMessage("Valid
HELO").isNull();
 
         HookReturnCode result = handler.doRcpt(session,null, mailAddress).getResult();
         assertEquals("Not reject", result,HookReturnCode.declined());
@@ -153,7 +153,7 @@ public class ResolvableEhloHeloHandlerTest {
 
 
         handler.doHelo(session, INVALID_HOST);
-        assertNotNull("Value stored",session.getAttachment(ResolvableEhloHeloHandler.BAD_EHLO_HELO,
State.Transaction));
+        assertThat(session.getAttachment(BAD_EHLO_HELO, Transaction)).withFailMessage("Value
stored").isNotNull();
 
 
         HookReturnCode result = handler.doRcpt(session,null, mailAddress).getResult();
@@ -169,7 +169,7 @@ public class ResolvableEhloHeloHandlerTest {
 
 
         handler.doHelo(session, INVALID_HOST);
-        assertNotNull("Value stored",session.getAttachment(ResolvableEhloHeloHandler.BAD_EHLO_HELO,
State.Transaction));
+        assertThat(session.getAttachment(BAD_EHLO_HELO, Transaction)).withFailMessage("Value
stored").isNotNull();
 
 
         HookReturnCode result = handler.doRcpt(session,null, mailAddress).getResult();

http://git-wip-us.apache.org/repos/asf/james-project/blob/137d6c79/server/container/core/src/test/java/org/apache/james/server/core/MimeMessageCopyOnWriteProxyTest.java
----------------------------------------------------------------------
diff --git a/server/container/core/src/test/java/org/apache/james/server/core/MimeMessageCopyOnWriteProxyTest.java
b/server/container/core/src/test/java/org/apache/james/server/core/MimeMessageCopyOnWriteProxyTest.java
index 5f02353..63a28ad 100644
--- a/server/container/core/src/test/java/org/apache/james/server/core/MimeMessageCopyOnWriteProxyTest.java
+++ b/server/container/core/src/test/java/org/apache/james/server/core/MimeMessageCopyOnWriteProxyTest.java
@@ -20,9 +20,7 @@ package org.apache.james.server.core;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.fail;
 
 import java.util.ArrayList;

http://git-wip-us.apache.org/repos/asf/james-project/blob/137d6c79/server/dns-service/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/DNSJavaServiceTest.java
----------------------------------------------------------------------
diff --git a/server/dns-service/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/DNSJavaServiceTest.java
b/server/dns-service/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/DNSJavaServiceTest.java
index 921cf58..bd693e8 100644
--- a/server/dns-service/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/DNSJavaServiceTest.java
+++ b/server/dns-service/dnsservice-dnsjava/src/test/java/org/apache/james/dnsservice/dnsjava/DNSJavaServiceTest.java
@@ -20,7 +20,6 @@ package org.apache.james.dnsservice.dnsjava;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyInt;
@@ -224,7 +223,7 @@ public class DNSJavaServiceTest {
     private static Zone loadZone(String zoneName) throws IOException {
         String zoneFilename = zoneName + "zone";
         URL zoneResource = Resources.getResource(DNSJavaServiceTest.class, zoneFilename);
-        assertNotNull("test resource for zone could not be loaded: " + zoneFilename, zoneResource);
+        assertThat(zoneResource).withFailMessage("test resource for zone could not be loaded:
" + zoneFilename).isNotNull();
         return new Zone(Name.fromString(zoneName), zoneResource.getFile());
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/137d6c79/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java
b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java
index bf1d173..9464bea 100644
--- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java
+++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessorTest.java
@@ -20,8 +20,6 @@ package org.apache.james.mailetcontainer.lib;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
 
 import java.io.ByteArrayInputStream;
 import java.util.Arrays;

http://git-wip-us.apache.org/repos/asf/james-project/blob/137d6c79/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
index 005bb00..7bcd836 100644
--- a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
+++ b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
@@ -18,8 +18,9 @@
  ****************************************************************/
 package org.apache.james.smtpserver;
 
+import static org.apache.james.spamassassin.SpamAssassinResult.STATUS_MAIL_ATTRIBUTE_NAME;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 
 import java.util.HashMap;
 
@@ -121,7 +122,7 @@ public class SpamAssassinHandlerTest {
 
         assertEquals("Email was not rejected", response.getResult(), HookReturnCode.declined());
         assertEquals("email was not spam", mockedMail.getAttribute(SpamAssassinResult.FLAG_MAIL_ATTRIBUTE_NAME),
"NO");
-        assertNotNull("spam hits", mockedMail.getAttribute(SpamAssassinResult.STATUS_MAIL_ATTRIBUTE_NAME));
+        assertThat(mockedMail.getAttribute(STATUS_MAIL_ATTRIBUTE_NAME)).withFailMessage("spam
hits").isNotNull();
 
     }
 
@@ -138,7 +139,7 @@ public class SpamAssassinHandlerTest {
 
         assertEquals("Email was not rejected", response.getResult(), HookReturnCode.declined());
         assertEquals("email was spam", mockedMail.getAttribute(SpamAssassinResult.FLAG_MAIL_ATTRIBUTE_NAME),
"YES");
-        assertNotNull("spam hits", mockedMail.getAttribute(SpamAssassinResult.STATUS_MAIL_ATTRIBUTE_NAME));
+        assertThat(mockedMail.getAttribute(STATUS_MAIL_ATTRIBUTE_NAME)).withFailMessage("spam
hits").isNotNull();
     }
 
     @Test
@@ -154,6 +155,6 @@ public class SpamAssassinHandlerTest {
 
         assertEquals("Email was rejected", response.getResult(), HookReturnCode.deny());
         assertEquals("email was spam", mockedMail.getAttribute(SpamAssassinResult.FLAG_MAIL_ATTRIBUTE_NAME),
"YES");
-        assertNotNull("spam hits", mockedMail.getAttribute(SpamAssassinResult.STATUS_MAIL_ATTRIBUTE_NAME));
+        assertThat(mockedMail.getAttribute(STATUS_MAIL_ATTRIBUTE_NAME)).withFailMessage("spam
hits").isNotNull();
     }
 }


---------------------------------------------------------------------
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