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 ad...@apache.org on 2017/07/25 07:29:31 UTC
[2/2] james-project git commit: JAMES-2095 AttachmentTest: specify
charset for string/byte conv
JAMES-2095 AttachmentTest: specify charset for string/byte conv
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/0a8c8501
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/0a8c8501
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/0a8c8501
Branch: refs/heads/master
Commit: 0a8c8501139953247663a728c2626b1ca89d99eb
Parents: 563a21a
Author: Luc DUZAN <ld...@linagora.com>
Authored: Mon Jul 10 17:26:55 2017 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Tue Jul 25 09:28:22 2017 +0200
----------------------------------------------------------------------
.../james/mailbox/model/AttachmentTest.java | 28 +++++++++++---------
1 file changed, 16 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/0a8c8501/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentTest.java
index 53728eb..8edbdae 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentTest.java
@@ -23,7 +23,9 @@ package org.apache.james.mailbox.model;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.InputStream;
+import java.nio.charset.Charset;
+import com.google.common.base.Charsets;
import org.apache.commons.io.IOUtils;
import org.apache.james.mailbox.model.Attachment;
@@ -31,43 +33,45 @@ import org.junit.Test;
public class AttachmentTest {
+ private static Charset CHARSET = Charsets.UTF_8;
+
@Test
public void streamShouldBeConsumedOneTime() throws Exception {
String input = "mystream";
Attachment attachment = Attachment.builder()
- .bytes(input.getBytes())
+ .bytes(input.getBytes(CHARSET))
.type("content")
.build();
InputStream stream = attachment.getStream();
assertThat(stream).isNotNull();
- assertThat(IOUtils.toString(stream)).isEqualTo(input);
+ assertThat(IOUtils.toString(stream, CHARSET)).isEqualTo(input);
}
@Test
public void getByteShouldReturnByteArrayRepresentingTheAttachment() throws Exception {
String input = "mystream";
Attachment attachment = Attachment.builder()
- .bytes(input.getBytes())
+ .bytes(input.getBytes(CHARSET))
.type("content")
.build();
byte[] bytes = attachment.getBytes();
- assertThat(new String(bytes)).isEqualTo(input);
+ assertThat(new String(bytes, CHARSET)).isEqualTo(input);
}
@Test
public void streamShouldBeConsumedMoreThanOneTime() throws Exception {
String input = "mystream";
Attachment attachment = Attachment.builder()
- .bytes(input.getBytes())
+ .bytes(input.getBytes(CHARSET))
.type("content")
.build();
attachment.getStream();
InputStream stream = attachment.getStream();
assertThat(stream).isNotNull();
- assertThat(IOUtils.toString(stream)).isEqualTo(input);
+ assertThat(IOUtils.toString(stream, CHARSET)).isEqualTo(input);
}
@Test (expected = IllegalArgumentException.class)
@@ -102,21 +106,21 @@ public class AttachmentTest {
@Test (expected = IllegalStateException.class)
public void buildShouldThrowWhenBytesIsNotProvided() {
Attachment.builder()
- .attachmentId(AttachmentId.forPayload("mystream".getBytes()))
+ .attachmentId(AttachmentId.forPayload("mystream".getBytes(CHARSET)))
.build();
}
@Test (expected = IllegalStateException.class)
public void buildShouldThrowWhenTypeIsNotProvided() {
Attachment.builder()
- .attachmentId(AttachmentId.forPayload("mystream".getBytes()))
- .bytes("mystream".getBytes())
+ .attachmentId(AttachmentId.forPayload("mystream".getBytes(CHARSET)))
+ .bytes("mystream".getBytes(CHARSET))
.build();
}
@Test
public void buildShouldSetTheAttachmentId() throws Exception {
- byte[] bytes = "mystream".getBytes();
+ byte[] bytes = "mystream".getBytes(CHARSET);
Attachment attachment = Attachment.builder()
.bytes(bytes)
.type("content")
@@ -130,10 +134,10 @@ public class AttachmentTest {
public void buildShouldSetTheSize() throws Exception {
String input = "mystream";
Attachment attachment = Attachment.builder()
- .bytes(input.getBytes())
+ .bytes(input.getBytes(CHARSET))
.type("content")
.build();
- assertThat(attachment.getSize()).isEqualTo(input.getBytes().length);
+ assertThat(attachment.getSize()).isEqualTo(input.getBytes(CHARSET).length);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org