IMAP-370 Provide tests for CopyCommandParser and MoveCommandParser

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

Branch: refs/heads/master
Commit: 53755c7b785c03ccaf6b92af73e321f9722e1d46
Parents: 45edd6c
Author: Benoit Tellier <btell...@linagora.com>
Authored: Wed Feb 24 16:55:05 2016 +0700
Committer: Benoit Tellier <btell...@linagora.com>
Committed: Fri Mar 4 19:35:24 2016 +0700

----------------------------------------------------------------------
 protocols/imap/pom.xml                          |  6 +++
 .../request/AbstractMessageRangeRequest.java    | 28 +++++++++++
 .../imap/decode/parser/CopyParserTest.java      | 49 ++++++++++++++++++++
 .../imap/decode/parser/MoveParserTest.java      | 49 ++++++++++++++++++++
 4 files changed, 132 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/53755c7b/protocols/imap/pom.xml
----------------------------------------------------------------------
diff --git a/protocols/imap/pom.xml b/protocols/imap/pom.xml
index 49c074f..305985d 100644
--- a/protocols/imap/pom.xml
+++ b/protocols/imap/pom.xml
@@ -86,6 +86,12 @@
             <artifactId>guava</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <version>${assertj-1.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.jmock</groupId>
             <artifactId>jmock</artifactId>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/james-project/blob/53755c7b/protocols/imap/src/main/java/org/apache/james/imap/message/request/AbstractMessageRangeRequest.java
----------------------------------------------------------------------
diff --git 
a/protocols/imap/src/main/java/org/apache/james/imap/message/request/AbstractMessageRangeRequest.java
 
b/protocols/imap/src/main/java/org/apache/james/imap/message/request/AbstractMessageRangeRequest.java
index f9672a0..a6c56c1 100644
--- 
a/protocols/imap/src/main/java/org/apache/james/imap/message/request/AbstractMessageRangeRequest.java
+++ 
b/protocols/imap/src/main/java/org/apache/james/imap/message/request/AbstractMessageRangeRequest.java
@@ -19,9 +19,15 @@
 
 package org.apache.james.imap.message.request;
 
+import java.util.Arrays;
+import java.util.List;
+
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.message.IdRange;
 
+import com.google.common.base.Objects;
+import com.google.common.hash.HashCode;
+
 public abstract class AbstractMessageRangeRequest extends AbstractImapRequest {
 
     private final IdRange[] idSet;
@@ -46,4 +52,26 @@ public abstract class AbstractMessageRangeRequest extends 
AbstractImapRequest {
     public final boolean isUseUids() {
         return useUids;
     }
+
+    @Override
+    public boolean equals(Object o) {
+        if (o == null || getClass() != o.getClass()) return false;
+
+        AbstractMessageRangeRequest that = (AbstractMessageRangeRequest) o;
+
+        return equals(this.idSet, that.idSet)
+            && Objects.equal(this.mailboxName, that.mailboxName)
+            && Objects.equal(this.useUids, that.useUids);
+    }
+
+    private boolean equals(IdRange[] idSet1, IdRange[] idSet2) {
+        List<IdRange> idRanges1 = Arrays.asList(idSet1);
+        List<IdRange> idRanges2 = Arrays.asList(idSet2);
+        return Objects.equal(idRanges1, idRanges2);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(idSet, mailboxName, useUids);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/53755c7b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/CopyParserTest.java
----------------------------------------------------------------------
diff --git 
a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/CopyParserTest.java
 
b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/CopyParserTest.java
new file mode 100644
index 0000000..05a5bfc
--- /dev/null
+++ 
b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/CopyParserTest.java
@@ -0,0 +1,49 @@
+/****************************************************************
+ * 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.decode.parser;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.message.IdRange;
+import org.apache.james.imap.decode.ImapRequestStreamLineReader;
+import org.apache.james.imap.message.request.CopyRequest;
+import org.apache.james.protocols.imap.DecodingException;
+import org.junit.Test;
+
+public class CopyParserTest {
+
+    @Test
+    public void testQuotaParsing() throws DecodingException {
+        CopyCommandParser parser = new CopyCommandParser();
+        ImapCommand command = ImapCommand.anyStateCommand("Command");
+        String commandString = " 42:69 foo \n";
+
+        InputStream inputStream = new 
ByteArrayInputStream(commandString.getBytes());
+        ImapRequestStreamLineReader lineReader = new 
ImapRequestStreamLineReader(inputStream, null);
+        CopyRequest request = (CopyRequest) parser.decode(command, lineReader, 
"A003", null);
+        CopyRequest expected = new CopyRequest(command, new IdRange[] {new 
IdRange(42, 69)}, "foo", false, "A003");
+
+        assertThat(request).isEqualTo(expected);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/53755c7b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/MoveParserTest.java
----------------------------------------------------------------------
diff --git 
a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/MoveParserTest.java
 
b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/MoveParserTest.java
new file mode 100644
index 0000000..c17b379
--- /dev/null
+++ 
b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/MoveParserTest.java
@@ -0,0 +1,49 @@
+/****************************************************************
+ * 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.decode.parser;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.message.IdRange;
+import org.apache.james.imap.decode.ImapRequestStreamLineReader;
+import org.apache.james.imap.message.request.MoveRequest;
+import org.apache.james.protocols.imap.DecodingException;
+import org.junit.Test;
+
+public class MoveParserTest {
+
+    @Test
+    public void testQuotaParsing() throws DecodingException {
+        MoveCommandParser parser = new MoveCommandParser();
+        ImapCommand command = ImapCommand.anyStateCommand("Command");
+        String commandString = " 42:69 foo \n";
+
+        InputStream inputStream = new 
ByteArrayInputStream(commandString.getBytes());
+        ImapRequestStreamLineReader lineReader = new 
ImapRequestStreamLineReader(inputStream, null);
+        MoveRequest request = (MoveRequest) parser.decode(command, lineReader, 
"A003", null);
+        MoveRequest expected = new MoveRequest(command, new IdRange[] {new 
IdRange(42, 69)}, "foo", false, "A003");
+
+        assertThat(request).isEqualTo(expected);
+    }
+}


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