james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [8/9] james-project git commit: PROTOCOL-117 cover ListingEncodingUtils with tests
Date Wed, 08 Nov 2017 07:29:55 GMT
PROTOCOL-117 cover ListingEncodingUtils with tests


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

Branch: refs/heads/master
Commit: 1411959de159366e35b4341938308ba463defb0a
Parents: 78f2390
Author: Matthieu Baechler <matthieu@apache.org>
Authored: Tue Nov 7 16:37:08 2017 +0100
Committer: Matthieu Baechler <matthieu@apache.org>
Committed: Tue Nov 7 17:55:48 2017 +0100

----------------------------------------------------------------------
 .../imap/encode/LSubResponseEncoderTest.java    | 49 +++++------
 .../imap/encode/ListResponseEncoderTest.java    | 62 ++++----------
 .../imap/encode/ListingEncodingUtilsTest.java   | 86 ++++++++++++++------
 .../imap/encode/XListResponseEncoderTest.java   | 81 ++++++++++++++++++
 4 files changed, 183 insertions(+), 95 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1411959d/protocols/imap/src/test/java/org/apache/james/imap/encode/LSubResponseEncoderTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/encode/LSubResponseEncoderTest.java
b/protocols/imap/src/test/java/org/apache/james/imap/encode/LSubResponseEncoderTest.java
index 23836f1..a0c9348 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/encode/LSubResponseEncoderTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/encode/LSubResponseEncoderTest.java
@@ -19,6 +19,7 @@
 
 package org.apache.james.imap.encode;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -34,50 +35,44 @@ import org.junit.Before;
 import org.junit.Test;
 
 public class LSubResponseEncoderTest  {
+    private LSubResponseEncoder encoder;
 
-    LSubResponseEncoder encoder;
-
-    ImapEncoder mockNextEncoder;
-
-    ByteImapResponseWriter writer = new ByteImapResponseWriter();
-    ImapResponseComposer composer = new ImapResponseComposerImpl(writer);
+    private ByteImapResponseWriter writer = new ByteImapResponseWriter();
+    private ImapResponseComposer composer = new ImapResponseComposerImpl(writer);
 
     private Mockery context = new JUnit4Mockery();
-    
+
     @Before
     public void setUp() throws Exception {
-        mockNextEncoder = context.mock(ImapEncoder.class);
-        encoder = new LSubResponseEncoder(mockNextEncoder);
+        encoder = new LSubResponseEncoder(context.mock(ImapEncoder.class));
     }
 
     @Test
-    public void testIsAcceptable() {
-        assertFalse(encoder.isAcceptable(new ListResponse(true, true, true,
-                true, false, false, "name", '.')));
-        assertTrue(encoder.isAcceptable(new LSubResponse("name", true, '.')));
-        assertFalse(encoder.isAcceptable(context.mock(ImapMessage.class)));
-        assertFalse(encoder.isAcceptable(null));
+    public void encoderShouldNotAcceptListResponse() {
+        assertThat(encoder.isAcceptable(new ListResponse(true, true, true,
+            true, false, false, "name", '.')))
+            .isFalse();
     }
 
     @Test
-	public void testName() throws Exception {
-        encoder.encode(new LSubResponse("INBOX.name", false, '.'), composer, new FakeImapSession());
-        assertEquals("* LSUB () \".\" \"INBOX.name\"\r\n", writer.getString());
-
+    public void encoderShouldAcceptLsubResponse() {
+        assertThat(encoder.isAcceptable(new LSubResponse("name", true, '.'))).isTrue();
     }
 
     @Test
-	public void testDelimiter() throws Exception {
-        encoder.encode(new LSubResponse("INBOX.name", false, '.'), composer, new FakeImapSession());
-        assertEquals("* LSUB () \".\" \"INBOX.name\"\r\n", writer.getString());
-
+    public void encoderShouldNotAcceptImapMessage() {
+        assertThat(encoder.isAcceptable(context.mock(ImapMessage.class))).isFalse();
     }
 
     @Test
-    public void testNoSelect() throws Exception {
-        encoder.encode(new LSubResponse("INBOX.name", true, '.'), composer, new FakeImapSession());
-        assertEquals("* LSUB (\\Noselect) \".\" \"INBOX.name\"\r\n", writer.getString());
-
+    public void encoderShouldNotAcceptNull() {
+        assertThat(encoder.isAcceptable(null)).isFalse();
+    }
 
+    @Test
+    public void encoderShouldIncludeLSUBCommand() throws Exception {
+        encoder.encode(new LSubResponse("name", true, '.'), composer, new FakeImapSession());
+        assertThat(writer.getString()).startsWith("* LSUB");
     }
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1411959d/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java
b/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java
index 67bd1bc..e70572d 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java
@@ -19,6 +19,7 @@
 
 package org.apache.james.imap.encode;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -37,8 +38,6 @@ public class ListResponseEncoderTest {
 
     private ListResponseEncoder encoder;
 
-    private ImapEncoder mockNextEncoder;
-
     private ByteImapResponseWriter writer = new ByteImapResponseWriter();
     private ImapResponseComposer composer = new ImapResponseComposerImpl(writer);
 
@@ -46,63 +45,36 @@ public class ListResponseEncoderTest {
     
     @Before
     public void setUp() throws Exception {
-        mockNextEncoder = context.mock(ImapEncoder.class);
-        encoder = new ListResponseEncoder(mockNextEncoder);
-    }
-
-    @Test
-    public void testIsAcceptable() {
-        assertTrue(encoder.isAcceptable(new ListResponse(true, true, true,
-                true, false, false, "name", '.')));
-        assertFalse(encoder.isAcceptable(new LSubResponse("name", true, '.')));
-        assertFalse(encoder.isAcceptable(context.mock(ImapMessage.class)));
-        assertFalse(encoder.isAcceptable(null));
-    }
-
-    @Test
-	public void testName() throws Exception {     
-        encoder.encode(new ListResponse(false, false, false, false, false, false, "INBOX.name",
'.'), composer, new FakeImapSession());
-        assertEquals("* LIST () \".\" \"INBOX.name\"\r\n", writer.getString());
-    }
-
-    @Test
-	public void testDelimiter() throws Exception {
-        encoder.encode(new ListResponse(false, false, false, false, false, false, "INBOX.name",
'.'), composer, new FakeImapSession());
-        assertEquals("* LIST () \".\" \"INBOX.name\"\r\n", writer.getString());
+        encoder = new ListResponseEncoder(context.mock(ImapEncoder.class));
     }
 
-
     @Test
-    public void testAllAttributes() throws Exception {
-        encoder.encode(new ListResponse(true, true, true, true, false, false, "INBOX.name",
'.'), composer, new FakeImapSession());
-        assertEquals("* LIST (\\Noinferiors \\Noselect \\Marked \\Unmarked) \".\" \"INBOX.name\"\r\n",
writer.getString());
-
+    public void encoderShouldAcceptListResponse() {
+        assertThat(encoder.isAcceptable(new ListResponse(true, true, true,
+            true, false, false, "name", '.')))
+        .isTrue();
     }
 
     @Test
-    public void testNoInferiors() throws Exception {      
-        encoder.encode(new ListResponse(true, false, false, false, false, false, "INBOX.name",
'.'), composer, new FakeImapSession());
-        assertEquals("* LIST (\\Noinferiors) \".\" \"INBOX.name\"\r\n", writer.getString());
+    public void encoderShouldNotAcceptLsubResponse() {
+        assertThat(encoder.isAcceptable(new LSubResponse("name", true, '.'))).isFalse();
+        assertFalse(encoder.isAcceptable(context.mock(ImapMessage.class)));
+        assertFalse(encoder.isAcceptable(null));
     }
 
     @Test
-    public void testNoSelect() throws Exception {
-        encoder.encode(new ListResponse(false, true, false, false, false, false, "INBOX.name",
'.'), composer, new FakeImapSession());
-        assertEquals("* LIST (\\Noselect) \".\" \"INBOX.name\"\r\n", writer.getString());
-
+    public void encoderShouldNotAcceptImapMessage() {
+        assertThat(encoder.isAcceptable(context.mock(ImapMessage.class))).isFalse();
     }
 
     @Test
-    public void testMarked() throws Exception {
-        encoder.encode(new ListResponse(false, false, true, false, false, false, "INBOX.name",
'.'), composer, new FakeImapSession());
-        assertEquals("* LIST (\\Marked) \".\" \"INBOX.name\"\r\n", writer.getString());
-
+    public void encoderShouldNotAcceptNull() {
+        assertThat(encoder.isAcceptable(null)).isFalse();
     }
 
     @Test
-    public void testUnmarked() throws Exception {
-        encoder.encode(new ListResponse(false, false, false, true, false, false, "INBOX.name",
'.'), composer, new FakeImapSession());
-        assertEquals("* LIST (\\Unmarked) \".\" \"INBOX.name\"\r\n", writer.getString());
-
+	public void encoderShouldIncludeListCommand() throws Exception {
+        encoder.encode(new ListResponse(false, false, false, false, false, false, "INBOX.name",
'.'), composer, new FakeImapSession());
+        assertThat(writer.getString()).startsWith("* LIST");
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1411959d/protocols/imap/src/test/java/org/apache/james/imap/encode/ListingEncodingUtilsTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/encode/ListingEncodingUtilsTest.java
b/protocols/imap/src/test/java/org/apache/james/imap/encode/ListingEncodingUtilsTest.java
index bb5b187..dc2f439 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/encode/ListingEncodingUtilsTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/encode/ListingEncodingUtilsTest.java
@@ -18,52 +18,92 @@
  ****************************************************************/
 package org.apache.james.imap.encode;
 
-import java.util.ArrayList;
-import java.util.List;
+import static org.assertj.core.api.Assertions.assertThat;
 
+import org.apache.james.imap.api.process.MailboxType;
 import org.apache.james.imap.encode.base.ByteImapResponseWriter;
 import org.apache.james.imap.encode.base.ImapResponseComposerImpl;
 import org.apache.james.imap.message.response.ListResponse;
-import org.junit.Assert;
-import org.junit.Before;
+import org.apache.james.imap.message.response.XListResponse;
 import org.junit.Test;
 
 public class ListingEncodingUtilsTest  {
 
-    final String nameParameter = "LIST";
-    final String typeNameParameters = "A Type Name";
+    final String nameParameter = "mailbox";
+    final String typeNameParameters = "LIST";
     
-    List<String> attributesOutput;
-        
     private ByteImapResponseWriter writer = new ByteImapResponseWriter();
     private ImapResponseComposer composer = new ImapResponseComposerImpl(writer);
-    
-    @Before
-    public void setUp() throws Exception {
-        attributesOutput = new ArrayList<>();
-      
+
+    @Test
+    public void encodeShouldWriteNilDelimiterWhenUnassigned() throws Exception {
+        ListResponse input = new ListResponse(false, false, false, false, true, false, nameParameter,
((char) Character.UNASSIGNED));
+
+        ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
+        assertThat(writer.getString()).isEqualTo("* LIST (\\HasChildren) NIL \"mailbox\"\r\n");
     }
 
     @Test
-    public void testShouldAddHasChildrenToAttributes() throws Exception {
-        // Setup 
-        attributesOutput.add("\\HasChildren");
+    public void encodeShouldWriteAnyDelimiter() throws Exception {
+        ListResponse input = new ListResponse(false, false, false, false, true, false, nameParameter,
'#');
+
+        ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
+        assertThat(writer.getString()).isEqualTo("* LIST (\\HasChildren) \"#\" \"mailbox\"\r\n");
+    }
+
+    @Test
+    public void encodeShouldNotIncludeAttributeWhenNone() throws Exception {
+        ListResponse input = new ListResponse(false, false, false, false, false, false, nameParameter,
'.');
+
+        ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
+        assertThat(writer.getString()).isEqualTo("* LIST () \".\" \"mailbox\"\r\n");
+    }
+
+    @Test
+    public void encodeShouldAddHasChildrenToAttributes() throws Exception {
         ListResponse input = new ListResponse(false, false, false, false, true, false, nameParameter,
'.');
             
-        // Exercise
         ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
-        Assert.assertEquals("* A Type Name (\\HasChildren) \".\" \"LIST\"\r\n", writer.getString());
+        assertThat(writer.getString()).isEqualTo("* LIST (\\HasChildren) \".\" \"mailbox\"\r\n");
     }
     
     @Test
-    public void testShouldAddHasNoChildrenToAttributes() throws Exception {
-        // Setup 
-        attributesOutput.add("\\HasNoChildren");
+    public void encodeShouldAddHasNoChildrenToAttributes() throws Exception {
         ListResponse input = new ListResponse(false, false, false, false, false, true, nameParameter,
'.');
             
-        // Exercise
         ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
-        Assert.assertEquals("* A Type Name (\\HasNoChildren) \".\" \"LIST\"\r\n", writer.getString());
+        assertThat(writer.getString()).isEqualTo("* LIST (\\HasNoChildren) \".\" \"mailbox\"\r\n");
+    }
+
+    @Test
+    public void encodeShouldAddSeveralAttributes() throws Exception {
+        ListResponse input = new ListResponse(true, true, false, false, false, true, nameParameter,
'.');
+
+        ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
+        assertThat(writer.getString()).isEqualTo("* LIST (\\Noinferiors \\Noselect \\HasNoChildren)
\".\" \"mailbox\"\r\n");
+    }
+
+    @Test
+    public void encodeShouldAddMarkedAttribute() throws Exception {
+        ListResponse input = new ListResponse(false, false, true, false, false, false, nameParameter,
'.');
+
+        ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
+        assertThat(writer.getString()).isEqualTo("* LIST (\\Marked) \".\" \"mailbox\"\r\n");
+    }
+
+    @Test
+    public void encodeShouldAddUnmarkedAttribute() throws Exception {
+        ListResponse input = new ListResponse(false, false, false, true, false, false, nameParameter,
'.');
+
+        ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
+        assertThat(writer.getString()).isEqualTo("* LIST (\\Unmarked) \".\" \"mailbox\"\r\n");
+    }
+
+    @Test
+    public void encodeShouldAddXListAttributeWhenTypeIsInbox() throws Exception {
+        XListResponse input = new XListResponse(false, false, false, false, true, false,
nameParameter, '.', MailboxType.INBOX);
 
+        ListingEncodingUtils.encodeListingResponse("XLIST", composer, input);
+        assertThat(writer.getString()).isEqualTo("* XLIST (\\HasChildren \\Inbox) \".\" \"mailbox\"\r\n");
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1411959d/protocols/imap/src/test/java/org/apache/james/imap/encode/XListResponseEncoderTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/encode/XListResponseEncoderTest.java
b/protocols/imap/src/test/java/org/apache/james/imap/encode/XListResponseEncoderTest.java
new file mode 100644
index 0000000..7216dc8
--- /dev/null
+++ b/protocols/imap/src/test/java/org/apache/james/imap/encode/XListResponseEncoderTest.java
@@ -0,0 +1,81 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.imap.encode;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertFalse;
+
+import org.apache.james.imap.api.ImapMessage;
+import org.apache.james.imap.api.process.MailboxType;
+import org.apache.james.imap.encode.base.ByteImapResponseWriter;
+import org.apache.james.imap.encode.base.ImapResponseComposerImpl;
+import org.apache.james.imap.message.response.LSubResponse;
+import org.apache.james.imap.message.response.ListResponse;
+import org.apache.james.imap.message.response.XListResponse;
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.junit.Before;
+import org.junit.Test;
+
+public class XListResponseEncoderTest {
+
+    private XListResponseEncoder encoder;
+
+    private ByteImapResponseWriter writer = new ByteImapResponseWriter();
+    private ImapResponseComposer composer = new ImapResponseComposerImpl(writer);
+
+    private Mockery context = new JUnit4Mockery();
+    
+    @Before
+    public void setUp() throws Exception {
+        encoder = new XListResponseEncoder(context.mock(ImapEncoder.class));
+    }
+
+    @Test
+    public void encoderShouldAcceptXListResponse() {
+        assertThat(encoder.isAcceptable(new XListResponse(true, true, true,
+            true, false, false, "name", '.', MailboxType.INBOX)))
+        .isTrue();
+    }
+
+    @Test
+    public void encoderShouldNotAcceptLsubResponse() {
+        assertThat(encoder.isAcceptable(new LSubResponse("name", true, '.'))).isFalse();
+        assertFalse(encoder.isAcceptable(context.mock(ImapMessage.class)));
+        assertFalse(encoder.isAcceptable(null));
+    }
+
+    @Test
+    public void encoderShouldNotAcceptImapMessage() {
+        assertThat(encoder.isAcceptable(context.mock(ImapMessage.class))).isFalse();
+    }
+
+    @Test
+    public void encoderShouldNotAcceptNull() {
+        assertThat(encoder.isAcceptable(null)).isFalse();
+    }
+
+    @Test
+	public void encoderShouldIncludeListCommand() throws Exception {
+        encoder.encode(new XListResponse(true, true, true,
+            true, false, false, "name", '.', MailboxType.INBOX), composer, new FakeImapSession());
+        assertThat(writer.getString()).startsWith("* XLIST");
+    }
+}


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