james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject svn commit: r1688585 - in /james/mailbox/trunk/api/src: main/java/org/apache/james/mailbox/model/MessageRange.java test/java/org/apache/james/mailbox/MessageRangeTest.java test/java/org/apache/james/mailbox/model/MessageRangeTest.java
Date Wed, 01 Jul 2015 08:27:04 GMT
Author: btellier
Date: Wed Jul  1 08:27:03 2015
New Revision: 1688585

URL: http://svn.apache.org/r1688585
Log:
MAILBOX-220 StoreMessageManager::getMessages returns no messages when using FROM ranges. -
Contributed by Antoine Duprat

Added:
    james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/model/MessageRangeTest.java
Removed:
    james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/MessageRangeTest.java
Modified:
    james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/MessageRange.java

Modified: james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/MessageRange.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/MessageRange.java?rev=1688585&r1=1688584&r2=1688585&view=diff
==============================================================================
--- james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/MessageRange.java
(original)
+++ james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/model/MessageRange.java
Wed Jul  1 08:27:03 2015
@@ -102,8 +102,7 @@ public class MessageRange implements Ite
      * @return not null
      */
     public static MessageRange from(long from) {
-        final MessageRange result = new MessageRange(Type.FROM, from, NOT_A_UID);
-        return result;
+        return new MessageRange(Type.FROM, from, MAX_UID);
     }
 
 

Added: james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/model/MessageRangeTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/model/MessageRangeTest.java?rev=1688585&view=auto
==============================================================================
--- james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/model/MessageRangeTest.java
(added)
+++ james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/model/MessageRangeTest.java
Wed Jul  1 08:27:03 2015
@@ -0,0 +1,113 @@
+/****************************************************************
+ * 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.mailbox.model;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+
+public class MessageRangeTest {
+
+    @Test
+    public void testToRanges() {
+        List<MessageRange> ranges = MessageRange.toRanges(Arrays.asList(1L,2L,3L,5L,6L,9L));
+        assertEquals(3, ranges.size());
+        checkRange(1, 3, ranges.get(0));
+        checkRange(5, 6, ranges.get(1));
+        checkRange(9, 9, ranges.get(2));
+
+    }
+    
+    @Test
+    public void testOneUidToRange() {
+        List<MessageRange> ranges = MessageRange.toRanges(Arrays.asList(1L));
+        assertEquals(1, ranges.size());
+        checkRange(1, 1, ranges.get(0));
+    }
+    
+    // Test for MAILBOX-56
+    @Test
+    public void testTwoSeqUidToRange() {
+        List<MessageRange> ranges = MessageRange.toRanges(Arrays.asList(1L,2L));
+        assertEquals(1, ranges.size());
+        checkRange(1, 2, ranges.get(0));
+
+    }
+    
+    
+    private void checkRange(long from, long to, MessageRange range) {
+        assertEquals(from, range.getUidFrom());
+        assertEquals(to, range.getUidTo());
+    }
+    
+    @Test
+    public void testSplitOne() {
+        MessageRange one = MessageRange.one(1);
+        List<MessageRange> ranges = one.split(2);
+        assertEquals(1, ranges.size());
+        checkRange(1, 1, ranges.get(0));
+        assertEquals(MessageRange.Type.ONE, ranges.get(0).getType());
+    }
+    
+    @Test
+    public void testSplitFrom() {
+        MessageRange from = MessageRange.from(1);
+        List<MessageRange> ranges = from.split(2);
+        assertEquals(1, ranges.size());
+        checkRange(1, MessageRange.MAX_UID, ranges.get(0));
+        assertEquals(MessageRange.Type.FROM, ranges.get(0).getType());
+    }
+    
+    @Test
+    public void testSplitRange() {
+        MessageRange range = MessageRange.range(1,10);
+        List<MessageRange> ranges = range.split(3);
+        assertEquals(4, ranges.size());
+        checkRange(1, 3, ranges.get(0));
+        assertEquals(MessageRange.Type.RANGE, ranges.get(0).getType());
+        checkRange(4, 6, ranges.get(1));
+        assertEquals(MessageRange.Type.RANGE, ranges.get(1).getType());
+        checkRange(7, 9, ranges.get(2));
+        assertEquals(MessageRange.Type.RANGE, ranges.get(2).getType());
+        checkRange(10, 10, ranges.get(3));
+        assertEquals(MessageRange.Type.ONE, ranges.get(3).getType());
+    }
+    
+    @Test
+    public void fromShouldSetTypeToFrom() {
+    	MessageRange messageRange = MessageRange.from(10);
+    	assertEquals(messageRange.getType(), MessageRange.Type.FROM);
+    }
+    
+    @Test
+    public void fromShouldSetUidFromToGivenValue() {
+    	int from = 10;
+		MessageRange messageRange = MessageRange.from(from);
+    	assertEquals(messageRange.getUidFrom(), from);
+    }
+    
+    @Test
+    public void fromShouldSetUidToToMax() {
+    	MessageRange messageRange = MessageRange.from(10);
+    	assertEquals(messageRange.getUidTo(), MessageRange.MAX_UID);
+    }
+}



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