james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [16/34] james-project git commit: JAMES-2085 Remove unneeded exception handling
Date Wed, 05 Jul 2017 13:59:23 GMT
JAMES-2085 Remove unneeded exception handling

MessageId serialization is handled by capabilities


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

Branch: refs/heads/master
Commit: 746bbc89748141723194ca03cac499877f911d78
Parents: 8a88876
Author: benwa <btellier@linagora.com>
Authored: Mon Jul 3 16:37:46 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Jul 5 17:13:48 2017 +0700

----------------------------------------------------------------------
 .../json/IndexableMessageTest.java              | 32 ------------------
 .../james/mailbox/store/search/SearchUtil.java  | 11 +++---
 .../comparator/AbstractHeaderComparator.java    | 10 +++---
 .../mailbox/store/search/SearchUtilTest.java    | 35 --------------------
 4 files changed, 9 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/746bbc89/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageTest.java
b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageTest.java
index db221b7..5fbb373 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageTest.java
@@ -502,38 +502,6 @@ public class IndexableMessageTest {
         // Then
         assertThat(indexableMessage.getText()).contains("subject should be parsed");
     }
-    
-    @Test
-    public void  shouldHandleCorrectlyMessageIdHavingSerializeMethodThatThrowAnException()
throws Exception {
-       MessageId invalidMessageIdThatThrowException = mock(MessageId.class);
-       when(invalidMessageIdThatThrowException.serialize())
-           .thenThrow(new UnsupportedOperationException());
-       
-        // When
-        MailboxMessage mailboxMessage = mock(MailboxMessage.class);
-        TestId mailboxId = TestId.of(1);
-        when(mailboxMessage.getMailboxId())
-            .thenReturn(mailboxId);
-        when(mailboxMessage.getMessageId())
-            .thenReturn(invalidMessageIdThatThrowException);
-        when(mailboxMessage.getFullContent())
-            .thenReturn(new ByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/bodyMakeTikaToFail.eml"))));
-        when(mailboxMessage.createFlags())
-            .thenReturn(new Flags());
-        when(mailboxMessage.getUid())
-            .thenReturn(MESSAGE_UID);
-
-        IndexableMessage indexableMessage = IndexableMessage.builder()
-                .message(mailboxMessage)
-                .users(ImmutableList.of(new MockMailboxSession("username").getUser()))
-                .extractor(textExtractor)
-                .zoneId(ZoneId.of("Europe/Paris"))
-                .indexAttachments(IndexAttachments.YES)
-                .build();
-
-        // Then
-        assertThat(indexableMessage.getMessageId()).isNull();
-    }
 
     @Test
     public void shouldHandleCorrectlyMessageIdHavingSerializeMethodThatReturnNull() throws
Exception {

http://git-wip-us.apache.org/repos/asf/james-project/blob/746bbc89/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SearchUtil.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SearchUtil.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SearchUtil.java
index 39ec71b..703385c 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SearchUtil.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SearchUtil.java
@@ -180,13 +180,10 @@ public class SearchUtil {
 
 
     public static String getSerializedMessageIdIfSupportedByUnderlyingStorageOrNull(MailboxMessage
mailboxMessage) {
-        try {
-            MessageId messageId = mailboxMessage.getMessageId();
-            if (messageId != null) {
-                return messageId.serialize();
-            }
-        } catch(UnsupportedOperationException e) {}
-
+        MessageId messageId = mailboxMessage.getMessageId();
+        if (messageId != null) {
+            return messageId.serialize();
+        }
         return null;
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/746bbc89/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/comparator/AbstractHeaderComparator.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/comparator/AbstractHeaderComparator.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/comparator/AbstractHeaderComparator.java
index b626482..37f2c0f 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/comparator/AbstractHeaderComparator.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/comparator/AbstractHeaderComparator.java
@@ -43,11 +43,11 @@ public abstract class AbstractHeaderComparator implements Comparator<MailboxMess
         try {
             final List<Header> headers = ResultUtils.createHeaders(message);
             for (Header header : headers) {
-                    String name = header.getName();
-                    if (headerName.equalsIgnoreCase(name)) {
-                        final String value = header.getValue();
-                        return value.toUpperCase(Locale.US);
-                    }
+                String name = header.getName();
+                if (headerName.equalsIgnoreCase(name)) {
+                    final String value = header.getValue();
+                    return value.toUpperCase(Locale.US);
+                }
 
             }
         } catch (IOException e) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/746bbc89/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/SearchUtilTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/SearchUtilTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/SearchUtilTest.java
index 542ef9c..8dcccff 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/SearchUtilTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/SearchUtilTest.java
@@ -104,24 +104,6 @@ public class SearchUtilTest {
     }
 
     @Test
-    public void getSerializedMessageIdIfSupportedByUnderlyingStorageOrNullForMessageIdThatSerializeReturnUnsupportedOperationExceptionShouldReturnNull()
{
-        //given
-        MessageId invalidMessageIdThatThrowException = mock(MessageId.class);
-        when(invalidMessageIdThatThrowException.serialize())
-            .thenThrow(new UnsupportedOperationException());
-
-        MailboxMessage message = mock(MailboxMessage.class);
-        when(message.getMessageId())
-            .thenReturn(invalidMessageIdThatThrowException);
-
-        //when
-        String serialiazedMessageId = SearchUtil.getSerializedMessageIdIfSupportedByUnderlyingStorageOrNull(message);
-
-        //expect
-        assertNull(serialiazedMessageId);
-    }
-
-    @Test
     public void getSerializedMessageIdIfSupportedByUnderlyingStorageOrNullForValidMessageIdShouldReturnSerializedId()
{
         //given
         String messageIdString = "http://www.labraxeenne.com/#/";
@@ -140,21 +122,4 @@ public class SearchUtilTest {
         assertEquals(serialiazedMessageId, messageIdString);
     }
 
-    @Test
-    public void getSerializedMessageIdIfSupportedByUnderlyingStorageOrNullForMessageIdThatReturnUssuportedOperationException()
{
-        //given
-        MessageId messageId = mock(MessageId.class);
-        when(messageId.serialize())
-            .thenThrow(new UnsupportedOperationException());
-
-        MailboxMessage message = mock(MailboxMessage.class);
-        when(message.getMessageId())
-            .thenReturn(messageId);
-
-        //when
-        String serialiazedMessageId = SearchUtil.getSerializedMessageIdIfSupportedByUnderlyingStorageOrNull(message);
-
-        //expect
-        assertEquals(serialiazedMessageId, null);
-    }
 }


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