JAMES-1704 SimpleMailboxMessage should have textualLineCount well copied

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

Branch: refs/heads/master
Commit: 7fb157bc78a2d4d2cde0ca4492dedd99b45b2772
Parents: 5a21b6b
Author: Benoit Tellier <btell...@linagora.com>
Authored: Fri Mar 11 14:30:14 2016 +0700
Committer: Benoit Tellier <btell...@linagora.com>
Committed: Thu Mar 24 12:44:25 2016 +0700

----------------------------------------------------------------------
 .../mail/model/impl/SimpleMailboxMessage.java   |  1 +
 .../model/impl/SimpleMailboxMessageTest.java    | 58 ++++++++++++--------
 2 files changed, 36 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7fb157bc/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
index ee15e79..0ae7aee 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
@@ -44,6 +44,7 @@ public class SimpleMailboxMessage<Id extends MailboxId> 
extends DelegatingMailbo
         SharedByteArrayInputStream content = copyFullContent(original);
         int bodyStartOctet = Ints.checkedCast(original.getFullContentOctets() 
- original.getBodyOctets());
         PropertyBuilder pBuilder = new 
PropertyBuilder(original.getProperties());
+        pBuilder.setTextualLineCount(original.getTextualLineCount());
         return new SimpleMailboxMessage<Id>(internalDate, size, 
bodyStartOctet, content, flags, pBuilder, mailboxId);
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/7fb157bc/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessageTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessageTest.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessageTest.java
index cabf6bf..17761a3 100644
--- 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessageTest.java
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessageTest.java
@@ -19,18 +19,17 @@
 package org.apache.james.mailbox.store.mail.model.impl;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.nio.charset.Charset;
 import java.util.Calendar;
+import java.util.Date;
 
 import javax.mail.Flags;
 import javax.mail.util.SharedByteArrayInputStream;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.james.mailbox.FlagsBuilder;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.store.TestId;
@@ -42,6 +41,8 @@ public class SimpleMailboxMessageTest {
     private static final Charset MESSAGE_CHARSET = Charset.forName("UTF-8");
     private static final String MESSAGE_CONTENT = "Simple message content 
without special characters";
     private static final String MESSAGE_CONTENT_SPECIAL_CHAR = "Simple message 
content with special characters: \"'(§è!çà$*`";
+    public static final TestId TEST_ID = TestId.of(1L);
+    public static final int BODY_START_OCTET = 0;
     private SimpleMailboxMessage<TestId> MESSAGE;
     private SimpleMailboxMessage<TestId> MESSAGE_SPECIAL_CHAR;
 
@@ -53,35 +54,27 @@ public class SimpleMailboxMessageTest {
 
     @Test
     public void testSize() {
-        assertEquals(MESSAGE_CONTENT.length(), MESSAGE.getFullContentOctets());
+        
assertThat(MESSAGE.getFullContentOctets()).isEqualTo(MESSAGE_CONTENT.length());
     }
 
     @Test
     public void testInputStreamSize() throws IOException {
-        InputStream is = MESSAGE.getFullContent();
-        int byteCount = 0;
-        while (is.read() != -1) {
-            byteCount++;
-        }
-        assertEquals(MESSAGE_CONTENT.length(), byteCount);
+        ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream();
+        byteArrayOutputStream.write(MESSAGE.getFullContent());
+        
assertThat(byteArrayOutputStream.size()).isEqualTo(MESSAGE_CONTENT.getBytes().length);
     }
 
     @Test
     public void testInputStreamSizeSpecialCharacters() throws IOException {
-        InputStream is = MESSAGE_SPECIAL_CHAR.getFullContent();
-        int byteCount = 0;
-        while (is.read() != -1) {
-            byteCount++;
-        }
-        assertFalse(MESSAGE_CONTENT_SPECIAL_CHAR.length() == byteCount);
+        ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream();
+        byteArrayOutputStream.write(MESSAGE_SPECIAL_CHAR.getFullContent());
+        
assertThat(byteArrayOutputStream.size()).isEqualTo(MESSAGE_CONTENT_SPECIAL_CHAR.getBytes().length);
     }
 
     @Test
     public void testFullContent() throws IOException {
-        assertEquals(MESSAGE_CONTENT,
-                new 
String(IOUtils.toByteArray(MESSAGE.getFullContent()),MESSAGE_CHARSET));
-        assertEquals(MESSAGE_CONTENT_SPECIAL_CHAR,
-                new 
String(IOUtils.toByteArray(MESSAGE_SPECIAL_CHAR.getFullContent()),MESSAGE_CHARSET));
+        assertThat(new 
String(IOUtils.toByteArray(MESSAGE.getFullContent()),MESSAGE_CHARSET)).isEqualTo(MESSAGE_CONTENT);
+        assertThat(new 
String(IOUtils.toByteArray(MESSAGE_SPECIAL_CHAR.getFullContent()),MESSAGE_CHARSET)).isEqualTo(MESSAGE_CONTENT_SPECIAL_CHAR);
     }
 
     @Test
@@ -92,17 +85,36 @@ public class SimpleMailboxMessageTest {
 
     @Test
     public void copyShouldReturnFieldByFieldEqualsObject() throws 
MailboxException {
-        SimpleMailboxMessage<TestId> original = buildMessage("my content");
+        long textualLineCount = 42L;
+        String text = "text";
+        String plain = "plain";
+        PropertyBuilder propertyBuilder = new PropertyBuilder();
+        propertyBuilder.setTextualLineCount(textualLineCount);
+        propertyBuilder.setMediaType(text);
+        propertyBuilder.setSubType(plain);
+        SimpleMailboxMessage<TestId> original = new 
SimpleMailboxMessage<TestId>(new Date(),
+            MESSAGE_CONTENT.length(),
+            BODY_START_OCTET,
+            new 
SharedByteArrayInputStream(MESSAGE_CONTENT.getBytes(MESSAGE_CHARSET)),
+            new Flags(),
+            propertyBuilder,
+            TEST_ID);
+
         SimpleMailboxMessage<TestId> copy = 
SimpleMailboxMessage.copy(TestId.of(1337), original);
+
         assertThat((Object)copy).isEqualToIgnoringGivenFields(original, 
"message", "mailboxId").isNotSameAs(original);
         assertThat(copy.getMessage()).usingComparator(new 
FieldByFieldComparator()).isEqualTo(original.getMessage());
+        assertThat(SimpleMailboxMessage.copy(TEST_ID, 
original).getTextualLineCount()).isEqualTo(textualLineCount);
+        assertThat(SimpleMailboxMessage.copy(TEST_ID, 
original).getMediaType()).isEqualTo(text);
+        assertThat(SimpleMailboxMessage.copy(TEST_ID, 
original).getSubType()).isEqualTo(plain);
+
     }
 
     private static SimpleMailboxMessage<TestId> buildMessage(String content) {
         return new 
SimpleMailboxMessage<TestId>(Calendar.getInstance().getTime(),
-            content.length(), 0, new SharedByteArrayInputStream(
+            content.length(), BODY_START_OCTET, new SharedByteArrayInputStream(
                     content.getBytes(MESSAGE_CHARSET)), new Flags(),
-            new PropertyBuilder(), TestId.of(1L));
+            new PropertyBuilder(), TEST_ID);
     }
 
 }


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

Reply via email to