james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [james-project] 01/12: JAMES-2709 FileExtension::asFileSuffix
Date Fri, 19 Apr 2019 07:42:54 GMT
This is an automated email from the ASF dual-hosted git repository.

aduprat pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit ce1e2028153bd11467bda128594b7bc00f1d92bd
Author: Benoit Tellier <btellier@linagora.com>
AuthorDate: Thu Apr 11 10:42:57 2019 +0700

    JAMES-2709 FileExtension::asFileSuffix
---
 .../james/blob/export/api/FileExtension.java       |  9 ++++-
 .../james/blob/export/api/FileExtensionTest.java   | 40 +++++++++++++++++-----
 2 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/server/blob/blob-export-api/src/main/java/org/apache/james/blob/export/api/FileExtension.java
b/server/blob/blob-export-api/src/main/java/org/apache/james/blob/export/api/FileExtension.java
index b0c3000..1faebe6 100644
--- a/server/blob/blob-export-api/src/main/java/org/apache/james/blob/export/api/FileExtension.java
+++ b/server/blob/blob-export-api/src/main/java/org/apache/james/blob/export/api/FileExtension.java
@@ -39,13 +39,20 @@ public class FileExtension {
 
     @VisibleForTesting
     FileExtension(String extension) {
+        Preconditions.checkNotNull(extension, "'extension' can not be null");
+        Preconditions.checkArgument(StringUtils.isNotBlank(extension), "'extension' can not
be blank");
+
         this.extension = extension;
     }
 
     public String appendExtension(String filePath) {
         Preconditions.checkArgument(StringUtils.isNotBlank(filePath), "filePath cannot be
null or blank");
 
-        return filePath + EXTENSION_SEPARATOR + extension;
+        return filePath + asFileSuffix();
+    }
+
+    public String asFileSuffix() {
+        return EXTENSION_SEPARATOR + extension;
     }
 
     public String getExtension() {
diff --git a/server/blob/blob-export-api/src/test/java/org/apache/james/blob/export/api/FileExtensionTest.java
b/server/blob/blob-export-api/src/test/java/org/apache/james/blob/export/api/FileExtensionTest.java
index 6c0823b..d2642e2 100644
--- a/server/blob/blob-export-api/src/test/java/org/apache/james/blob/export/api/FileExtensionTest.java
+++ b/server/blob/blob-export-api/src/test/java/org/apache/james/blob/export/api/FileExtensionTest.java
@@ -23,42 +23,64 @@ import static org.apache.james.blob.export.api.FileExtension.ZIP_EXTENSION_STRIN
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
 
 class FileExtensionTest {
+    @Test
+    void shouldMatchBeanContract() {
+        EqualsVerifier.forClass(FileExtension.class)
+            .verify();
+    }
 
-    private FileExtension fileExtension;
+    @Test
+    void constructorShouldThrowOnNull() {
+        assertThatThrownBy(() -> new FileExtension(null))
+            .isInstanceOf(NullPointerException.class);
+    }
 
-    @BeforeEach
-    void beforeEach() {
-        fileExtension = new FileExtension(ZIP_EXTENSION_STRING);
+    @Test
+    void constructorShouldThrowOnEmpty() {
+        assertThatThrownBy(() -> new FileExtension(""))
+            .isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
-    void shouldMatchBeanContract() {
-        EqualsVerifier.forClass(FileExtension.class)
-            .verify();
+    void constructorShouldThrowOnBlank() {
+        assertThatThrownBy(() -> new FileExtension("  "))
+            .isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
     void appendExtensionShouldThrowWhenPassingNullValue() {
+        FileExtension fileExtension = new FileExtension(ZIP_EXTENSION_STRING);
+
         assertThatThrownBy(() -> fileExtension.appendExtension(null))
             .isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
     void appendExtensionShouldThrowWhenPassingEmptyStringValue() {
+        FileExtension fileExtension = new FileExtension(ZIP_EXTENSION_STRING);
+
         assertThatThrownBy(() -> fileExtension.appendExtension(""))
             .isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
     void appendExtensionShouldReturnValueEndsWithExtension() {
-        fileExtension = new FileExtension("tar.gz");
+        FileExtension fileExtension = new FileExtension("tar.gz");
+
         assertThat(fileExtension.appendExtension("/local/james"))
             .endsWith(".tar.gz");
     }
+
+    @Test
+    void asFileSuffixShouldReturnDotAndExtension() {
+        FileExtension fileExtension = new FileExtension("tar.gz");
+
+        assertThat(fileExtension.asFileSuffix())
+            .isEqualTo(".tar.gz");
+    }
 }


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