james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [05/11] james-project git commit: JAMES-1825 use a MessageUid strong type instead of long in the whole code base
Date Mon, 10 Oct 2016 10:34:23 GMT
http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
index c378313..f90c144 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/MessageSearches.java
@@ -40,13 +40,14 @@ import java.util.TreeSet;
 import javax.mail.Flags;
 
 import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.UnsupportedSearchException;
 import org.apache.james.mailbox.model.MessageResult.Header;
 import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.model.SearchQuery.AddressType;
 import org.apache.james.mailbox.model.SearchQuery.DateResolution;
-import org.apache.james.mailbox.model.SearchQuery.NumericRange;
+import org.apache.james.mailbox.model.SearchQuery.UidRange;
 import org.apache.james.mailbox.store.ResultUtils;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.search.comparator.CombinedComparator;
@@ -74,7 +75,7 @@ import com.google.common.collect.Lists;
 /**
  * Utility methods to help perform search operations.
  */
-public class MessageSearches implements Iterable<Long> {
+public class MessageSearches implements Iterable<MessageUid> {
 
     private Iterator<MailboxMessage> messages;
     private SearchQuery query;
@@ -92,7 +93,7 @@ public class MessageSearches implements Iterable<Long> {
     public MessageSearches() {
     }
 
-    private Collection<Long> search() {
+    private Set<MessageUid> search() {
         TreeSet<MailboxMessage> matched = new TreeSet<MailboxMessage>(CombinedComparator.create(query.getSorts()));
         while (messages.hasNext()) {
             MailboxMessage m = messages.next();
@@ -106,7 +107,7 @@ public class MessageSearches implements Iterable<Long> {
                 }
             }
         }
-        Set<Long> uids = new HashSet<Long>();
+        Set<MessageUid> uids = new HashSet<MessageUid>();
         Iterator<MailboxMessage> matchedIt = matched.iterator();
         while (matchedIt.hasNext()) {
             uids.add(matchedIt.next().getUid());
@@ -127,7 +128,7 @@ public class MessageSearches implements Iterable<Long> {
      */
     private boolean isMatch(SearchQuery query, MailboxMessage message) throws MailboxException {
         final List<SearchQuery.Criterion> criteria = query.getCriterias();
-        final Collection<Long> recentMessageUids = query.getRecentMessageUids();
+        final Collection<MessageUid> recentMessageUids = query.getRecentMessageUids();
         boolean result = true;
         if (criteria != null) {
             for (SearchQuery.Criterion criterion : criteria) {
@@ -154,7 +155,7 @@ public class MessageSearches implements Iterable<Long> {
      * @throws MailboxException
      */
     public boolean isMatch(SearchQuery.Criterion criterion, MailboxMessage message,
-            final Collection<Long> recentMessageUids) throws MailboxException {
+            final Collection<MessageUid> recentMessageUids) throws MailboxException {
         final boolean result;
         if (criterion instanceof SearchQuery.InternalDateCriterion) {
             result = matches((SearchQuery.InternalDateCriterion) criterion, message);
@@ -264,7 +265,7 @@ public class MessageSearches implements Iterable<Long> {
         }
     }
     private boolean matches(SearchQuery.ConjunctionCriterion criterion, MailboxMessage message,
-            final Collection<Long> recentMessageUids) throws MailboxException {
+            final Collection<MessageUid> recentMessageUids) throws MailboxException {
         final List<SearchQuery.Criterion> criteria = criterion.getCriteria();
         switch (criterion.getType()) {
         case NOR:
@@ -279,7 +280,7 @@ public class MessageSearches implements Iterable<Long> {
     }
 
     private boolean and(List<SearchQuery.Criterion> criteria, MailboxMessage message,
-            final Collection<Long> recentMessageUids) throws MailboxException {
+            final Collection<MessageUid> recentMessageUids) throws MailboxException {
         boolean result = true;
         for (SearchQuery.Criterion criterion : criteria) {
             boolean matches = isMatch(criterion, message, recentMessageUids);
@@ -292,7 +293,7 @@ public class MessageSearches implements Iterable<Long> {
     }
 
     private boolean or(List<SearchQuery.Criterion> criteria, MailboxMessage message,
-            final Collection<Long> recentMessageUids) throws MailboxException {
+            final Collection<MessageUid> recentMessageUids) throws MailboxException {
         boolean result = false;
         for (SearchQuery.Criterion criterion : criteria) {
             boolean matches = isMatch(criterion, message, recentMessageUids);
@@ -305,7 +306,7 @@ public class MessageSearches implements Iterable<Long> {
     }
 
     private boolean nor(List<SearchQuery.Criterion> criteria, MailboxMessage message,
-            final Collection<Long> recentMessageUids) throws MailboxException {
+            final Collection<MessageUid> recentMessageUids) throws MailboxException {
         boolean result = true;
         for (SearchQuery.Criterion criterion : criteria) {
             boolean matches = isMatch(criterion, message, recentMessageUids);
@@ -318,7 +319,7 @@ public class MessageSearches implements Iterable<Long> {
     }
 
     private boolean matches(SearchQuery.FlagCriterion criterion, MailboxMessage message,
-            Collection<Long> recentMessageUids) {
+            Collection<MessageUid> recentMessageUids) {
         SearchQuery.BooleanOperator operator = criterion.getOperator();
         boolean isSet = operator.isSet();
         Flags.Flag flag = criterion.getFlag();
@@ -332,8 +333,8 @@ public class MessageSearches implements Iterable<Long> {
         } else if (flag == Flags.Flag.FLAGGED) {
             result = isSet == message.isFlagged();
         } else if (flag == Flags.Flag.RECENT) {
-            final long uid = message.getUid();
-            result = isSet == recentMessageUids.contains(Long.valueOf(uid));
+            final MessageUid uid = message.getUid();
+            result = isSet == recentMessageUids.contains(uid);
         } else if (flag == Flags.Flag.DELETED) {
             result = isSet == message.isDeleted();
         } else {
@@ -343,7 +344,7 @@ public class MessageSearches implements Iterable<Long> {
     }
 
     private boolean matches(SearchQuery.CustomFlagCriterion criterion, MailboxMessage message,
-            Collection<Long> recentMessageUids) {
+            Collection<MessageUid> recentMessageUids) {
         SearchQuery.BooleanOperator operator = criterion.getOperator();
         boolean isSet = operator.isSet();
         String flag = criterion.getFlag();
@@ -351,11 +352,11 @@ public class MessageSearches implements Iterable<Long> {
     }
 
     private boolean matches(SearchQuery.UidCriterion criterion, MailboxMessage message) {
-        SearchQuery.InOperator operator = criterion.getOperator();
-        NumericRange[] ranges = operator.getRange();
-        long uid = message.getUid();
+        SearchQuery.UidInOperator operator = criterion.getOperator();
+        UidRange[] ranges = operator.getRange();
+        MessageUid uid = message.getUid();
         boolean result = false;
-        for (NumericRange numericRange : ranges) {
+        for (UidRange numericRange : ranges) {
             if (numericRange.isIn(uid)) {
                 result = true;
                 break;
@@ -630,7 +631,7 @@ public class MessageSearches implements Iterable<Long> {
      * according to the SearchQuery
      * 
      */
-    public Iterator<Long> iterator() {
+    public Iterator<MessageUid> iterator() {
         return search().iterator();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java
index 8101f9d..18ea774 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java
@@ -31,6 +31,7 @@ import javax.inject.Inject;
 
 import org.apache.james.mailbox.MailboxManager.SearchCapabilities;
 import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
@@ -39,8 +40,8 @@ import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
 import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.model.SearchQuery.ConjunctionCriterion;
 import org.apache.james.mailbox.model.SearchQuery.Criterion;
-import org.apache.james.mailbox.model.SearchQuery.NumericRange;
 import org.apache.james.mailbox.model.SearchQuery.UidCriterion;
+import org.apache.james.mailbox.model.SearchQuery.UidRange;
 import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
 import org.apache.james.mailbox.store.mail.MessageMapper;
 import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
@@ -101,15 +102,15 @@ public class SimpleMessageSearchIndex implements MessageSearchIndex {
 	}
     
     @Override
-    public Iterator<Long> search(MailboxSession session, Mailbox mailbox, SearchQuery query) throws MailboxException {
+    public Iterator<MessageUid> search(MailboxSession session, Mailbox mailbox, SearchQuery query) throws MailboxException {
         Preconditions.checkArgument(session != null, "'session' is mandatory");
         return searchMultimap(session, ImmutableList.of(mailbox), query)
                 .get(mailbox.getMailboxId())
                 .iterator();
     }
     
-    private Multimap<MailboxId, Long> searchMultimap(MailboxSession session, Iterable<Mailbox> mailboxes, SearchQuery query) throws MailboxException {
-        Builder<MailboxId, Long> multimap = ImmutableMultimap.builder();
+    private Multimap<MailboxId, MessageUid> searchMultimap(MailboxSession session, Iterable<Mailbox> mailboxes, SearchQuery query) throws MailboxException {
+        Builder<MailboxId, MessageUid> multimap = ImmutableMultimap.builder();
         for (Mailbox mailbox: mailboxes) {
             multimap.putAll(searchMultimap(session, mailbox, query));
         }
@@ -117,7 +118,7 @@ public class SimpleMessageSearchIndex implements MessageSearchIndex {
 
     }
     
-    private Multimap<MailboxId, Long> searchMultimap(MailboxSession session, Mailbox mailbox, SearchQuery query) throws MailboxException {
+    private Multimap<MailboxId, MessageUid> searchMultimap(MailboxSession session, Mailbox mailbox, SearchQuery query) throws MailboxException {
         if (!isMatchingUser(session, mailbox)) {
             return ImmutableMultimap.of();
         }
@@ -129,8 +130,8 @@ public class SimpleMessageSearchIndex implements MessageSearchIndex {
         if (uidCrit != null) {
             // if there is a conjugated uid range criterion in the query tree we can optimize by
             // only fetching this uid range
-            NumericRange[] ranges = uidCrit.getOperator().getRange();
-            for (NumericRange r : ranges) {
+            UidRange[] ranges = uidCrit.getOperator().getRange();
+            for (UidRange r : ranges) {
                 Iterator<MailboxMessage> it = mapper.findInMailbox(mailbox, MessageRange.range(r.getLowValue(), r.getHighValue()), FetchType.Metadata, -1);
                 while (it.hasNext()) {
                     hitSet.add(it.next());
@@ -146,7 +147,7 @@ public class SimpleMessageSearchIndex implements MessageSearchIndex {
         }
         
         // MessageSearches does the filtering for us
-        return ImmutableMultimap.<MailboxId, Long>builder()
+        return ImmutableMultimap.<MailboxId, MessageUid>builder()
                     .putAll(mailbox.getMailboxId(), ImmutableList.copyOf(new MessageSearches(hitSet.iterator(), query, session).iterator()))
                     .build();
     }
@@ -156,7 +157,7 @@ public class SimpleMessageSearchIndex implements MessageSearchIndex {
     }
 
     @Override
-    public Map<MailboxId, Collection<Long>> search(MailboxSession session, final MultimailboxesSearchQuery searchQuery) throws MailboxException {
+    public Map<MailboxId, Collection<MessageUid>> search(MailboxSession session, final MultimailboxesSearchQuery searchQuery) throws MailboxException {
         List<Mailbox> allUserMailboxes = mailboxMapperFactory.getMailboxMapper(session)
                 .findMailboxWithPathLike(new MailboxPath(session.getPersonalSpace(), session.getUser().getUserName(), WILDCARD));
         FluentIterable<Mailbox> filteredMailboxes = FluentIterable.from(allUserMailboxes).filter(new Predicate<Mailbox>() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/comparator/UidComparator.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/comparator/UidComparator.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/comparator/UidComparator.java
index 0873a2f..a7a2952 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/comparator/UidComparator.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/comparator/UidComparator.java
@@ -35,7 +35,7 @@ public class UidComparator implements Comparator<MailboxMessage>{
     
     @Override
     public int compare(MailboxMessage o1, MailboxMessage o2) {
-        return (int) (o1.getUid() - o2.getUid());
+        return o1.getUid().compareTo(o2.getUid());
     }
 
     public static Comparator<MailboxMessage> uid(boolean reverse){

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
index df99cd1..ad44ade 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
@@ -34,6 +34,7 @@ import javax.mail.Flags;
 
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MessageResult;
@@ -120,7 +121,7 @@ public class MailboxEventDispatcherTest {
 
         dispatcher = new MailboxEventDispatcher(collector);
         result = mock(MessageResult.class);
-        when(result.getUid()).thenReturn(23L);
+        when(result.getUid()).thenReturn(MessageUid.of(23));
     }
 
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxMessageResultImplTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxMessageResultImplTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxMessageResultImplTest.java
index 38b2132..7a44eea 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxMessageResultImplTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxMessageResultImplTest.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue;
 
 import java.util.Date;
 
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.junit.Before;
 import org.junit.Test;
@@ -42,9 +43,9 @@ public class MailboxMessageResultImplTest {
     public void initNames() throws Exception
     {
         Date dateAB = new Date();
-        MailboxMessage msgA = buildMessage(100, dateAB);
-        MailboxMessage msgB = buildMessage(100, dateAB);
-        MailboxMessage msgC = buildMessage(200, new Date());
+        MailboxMessage msgA = buildMessage(MessageUid.of(100), dateAB);
+        MailboxMessage msgB = buildMessage(MessageUid.of(100), dateAB);
+        MailboxMessage msgC = buildMessage(MessageUid.of(200), new Date());
         
         msgResultA = new MessageResultImpl(msgA);
         msgResultACopy = new MessageResultImpl(msgA);
@@ -53,7 +54,7 @@ public class MailboxMessageResultImplTest {
     }
 
 
-    private MailboxMessage buildMessage(int uid, Date aDate) throws Exception {
+    private MailboxMessage buildMessage(MessageUid uid, Date aDate) throws Exception {
         MessageBuilder builder = new MessageBuilder();
         builder.uid = uid;
         builder.internalDate = aDate;

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageBatcherTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageBatcherTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageBatcherTest.java
index 6d6f455..58ac911 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageBatcherTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageBatcherTest.java
@@ -23,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import java.util.List;
 
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MessageRange;
 import org.junit.Test;
@@ -34,7 +35,7 @@ public class MessageBatcherTest {
     private MessageBatcher.BatchedOperation incrementBatcher = new MessageBatcher.BatchedOperation() {
         @Override
         public List<MessageRange> execute(MessageRange messageRange) throws MailboxException {
-            return Lists.<MessageRange>newArrayList(MessageRange.range(messageRange.getUidFrom() + 1, messageRange.getUidTo() + 1));
+            return Lists.<MessageRange>newArrayList(MessageRange.range(messageRange.getUidFrom().next(), messageRange.getUidTo().next()));
         }
     };
 
@@ -42,21 +43,23 @@ public class MessageBatcherTest {
     public void batchMessagesShouldWorkOnSingleRangeMode() throws Exception {
         MessageBatcher messageBatcher = new MessageBatcher(0);
         
-        assertThat(messageBatcher.batchMessages(MessageRange.range(1, 10), incrementBatcher)).containsOnly(MessageRange.range(2, 11));
+        assertThat(messageBatcher.batchMessages(MessageRange.range(MessageUid.of(1), MessageUid.of(10)), incrementBatcher))
+            .containsOnly(MessageRange.range(MessageUid.of(2), MessageUid.of(11)));
     }
 
     @Test
     public void batchMessagesShouldWorkWithNonZeroBatchedSize() throws Exception {
         MessageBatcher messageBatcher = new MessageBatcher(5);
 
-        assertThat(messageBatcher.batchMessages(MessageRange.range(1, 10), incrementBatcher)).containsOnly(MessageRange.range(2, 6), MessageRange.range(7, 11));
+        assertThat(messageBatcher.batchMessages(MessageRange.range(MessageUid.of(1), MessageUid.of(10)), incrementBatcher))
+            .containsOnly(MessageRange.range(MessageUid.of(2), MessageUid.of(6)), MessageRange.range(MessageUid.of(7), MessageUid.of(11)));
     }
 
     @Test(expected = MailboxException.class)
     public void batchMessagesShouldPropagateExceptions() throws Exception {
         MessageBatcher messageBatcher = new MessageBatcher(0);
 
-        messageBatcher.batchMessages(MessageRange.range(1, 10), new MessageBatcher.BatchedOperation() {
+        messageBatcher.batchMessages(MessageRange.range(MessageUid.of(1), MessageUid.of(10)), new MessageBatcher.BatchedOperation() {
             public List<MessageRange> execute(MessageRange messageRange) throws MailboxException {
                 throw new MailboxException();
             }

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageBuilder.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageBuilder.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageBuilder.java
index f84b216..61df70d 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageBuilder.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageBuilder.java
@@ -24,12 +24,13 @@ import java.util.Map;
 
 import javax.mail.Flags;
 
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 
 public class MessageBuilder {
     
     public TestId mailboxId = TestId.of(113);
-    public long uid = 776;
+    public MessageUid uid = MessageUid.of(776);
     public Date internalDate = new Date();
     public int size = 8867;
     public Flags flags = new Flags();
@@ -45,7 +46,7 @@ public class MessageBuilder {
         headers.put(field, value);
     }
 
-    public void setKey(int mailboxId, int uid) {
+    public void setKey(int mailboxId, MessageUid uid) {
         this.uid = uid;
         this.mailboxId = TestId.of(mailboxId);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SearchUtilsMultipartMixedTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/SearchUtilsMultipartMixedTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SearchUtilsMultipartMixedTest.java
index d350e33..0773d48 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/SearchUtilsMultipartMixedTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SearchUtilsMultipartMixedTest.java
@@ -26,6 +26,7 @@ import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Collection;
 
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.search.MessageSearches;
@@ -109,7 +110,7 @@ public class SearchUtilsMultipartMixedTest {
     MailboxMessage row;
 
 
-    Collection<Long> recent;
+    Collection<MessageUid> recent;
     @Before
     public void setUp() throws Exception {
         final MessageBuilder builder = new MessageBuilder();
@@ -121,7 +122,7 @@ public class SearchUtilsMultipartMixedTest {
         builder.header("Content-Type", "multipart/mixed;boundary=1729");
         builder.body = Charset.forName("us-ascii").encode(BODY).array();
         row = builder.build();
-        recent = new ArrayList<Long>();
+        recent = new ArrayList<MessageUid>();
     }
     
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SearchUtilsRFC822Test.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/SearchUtilsRFC822Test.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SearchUtilsRFC822Test.java
index c06c191..e50934b 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/SearchUtilsRFC822Test.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SearchUtilsRFC822Test.java
@@ -26,6 +26,7 @@ import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Collection;
 
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.search.MessageSearches;
@@ -48,11 +49,11 @@ public class SearchUtilsRFC822Test {
 
     MailboxMessage row;
 
-    Collection<Long> recent;
+    Collection<MessageUid> recent;
 
     @Before
     public void setUp() throws Exception {
-        recent = new ArrayList<Long>();
+        recent = new ArrayList<MessageUid>();
         MessageBuilder builder = new MessageBuilder();
         builder.header("From", "Alex <alex@example.org");
         builder.header("To", FROM_ADDRESS);

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SearchUtilsTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/SearchUtilsTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SearchUtilsTest.java
index 5ac4fe2..96c5e99 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/SearchUtilsTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SearchUtilsTest.java
@@ -31,6 +31,7 @@ import java.util.TimeZone;
 
 import javax.mail.Flags;
 
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.model.SearchQuery.AddressType;
 import org.apache.james.mailbox.model.SearchQuery.DateResolution;
@@ -59,7 +60,7 @@ public class SearchUtilsTest {
 
     MessageBuilder builder;
 
-    Collection<Long> recent;
+    Collection<MessageUid> recent;
     
     private Calendar getGMT() {
         return Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.UK);
@@ -72,9 +73,9 @@ public class SearchUtilsTest {
     }
     @Before
     public void setUp() throws Exception {
-        recent = new ArrayList<Long>();
+        recent = new ArrayList<MessageUid>();
         builder = new MessageBuilder();
-        builder.uid = 1009;
+        builder.uid = MessageUid.of(1009);
     }
     
     @Test
@@ -441,32 +442,32 @@ public class SearchUtilsTest {
 
     @Test
     public void testShouldMatchUidRange() throws Exception {
-        builder.setKey(1, 1729);
+        builder.setKey(1, MessageUid.of(1729));
         MailboxMessage row = builder.build();
-        assertFalse(new MessageSearches().isMatch(SearchQuery.uid(range(1, 1)), row, recent));
-        assertFalse(new MessageSearches().isMatch(SearchQuery.uid(range(1728, 1728)), row,
+        assertFalse(new MessageSearches().isMatch(SearchQuery.uid(range(MessageUid.of(1), MessageUid.of(1))), row, recent));
+        assertFalse(new MessageSearches().isMatch(SearchQuery.uid(range(MessageUid.of(1728), MessageUid.of(1728))), row,
                 recent));
-        assertTrue(new MessageSearches().isMatch(SearchQuery.uid(range(1729, 1729)), row,
+        assertTrue(new MessageSearches().isMatch(SearchQuery.uid(range(MessageUid.of(1729), MessageUid.of(1729))), row,
                 recent));
-        assertFalse(new MessageSearches().isMatch(SearchQuery.uid(range(1730, 1730)), row,
+        assertFalse(new MessageSearches().isMatch(SearchQuery.uid(range(MessageUid.of(1730), MessageUid.of(1730))), row,
                 recent));
-        assertFalse(new MessageSearches().isMatch(SearchQuery.uid(range(1, 1728)), row,
+        assertFalse(new MessageSearches().isMatch(SearchQuery.uid(range(MessageUid.of(1), MessageUid.of(1728))), row,
                 recent));
-        assertTrue(new MessageSearches().isMatch(SearchQuery.uid(range(1, 1729)), row,
+        assertTrue(new MessageSearches().isMatch(SearchQuery.uid(range(MessageUid.of(1), MessageUid.of(1729))), row,
                 recent));
-        assertTrue(new MessageSearches().isMatch(SearchQuery.uid(range(1729, 1800)), row,
+        assertTrue(new MessageSearches().isMatch(SearchQuery.uid(range(MessageUid.of(1729), MessageUid.of(1800))), row,
                 recent));
         assertFalse(new MessageSearches().isMatch(SearchQuery
-                .uid(range(1730, Long.MAX_VALUE)), row, recent));
-        assertFalse(new MessageSearches().isMatch(SearchQuery.uid(range(1730,
-                Long.MAX_VALUE, 1, 1728)), row, recent));
-        assertTrue(new MessageSearches().isMatch(SearchQuery.uid(range(1730, Long.MAX_VALUE,
-                1, 1729)), row, recent));
+                .uid(range(MessageUid.of(1730), MessageUid.MAX_VALUE)), row, recent));
+        assertFalse(new MessageSearches().isMatch(SearchQuery.uid(range(MessageUid.of(1730),
+                MessageUid.MAX_VALUE, MessageUid.of(1), MessageUid.of(1728))), row, recent));
+        assertTrue(new MessageSearches().isMatch(SearchQuery.uid(range(MessageUid.of(1730), MessageUid.MAX_VALUE,
+                MessageUid.of(1), MessageUid.of(1729))), row, recent));
         assertFalse(new MessageSearches().isMatch(SearchQuery
-                .uid(range(1, 1728, 1800, 1810)), row, recent));
-        assertTrue(new MessageSearches().isMatch(SearchQuery.uid(range(1, 1, 1729, 1729)),
+                .uid(range(MessageUid.of(1), MessageUid.of(1728), MessageUid.of(1800), MessageUid.of(1810))), row, recent));
+        assertTrue(new MessageSearches().isMatch(SearchQuery.uid(range(MessageUid.of(1), MessageUid.of(1), MessageUid.of(1729), MessageUid.of(1729))),
                 row, recent));
-        assertFalse(new MessageSearches().isMatch(SearchQuery.uid(range(1, 1, 1800, 1800)),
+        assertFalse(new MessageSearches().isMatch(SearchQuery.uid(range(MessageUid.of(1), MessageUid.of(1), MessageUid.of(1800), MessageUid.of(1800))),
                 row, recent));
     }
 
@@ -565,7 +566,7 @@ public class SearchUtilsTest {
     public void testShouldMatchSeenRecentSet() throws Exception {
         builder.setFlags(false, false, false, false, false, false);
         MailboxMessage row = builder.build();
-        recent.add(new Long(row.getUid()));
+        recent.add(row.getUid());
         assertFalse(new MessageSearches().isMatch(SearchQuery.flagIsSet(Flags.Flag.SEEN),
                 row, recent));
         assertFalse(new MessageSearches().isMatch(SearchQuery.flagIsSet(Flags.Flag.FLAGGED),
@@ -584,7 +585,7 @@ public class SearchUtilsTest {
     public void testShouldMatchSeenFlagUnSet() throws Exception {
         builder.setFlags(false, true, true, true, true, true);
         MailboxMessage row = builder.build();
-        recent.add(new Long(row.getUid()));
+        recent.add(row.getUid());
         assertTrue(new MessageSearches().isMatch(SearchQuery.flagIsUnSet(Flags.Flag.SEEN),
                 row, recent));
         assertFalse(new MessageSearches().isMatch(SearchQuery
@@ -603,7 +604,7 @@ public class SearchUtilsTest {
     public void testShouldMatchAnsweredFlagUnSet() throws Exception {
         builder.setFlags(true, true, false, true, true, true);
         MailboxMessage row = builder.build();
-        recent.add(new Long(row.getUid()));
+        recent.add(row.getUid());
         assertFalse(new MessageSearches().isMatch(SearchQuery.flagIsUnSet(Flags.Flag.SEEN),
                 row, recent));
         assertFalse(new MessageSearches().isMatch(SearchQuery
@@ -622,7 +623,7 @@ public class SearchUtilsTest {
     public void testShouldMatchFlaggedFlagUnSet() throws Exception {
         builder.setFlags(true, false, true, true, true, true);
         MailboxMessage row = builder.build();
-        recent.add(new Long(row.getUid()));
+        recent.add(row.getUid());
         assertFalse(new MessageSearches().isMatch(SearchQuery.flagIsUnSet(Flags.Flag.SEEN),
                 row, recent));
         assertTrue(new MessageSearches().isMatch(
@@ -641,7 +642,7 @@ public class SearchUtilsTest {
     public void testShouldMatchDraftFlagUnSet() throws Exception {
         builder.setFlags(true, true, true, false, true, true);
         MailboxMessage row = builder.build();
-        recent.add(new Long(row.getUid()));
+        recent.add(row.getUid());
         assertFalse(new MessageSearches().isMatch(SearchQuery.flagIsUnSet(Flags.Flag.SEEN),
                 row, recent));
         assertFalse(new MessageSearches().isMatch(SearchQuery
@@ -660,7 +661,7 @@ public class SearchUtilsTest {
     public void testShouldMatchDeletedFlagUnSet() throws Exception {
         builder.setFlags(true, true, true, true, false, true);
         MailboxMessage row = builder.build();
-        recent.add(new Long(row.getUid()));
+        recent.add(row.getUid());
         assertFalse(new MessageSearches().isMatch(SearchQuery.flagIsUnSet(Flags.Flag.SEEN),
                 row, recent));
         assertFalse(new MessageSearches().isMatch(SearchQuery
@@ -679,7 +680,7 @@ public class SearchUtilsTest {
     public void testShouldMatchSeenRecentUnSet() throws Exception {
         builder.setFlags(true, true, true, true, true, true);
         MailboxMessage row = builder.build();
-        recent.add(new Long(row.getUid() + 1));
+        recent.add(row.getUid().next());
         assertFalse(new MessageSearches().isMatch(SearchQuery.flagIsUnSet(Flags.Flag.SEEN),
                 row, recent));
         assertFalse(new MessageSearches().isMatch(SearchQuery
@@ -737,15 +738,15 @@ public class SearchUtilsTest {
                 SearchQuery.all()), row, recent));
     }
     
-    private SearchQuery.NumericRange[] range(long low, long high) {
-        return new SearchQuery.NumericRange[]{ new SearchQuery.NumericRange(low, high) };
+    private SearchQuery.UidRange[] range(MessageUid low, MessageUid high) {
+        return new SearchQuery.UidRange[]{ new SearchQuery.UidRange(low, high) };
     }
 
-    private SearchQuery.NumericRange[] range(long lowOne, long highOne,
-            long lowTwo, long highTwo) {
-        return new SearchQuery.NumericRange[]{
-                new SearchQuery.NumericRange(lowOne, highOne),
-                new SearchQuery.NumericRange(lowTwo, highTwo) };
+    private SearchQuery.UidRange[] range(MessageUid lowOne, MessageUid highOne,
+            MessageUid lowTwo, MessageUid highTwo) {
+        return new SearchQuery.UidRange[]{
+                new SearchQuery.UidRange(lowOne, highOne),
+                new SearchQuery.UidRange(lowTwo, highTwo) };
     }
     
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
index b053172..6b18190 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
@@ -36,17 +36,20 @@ import java.util.Map.Entry;
 import javax.mail.Flags;
 
 import org.apache.commons.lang.NotImplementedException;
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.model.MessageAttachment;
 import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.Property;
 
+import com.google.common.base.Objects;
+
 public class SimpleMailboxMembership implements MailboxMessage {
     
     private static final String TOSTRING_SEPARATOR = " ";
     
     public TestId mailboxId;
-    public long uid;
+    public MessageUid uid;
     public Date internalDate;
     public boolean recent = false;
     public boolean answered = false;
@@ -55,7 +58,7 @@ public class SimpleMailboxMembership implements MailboxMessage {
     public boolean flagged = false;
     public boolean seen = false;
 
-    public SimpleMailboxMembership(TestId mailboxId, long uid, long modSeq, Date internalDate, int size, 
+    public SimpleMailboxMembership(TestId mailboxId, MessageUid uid, long modSeq, Date internalDate, int size, 
             Flags flags, byte[] body, Map<String, String> headers) throws Exception {
         super();
         this.mailboxId = mailboxId;
@@ -81,7 +84,7 @@ public class SimpleMailboxMembership implements MailboxMessage {
         return mailboxId;
     }
     
-    public long getUid() {
+    public MessageUid getUid() {
         return uid;
     }
 
@@ -148,27 +151,17 @@ public class SimpleMailboxMembership implements MailboxMessage {
 
     @Override
     public int hashCode() {
-        final int PRIME = 31;
-        int result = 1;
-        result = PRIME * result + (int) (mailboxId.id ^ (mailboxId.id >>> 32));
-        result = PRIME * result + (int) (uid ^ (uid >>> 32));
-        return result;
+        return Objects.hashCode(mailboxId.id, uid);
     }
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        final MailboxMessage other = (MailboxMessage) obj;
-        if (!mailboxId.equals(other.getMailboxId()))
-            return false;
-        if (uid != other.getUid())
-            return false;
-        return true;
+        if (obj instanceof SimpleMailboxMembership) {
+            SimpleMailboxMembership other = (SimpleMailboxMembership) obj;
+            return Objects.equal(this.mailboxId.id, other.mailboxId.id)
+                    && Objects.equal(this.uid, other.uid);
+        }
+        return false;
     }
 
     public String toString() {
@@ -248,7 +241,7 @@ public class SimpleMailboxMembership implements MailboxMessage {
     }
 
     public int compareTo(MailboxMessage other) {
-        return (int) (getUid() - other.getUid());
+        return getUid().compareTo(other.getUid());
     }
 
     public long getModSeq() {
@@ -259,7 +252,8 @@ public class SimpleMailboxMembership implements MailboxMessage {
         this.modSeq = modSeq;
     }
 
-    public void setUid(long uid) {
+    @Override
+    public void setUid(MessageUid uid) {
         this.uid = uid;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
index b49fa93..77a3523 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
@@ -32,6 +32,7 @@ import java.util.Set;
 import javax.mail.Flags;
 import javax.mail.util.SharedByteArrayInputStream;
 
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.model.MessageRange;
@@ -46,6 +47,9 @@ import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
 import org.assertj.core.api.iterable.Extractor;
 import org.junit.Test;
 
+import com.google.common.base.Optional;
+import com.google.common.collect.Iterables;
+
 public class StoreMailboxMessageResultIteratorTest {
 
     private final class TestFetchGroup implements FetchGroup {
@@ -84,20 +88,16 @@ public class StoreMailboxMessageResultIteratorTest {
                                                               org.apache.james.mailbox.store.mail.MessageMapper.FetchType type, int limit)
                 throws MailboxException {
             
-            long start = set.getUidFrom();
-            long end = Math.min(start + limit, set.getUidTo());
-
             List<MailboxMessage> messages = new ArrayList<MailboxMessage>();
-            
-            for (long uid: MessageRange.range(start, end)) {
+            for (MessageUid uid: Iterables.limit(set, limit)) {
                 if (messageRange.includes(uid)) {
                     messages.add(createMessage(uid));
-                }
+                }    
             }
             return messages.iterator();
         }
 
-        private SimpleMailboxMessage createMessage(long uid) {
+        private SimpleMailboxMessage createMessage(MessageUid uid) {
             SimpleMailboxMessage message = new SimpleMailboxMessage(null, 0, 0, new SharedByteArrayInputStream(
                     "".getBytes()), new Flags(), new PropertyBuilder(), TestId.of(1L));
             message.setUid(uid);
@@ -105,7 +105,7 @@ public class StoreMailboxMessageResultIteratorTest {
         }
 
         @Override
-        public Map<Long, MessageMetaData> expungeMarkedForDeletionInMailbox(Mailbox mailbox, MessageRange set)
+        public Map<MessageUid, MessageMetaData> expungeMarkedForDeletionInMailbox(Mailbox mailbox, MessageRange set)
                 throws MailboxException {
             throw new UnsupportedOperationException();
 
@@ -128,12 +128,12 @@ public class StoreMailboxMessageResultIteratorTest {
         }
 
         @Override
-        public Long findFirstUnseenMessageUid(Mailbox mailbox) throws MailboxException {
+        public MessageUid findFirstUnseenMessageUid(Mailbox mailbox) throws MailboxException {
             throw new UnsupportedOperationException();
         }
 
         @Override
-        public List<Long> findRecentMessageUidsInMailbox(Mailbox mailbox) throws MailboxException {
+        public List<MessageUid> findRecentMessageUidsInMailbox(Mailbox mailbox) throws MailboxException {
             throw new UnsupportedOperationException();
 
         }
@@ -155,7 +155,7 @@ public class StoreMailboxMessageResultIteratorTest {
         }
 
         @Override
-        public long getLastUid(Mailbox mailbox) throws MailboxException {
+        public Optional<MessageUid> getLastUid(Mailbox mailbox) throws MailboxException {
             throw new UnsupportedOperationException();
         }
 
@@ -173,21 +173,21 @@ public class StoreMailboxMessageResultIteratorTest {
 
     @Test
     public void testBatching() {
-        MessageRange range = MessageRange.range(1, 10);
+        MessageRange range = MessageRange.range(MessageUid.of(1), MessageUid.of(10));
         int batchSize = 3;
         StoreMessageResultIterator it = new StoreMessageResultIterator(new TestMessageMapper(MessageRange.all()), null, range, batchSize, new TestFetchGroup());
 
         assertThat(it).extracting(new Extractor<MessageResult, Long>(){
             @Override
             public Long extract(MessageResult input) {
-                return input.getUid();
+                return input.getUid().asLong();
             }
         }).containsExactly(1l, 2l, 3l, 4l, 5l, 6l, 7l, 8l, 9l, 10l);
     }
 
     @Test
     public void nextShouldReturnFirstElement() {
-        MessageRange range = MessageRange.one(1);
+        MessageRange range = MessageUid.of(1).toRange();
         int batchSize = 42;
         StoreMessageResultIterator iterator = new StoreMessageResultIterator(new TestMessageMapper(range), null, range, batchSize, new TestFetchGroup());
         assertThat(iterator.next()).isNotNull();
@@ -195,8 +195,8 @@ public class StoreMailboxMessageResultIteratorTest {
     
     @Test(expected=NoSuchElementException.class)
     public void nextShouldThrowWhenNoElement() {
-        MessageRange messages = MessageRange.one(1);
-        MessageRange findRange = MessageRange.one(2);
+        MessageRange messages = MessageUid.of(1).toRange();
+        MessageRange findRange = MessageUid.of(2).toRange();
         int batchSize = 42;
         StoreMessageResultIterator iterator = new StoreMessageResultIterator(new TestMessageMapper(messages), null, findRange, batchSize, new TestFetchGroup());
         iterator.next();
@@ -204,8 +204,8 @@ public class StoreMailboxMessageResultIteratorTest {
     
     @Test
     public void hasNextShouldReturnFalseWhenNoElement() {
-        MessageRange messages = MessageRange.one(1);
-        MessageRange findRange = MessageRange.one(2);
+        MessageRange messages = MessageUid.of(1).toRange();
+        MessageRange findRange = MessageUid.of(2).toRange();
         int batchSize = 42;
         StoreMessageResultIterator iterator = new StoreMessageResultIterator(new TestMessageMapper(messages), null, findRange, batchSize, new TestFetchGroup());
         assertThat(iterator.hasNext()).isFalse();

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListenerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListenerIntegrationTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListenerIntegrationTest.java
index fde1fcf..f266d29 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListenerIntegrationTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListenerIntegrationTest.java
@@ -25,6 +25,7 @@ import java.util.TreeMap;
 
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageMetaData;
@@ -109,7 +110,7 @@ public class BroadcastDelegatingMailboxListenerIntegrationTest {
     public void mailboxEventListenersShouldBeTriggeredIfRegistered() throws Exception {
         SimpleMailbox simpleMailbox = new SimpleMailbox(MAILBOX_PATH_1, 42);
         simpleMailbox.setMailboxId(TestId.of(52));
-        final MailboxListener.Event event = new EventFactory().added(mailboxSession, new TreeMap<Long, MessageMetaData>(), simpleMailbox);
+        final MailboxListener.Event event = new EventFactory().added(mailboxSession, new TreeMap<MessageUid, MessageMetaData>(), simpleMailbox);
 
         broadcastDelegatingMailboxListener1.event(event);
 
@@ -122,7 +123,7 @@ public class BroadcastDelegatingMailboxListenerIntegrationTest {
     public void onceEventListenersShouldBeTriggeredOnceAcrossTheCluster() {
         SimpleMailbox simpleMailbox = new SimpleMailbox(MAILBOX_PATH_1, 42);
         simpleMailbox.setMailboxId(TestId.of(52));
-        final MailboxListener.Event event = new EventFactory().added(mailboxSession, new TreeMap<Long, MessageMetaData>(), simpleMailbox);
+        final MailboxListener.Event event = new EventFactory().added(mailboxSession, new TreeMap<MessageUid, MessageMetaData>(), simpleMailbox);
 
         broadcastDelegatingMailboxListener1.event(event);
 
@@ -135,7 +136,7 @@ public class BroadcastDelegatingMailboxListenerIntegrationTest {
     public void eachEventListenersShouldBeTriggeredOnEachNode() {
         SimpleMailbox simpleMailbox = new SimpleMailbox(MAILBOX_PATH_1, 42);
         simpleMailbox.setMailboxId(TestId.of(52));
-        final MailboxListener.Event event = new EventFactory().added(mailboxSession, new TreeMap<Long, MessageMetaData>(), simpleMailbox);
+        final MailboxListener.Event event = new EventFactory().added(mailboxSession, new TreeMap<MessageUid, MessageMetaData>(), simpleMailbox);
 
         broadcastDelegatingMailboxListener1.event(event);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java
index bab3d60..1159f63 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java
@@ -27,6 +27,7 @@ import javax.mail.Flags;
 
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageMetaData;
@@ -43,7 +44,7 @@ import com.google.common.collect.Lists;
 
 public abstract class EventSerializerTest {
 
-    public static final long UID = 42L;
+    public static final MessageUid UID = MessageUid.of(42);
     public static final long MOD_SEQ = 24L;
     public static final UpdatedFlags UPDATED_FLAGS = new UpdatedFlags(UID, MOD_SEQ, new Flags(), new Flags(Flags.Flag.SEEN));
     public static final Flags FLAGS = new Flags();
@@ -68,7 +69,7 @@ public abstract class EventSerializerTest {
 
     @Test
     public void addedEventShouldBeWellConverted() throws Exception {
-        TreeMap<Long, MessageMetaData> treeMap = new TreeMap<Long, MessageMetaData>();
+        TreeMap<MessageUid, MessageMetaData> treeMap = new TreeMap<MessageUid, MessageMetaData>();
         treeMap.put(UID, MESSAGE_META_DATA);
         MailboxListener.Event event = eventFactory.added(mailboxSession, treeMap, mailbox);
         byte[] serializedEvent = serializer.serializeEvent(event);
@@ -82,7 +83,7 @@ public abstract class EventSerializerTest {
 
     @Test
     public void expungedEventShouldBeWellConverted() throws Exception {
-        TreeMap<Long, MessageMetaData> treeMap = new TreeMap<Long, MessageMetaData>();
+        TreeMap<MessageUid, MessageMetaData> treeMap = new TreeMap<MessageUid, MessageMetaData>();
         treeMap.put(UID, MESSAGE_META_DATA);
         MailboxListener.Event event = eventFactory.expunged(mailboxSession, treeMap, mailbox);
         byte[] serializedEvent = serializer.serializeEvent(event);

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/MailboxMessagePackEventSerializerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/MailboxMessagePackEventSerializerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/MailboxMessagePackEventSerializerTest.java
deleted file mode 100644
index cfcc378..0000000
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/MailboxMessagePackEventSerializerTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/****************************************************************
- * 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.store.json;
-
-import org.apache.james.mailbox.store.TestIdDeserializer;
-import org.apache.james.mailbox.store.event.EventSerializer;
-import org.apache.james.mailbox.store.json.event.EventConverter;
-import org.apache.james.mailbox.store.json.event.MailboxConverter;
-
-public class MailboxMessagePackEventSerializerTest extends EventSerializerTest {
-
-    @Override
-    EventSerializer createSerializer() {
-        return new MessagePackEventSerializer(
-            new EventConverter(
-                new MailboxConverter(new TestIdDeserializer())));
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/MessagePackEventSerializerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/MessagePackEventSerializerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/MessagePackEventSerializerTest.java
new file mode 100644
index 0000000..5da40ea
--- /dev/null
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/MessagePackEventSerializerTest.java
@@ -0,0 +1,35 @@
+/****************************************************************
+ * 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.store.json;
+
+import org.apache.james.mailbox.store.TestIdDeserializer;
+import org.apache.james.mailbox.store.event.EventSerializer;
+import org.apache.james.mailbox.store.json.event.EventConverter;
+import org.apache.james.mailbox.store.json.event.MailboxConverter;
+
+public class MessagePackEventSerializerTest extends EventSerializerTest {
+
+    @Override
+    EventSerializer createSerializer() {
+        return new MessagePackEventSerializer(
+            new EventConverter(
+                new MailboxConverter(new TestIdDeserializer())));
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DefaultMailboxMessageIdTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DefaultMailboxMessageIdTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DefaultMailboxMessageIdTest.java
index 19b83a3..ecfeb9f 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DefaultMailboxMessageIdTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DefaultMailboxMessageIdTest.java
@@ -20,6 +20,7 @@ package org.apache.james.mailbox.store.mail.model;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.store.TestId;
 import org.junit.Test;
 
@@ -29,12 +30,12 @@ public class DefaultMailboxMessageIdTest {
 
     @Test(expected=NullPointerException.class)
     public void constructorShouldThrowWhenNullMailboxId() {
-        new DefaultMessageId(null, 1);
+        new DefaultMessageId(null, MessageUid.of(1));
     }
 
     @Test
     public void serializeShouldFormatMailboxIdAndUid() {
-        DefaultMessageId id = new DefaultMessageId(TestId.of(12l), 1);
+        DefaultMessageId id = new DefaultMessageId(TestId.of(12l), MessageUid.of(1));
         assertThat(id.serialize()).isEqualTo("12-1");
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessageTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessageTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessageTest.java
index 1fae5a9..96cc74f 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessageTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessageTest.java
@@ -22,6 +22,7 @@ package org.apache.james.mailbox.store.mail.model;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.store.MessageBuilder;
 import org.junit.Test;
 
@@ -37,7 +38,7 @@ public class DelegatingMailboxMessageTest {
 
     private MailboxMessage buildMessage(int uid) throws Exception {
         MessageBuilder builder = new MessageBuilder();
-        builder.uid = uid;
+        builder.uid = MessageUid.of(uid);
         return builder.build();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMessageAssertTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMessageAssertTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMessageAssertTest.java
index 8626375..c5056f0 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMessageAssertTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMessageAssertTest.java
@@ -25,6 +25,7 @@ import java.util.Date;
 import javax.mail.Flags;
 import javax.mail.util.SharedByteArrayInputStream;
 
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.store.TestId;
 import org.apache.james.mailbox.store.mail.MessageMapper;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
@@ -34,7 +35,7 @@ import org.junit.Test;
 public class MailboxMessageAssertTest {
 
     public static final TestId MAILBOX_ID = TestId.of(42L);
-    public static final long UID = 24L;
+    public static final MessageUid UID = MessageUid.of(24);
 
     @Test
     public void messageAssertShouldSucceedWithTwoEqualsMessages() throws IOException {

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
index 956c8fb..5b2a016 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
@@ -32,6 +32,7 @@ import javax.mail.util.SharedByteArrayInputStream;
 
 import org.apache.james.mailbox.FlagsBuilder;
 import org.apache.james.mailbox.MessageManager.FlagsUpdateMode;
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.Attachment;
 import org.apache.james.mailbox.model.AttachmentId;
@@ -57,6 +58,7 @@ import org.xenei.junit.contract.Contract;
 import org.xenei.junit.contract.ContractTest;
 import org.xenei.junit.contract.IProducer;
 
+import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
 
 @Contract(MapperProvider.class)
@@ -178,7 +180,7 @@ public class MessageMapperTest<T extends MapperProvider> {
     @ContractTest
     public void mailboxUnSeenCountShouldBeDecrementedAfterAMessageIsMarkedSeen() throws MailboxException {
         saveMessages();
-        messageMapper.updateFlags(benwaInboxMailbox, new FlagsUpdateCalculator(new Flags(Flags.Flag.SEEN), FlagsUpdateMode.REPLACE), MessageRange.one(message1.getUid())).hasNext();
+        messageMapper.updateFlags(benwaInboxMailbox, new FlagsUpdateCalculator(new Flags(Flags.Flag.SEEN), FlagsUpdateMode.REPLACE), message1.getUid().toRange()).hasNext();
         assertThat(messageMapper.countUnseenMessagesInMailbox(benwaInboxMailbox)).isEqualTo(4);
     }
 
@@ -207,7 +209,7 @@ public class MessageMapperTest<T extends MapperProvider> {
     @ContractTest
     public void deletingUnExistingMessageShouldHaveNoSideEffect() throws MailboxException, IOException {
         saveMessages();
-        message6.setUid(messageMapper.getLastUid(benwaInboxMailbox) + 1);
+        message6.setUid(messageMapper.getLastUid(benwaInboxMailbox).get().next());
         messageMapper.delete(benwaInboxMailbox, message6);
         assertThat(messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.all(), MessageMapper.FetchType.Full, LIMIT))
             .containsOnly(message1, message2, message3, message4, message5);
@@ -215,7 +217,7 @@ public class MessageMapperTest<T extends MapperProvider> {
 
     @ContractTest
     public void noMessageShouldBeRetrievedInEmptyMailbox() throws MailboxException {
-        assertThat(messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.one(message1.getUid()), MessageMapper.FetchType.Metadata, LIMIT)).isEmpty();
+        assertThat(messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.one(MessageUid.MIN_VALUE), MessageMapper.FetchType.Metadata, LIMIT)).isEmpty();
     }
 
     @ContractTest
@@ -487,25 +489,25 @@ public class MessageMapperTest<T extends MapperProvider> {
     }
 
     @ContractTest
-    public void getLastUidShouldReturn0OnEmptyMailbox() throws MailboxException {
-        assertThat(messageMapper.getLastUid(benwaInboxMailbox)).isEqualTo(0);
+    public void getLastUidShouldReturnEmptyOnEmptyMailbox() throws MailboxException {
+        assertThat(messageMapper.getLastUid(benwaInboxMailbox)).isEqualTo(Optional.absent());
     }
 
     @ContractTest
     public void insertingAMessageShouldIncrementLastUid() throws MailboxException {
         messageMapper.add(benwaInboxMailbox, message1);
-        long uid = messageMapper.getLastUid(benwaInboxMailbox);
-        assertThat(uid).isGreaterThan(0);
+        Optional<MessageUid> uid = messageMapper.getLastUid(benwaInboxMailbox);
+        assertThat(uid).isNotEqualTo(Optional.absent());
         messageMapper.add(benwaInboxMailbox, message2);
-        assertThat(messageMapper.getLastUid(benwaInboxMailbox)).isGreaterThan(uid);
+        assertThat(messageMapper.getLastUid(benwaInboxMailbox).get()).isGreaterThan(uid.get());
     }
 
     @ContractTest
     public void copyShouldIncrementUid() throws MailboxException, IOException {
         saveMessages();
-        long uid = messageMapper.getLastUid(benwaInboxMailbox);
+        MessageUid uid = messageMapper.getLastUid(benwaInboxMailbox).get();
         messageMapper.copy(benwaInboxMailbox, SimpleMailboxMessage.copy(benwaInboxMailbox.getMailboxId(), message6));
-        assertThat(messageMapper.getLastUid(benwaInboxMailbox)).isGreaterThan(uid);
+        assertThat(messageMapper.getLastUid(benwaInboxMailbox).get()).isGreaterThan(uid);
     }
 
     @ContractTest
@@ -536,16 +538,16 @@ public class MessageMapperTest<T extends MapperProvider> {
         MailboxMessage message7 = SimpleMailboxMessage.copy(benwaInboxMailbox.getMailboxId(), message6);
         messageMapper.copy(benwaInboxMailbox, message7);
         message7.setModSeq(messageMapper.getHighestModSeq(benwaInboxMailbox));
-        assertThat(messageMapper.getLastUid(benwaInboxMailbox)).isGreaterThan(message6.getUid());
+        assertThat(messageMapper.getLastUid(benwaInboxMailbox).get()).isGreaterThan(message6.getUid());
 
         MailboxMessage result = messageMapper.findInMailbox(benwaInboxMailbox,
-            MessageRange.one(messageMapper.getLastUid(benwaInboxMailbox)),
+            MessageRange.one(messageMapper.getLastUid(benwaInboxMailbox).get()),
             MessageMapper.FetchType.Full,
             LIMIT)
             .next();
 
         MessageAssert.assertThat(result).isEqualToWithoutUid(message7, MessageMapper.FetchType.Full);
-        assertThat(result.getUid()).isEqualTo(messageMapper.getLastUid(benwaInboxMailbox));
+        assertThat(result.getUid()).isEqualTo(messageMapper.getLastUid(benwaInboxMailbox).get());
     }
 
     @ContractTest
@@ -743,7 +745,7 @@ public class MessageMapperTest<T extends MapperProvider> {
         MessageAssert.assertThat(retrieveMessageFromStorage(message)).hasFlags(new Flags(USER_FLAG));
     }
 
-    private Map<Long, MessageMetaData> markThenPerformExpunge(MessageRange range) throws MailboxException {
+    private Map<MessageUid, MessageMetaData> markThenPerformExpunge(MessageRange range) throws MailboxException {
         messageMapper.updateFlags(benwaInboxMailbox, new FlagsUpdateCalculator(new Flags(Flags.Flag.DELETED), FlagsUpdateMode.REPLACE), MessageRange.one(message1.getUid()));
         messageMapper.updateFlags(benwaInboxMailbox, new FlagsUpdateCalculator(new Flags(Flags.Flag.DELETED), FlagsUpdateMode.REPLACE), MessageRange.one(message4.getUid()));
         return messageMapper.expungeMarkedForDeletionInMailbox(benwaInboxMailbox, range);

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMoveTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMoveTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMoveTest.java
index 8d9de5c..add58ea 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMoveTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMoveTest.java
@@ -100,7 +100,7 @@ public class MessageMoveTest<T extends MapperProvider> {
         Flags expectedFlags = message1.createFlags();
         expectedFlags.add(Flags.Flag.RECENT);
         assertThat(messageMetaData.getFlags()).isEqualTo(expectedFlags);
-        assertThat(messageMetaData.getUid()).isEqualTo(messageMapper.getLastUid(benwaWorkMailbox));
+        assertThat(messageMetaData.getUid()).isEqualTo(messageMapper.getLastUid(benwaWorkMailbox).get());
         assertThat(messageMetaData.getModSeq()).isEqualTo(messageMapper.getHighestModSeq(benwaWorkMailbox));
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MetadataMapAssert.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MetadataMapAssert.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MetadataMapAssert.java
index fc1ba4f..6d7b3c0 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MetadataMapAssert.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MetadataMapAssert.java
@@ -21,16 +21,17 @@ package org.apache.james.mailbox.store.mail.model;
 
 import java.util.Map;
 
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.model.MessageMetaData;
 import org.assertj.core.api.AbstractAssert;
 
-public class MetadataMapAssert extends AbstractAssert<MetadataMapAssert, Map<Long, MessageMetaData>> {
+public class MetadataMapAssert extends AbstractAssert<MetadataMapAssert, Map<MessageUid, MessageMetaData>> {
 
-    public MetadataMapAssert(Map<Long, MessageMetaData> actual) {
+    public MetadataMapAssert(Map<MessageUid, MessageMetaData> actual) {
         super(actual, MetadataMapAssert.class);
     }
 
-    public static MetadataMapAssert assertThat(Map<Long, MessageMetaData> actual) {
+    public static MetadataMapAssert assertThat(Map<MessageUid, MessageMetaData> actual) {
         return new MetadataMapAssert(actual);
     }
 
@@ -43,7 +44,7 @@ public class MetadataMapAssert extends AbstractAssert<MetadataMapAssert, Map<Lon
 
     public MetadataMapAssert containsMetadataForMessages(MailboxMessage... messages) {
         for(MailboxMessage message : messages) {
-            if (actual.get(message.getUid()).getUid() != message.getUid()) {
+            if (! actual.get(message.getUid()).getUid().equals(message.getUid())) {
                 failWithMessage("Expected UID stored in MessageMetadata to be <%s> but was <%s>", actual.get(message.getUid()).getUid(), message.getUid());
             }
             if (!actual.get(message.getUid()).getInternalDate().equals(message.getInternalDate())) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MetadataMapAssertTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MetadataMapAssertTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MetadataMapAssertTest.java
index 23dcf9c..0887e0a 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MetadataMapAssertTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MetadataMapAssertTest.java
@@ -26,6 +26,7 @@ import java.util.Map;
 import javax.mail.Flags;
 import javax.mail.util.SharedByteArrayInputStream;
 
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.store.SimpleMessageMetaData;
 import org.apache.james.mailbox.store.TestId;
@@ -36,7 +37,7 @@ import org.junit.Test;
 
 public class MetadataMapAssertTest {
 
-    private static final Long UID = 18L;
+    private static final MessageUid UID = MessageUid.of(18);
     private static final Long MODSEQ = 24L;
     private static final Date DATE = new Date();
     private static final String HEADER_STRING = "name: headerName\n\n";
@@ -55,31 +56,31 @@ public class MetadataMapAssertTest {
 
     @Test
     public void metadataMapAssertShouldSucceedWhenContainingRightMetadata() {
-        Map<Long, MessageMetaData> metaDataMap = new HashMap<Long, MessageMetaData>();
-        metaDataMap.put(18L, new SimpleMessageMetaData(UID, MODSEQ, new Flags(), HEADER_STRING.length() + BODY_STRING.length(), DATE));
+        Map<MessageUid, MessageMetaData> metaDataMap = new HashMap<MessageUid, MessageMetaData>();
+        metaDataMap.put(UID, new SimpleMessageMetaData(UID, MODSEQ, new Flags(), HEADER_STRING.length() + BODY_STRING.length(), DATE));
         MetadataMapAssert.assertThat(metaDataMap).containsMetadataForMessages(message1);
     }
 
     @Test(expected = AssertionError.class)
     public void metadataMapAssertShouldFailWhenUidMismatch() {
-        Map<Long, MessageMetaData> metaDataMap = new HashMap<Long, MessageMetaData>();
-        metaDataMap.put(18L, new SimpleMessageMetaData(UID + 1, MODSEQ, new Flags(), HEADER_STRING.length() + BODY_STRING.length(), DATE));
+        Map<MessageUid, MessageMetaData> metaDataMap = new HashMap<MessageUid, MessageMetaData>();
+        metaDataMap.put(UID, new SimpleMessageMetaData(UID.next(), MODSEQ, new Flags(), HEADER_STRING.length() + BODY_STRING.length(), DATE));
         MetadataMapAssert.assertThat(metaDataMap).containsMetadataForMessages(message1);
     }
 
     @Test(expected = AssertionError.class)
     public void metadataMapAssertShouldFailWhenDateMismatch() {
-        Map<Long, MessageMetaData> metaDataMap = new HashMap<Long, MessageMetaData>();
+        Map<MessageUid, MessageMetaData> metaDataMap = new HashMap<MessageUid, MessageMetaData>();
         Date date = new Date();
         date.setTime(DATE.getTime() + 100L);
-        metaDataMap.put(18L, new SimpleMessageMetaData(UID, MODSEQ, new Flags(), HEADER_STRING.length() + BODY_STRING.length(), date));
+        metaDataMap.put(UID, new SimpleMessageMetaData(UID, MODSEQ, new Flags(), HEADER_STRING.length() + BODY_STRING.length(), date));
         MetadataMapAssert.assertThat(metaDataMap).containsMetadataForMessages(message1);
     }
 
     @Test(expected = AssertionError.class)
     public void metadataMapAssertShouldFailWhenSizeMismatch() {
-        Map<Long, MessageMetaData> metaDataMap = new HashMap<Long, MessageMetaData>();
-        metaDataMap.put(18L, new SimpleMessageMetaData(UID , MODSEQ, new Flags(), HEADER_STRING.length() + BODY_STRING.length() + 1, DATE));
+        Map<MessageUid, MessageMetaData> metaDataMap = new HashMap<MessageUid, MessageMetaData>();
+        metaDataMap.put(UID, new SimpleMessageMetaData(UID , MODSEQ, new Flags(), HEADER_STRING.length() + BODY_STRING.length() + 1, DATE));
         MetadataMapAssert.assertThat(metaDataMap).containsMetadataForMessages(message1);
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/34242a5b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
index daa776f..3d5b4fd 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
@@ -24,21 +24,20 @@ import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import com.google.common.collect.Lists;
+import java.util.Date;
+
+import javax.mail.Flags;
+
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
 import org.apache.james.mailbox.store.SimpleMessageMetaData;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
 
-import javax.mail.Flags;
-import java.util.Date;
-import java.util.List;
+import com.google.common.collect.Lists;
 
 public class ListeningCurrentQuotaUpdaterTest {
 
@@ -62,36 +61,11 @@ public class ListeningCurrentQuotaUpdaterTest {
     @Test
     public void addedEventShouldIncreaseCurrentQuotaValues() throws Exception {
         MailboxListener.Added added = mock(MailboxListener.Added.class);
-        when(added.getMetaData(36)).thenAnswer(new Answer<MessageMetaData>() {
-            @Override
-            public MessageMetaData answer(InvocationOnMock invocationOnMock) throws Throwable {
-                return new SimpleMessageMetaData(36,0,new Flags(), SIZE, new Date());
-            }
-        });
-        when(added.getMetaData(38)).thenAnswer(new Answer<MessageMetaData>() {
-            @Override
-            public MessageMetaData answer(InvocationOnMock invocationOnMock) throws Throwable {
-                return new SimpleMessageMetaData(38,0,new Flags(), SIZE, new Date());
-            }
-        });
-        when(added.getUids()).thenAnswer(new Answer<List<Long>>() {
-            @Override
-            public List<Long> answer(InvocationOnMock invocationOnMock) throws Throwable {
-                return Lists.newArrayList(36L, 38L);
-            }
-        });
-        when(added.getMailboxPath()).thenAnswer(new Answer<MailboxPath>() {
-            @Override
-            public MailboxPath answer(InvocationOnMock invocationOnMock) throws Throwable {
-                return MAILBOX_PATH;
-            }
-        });
-        when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenAnswer(new Answer<QuotaRoot>() {
-            @Override
-            public QuotaRoot answer(InvocationOnMock invocationOnMock) throws Throwable {
-                return QUOTA_ROOT;
-            }
-        });
+        when(added.getMetaData(MessageUid.of(36))).thenReturn(new SimpleMessageMetaData(MessageUid.of(36),0,new Flags(), SIZE, new Date()));
+        when(added.getMetaData(MessageUid.of(38))).thenReturn(new SimpleMessageMetaData(MessageUid.of(38),0,new Flags(), SIZE, new Date()));
+        when(added.getUids()).thenReturn(Lists.newArrayList(MessageUid.of(36), MessageUid.of(38)));
+        when(added.getMailboxPath()).thenReturn(MAILBOX_PATH);
+        when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenReturn(QUOTA_ROOT);
         testee.event(added);
         verify(mockedCurrentQuotaManager).increase(QUOTA_ROOT, 2, 2 * SIZE);
     }
@@ -99,60 +73,20 @@ public class ListeningCurrentQuotaUpdaterTest {
     @Test
     public void expungedEventShouldDecreaseCurrentQuotaValues() throws Exception {
         MailboxListener.Expunged expunged = mock(MailboxListener.Expunged.class);
-        when(expunged.getMetaData(36)).thenAnswer(new Answer<MessageMetaData>() {
-            @Override
-            public MessageMetaData answer(InvocationOnMock invocationOnMock) throws Throwable {
-                return new SimpleMessageMetaData(36,0,new Flags(), SIZE, new Date());
-            }
-        });
-        when(expunged.getMetaData(38)).thenAnswer(new Answer<MessageMetaData>() {
-            @Override
-            public MessageMetaData answer(InvocationOnMock invocationOnMock) throws Throwable {
-                return new SimpleMessageMetaData(38,0,new Flags(), SIZE, new Date());
-            }
-        });
-        when(expunged.getUids()).thenAnswer(new Answer<List<Long>>() {
-            @Override
-            public List<Long> answer(InvocationOnMock invocationOnMock) throws Throwable {
-                return Lists.newArrayList(36L, 38L);
-            }
-        });
-        when(expunged.getMailboxPath()).thenAnswer(new Answer<MailboxPath>() {
-            @Override
-            public MailboxPath answer(InvocationOnMock invocationOnMock) throws Throwable {
-                return MAILBOX_PATH;
-            }
-        });
-        when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenAnswer(new Answer<QuotaRoot>() {
-            @Override
-            public QuotaRoot answer(InvocationOnMock invocationOnMock) throws Throwable {
-                return QUOTA_ROOT;
-            }
-        });
+        when(expunged.getMetaData(MessageUid.of(36))).thenReturn(new SimpleMessageMetaData(MessageUid.of(36),0,new Flags(), SIZE, new Date()));
+        when(expunged.getMetaData(MessageUid.of(38))).thenReturn(new SimpleMessageMetaData(MessageUid.of(38),0,new Flags(), SIZE, new Date()));
+        when(expunged.getUids()).thenReturn(Lists.newArrayList(MessageUid.of(36), MessageUid.of(38)));
+        when(expunged.getMailboxPath()).thenReturn(MAILBOX_PATH);
+        when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenReturn(QUOTA_ROOT);
         testee.event(expunged);
         verify(mockedCurrentQuotaManager).decrease(QUOTA_ROOT, 2, 2 * SIZE);
     }
     @Test
     public void emptyExpungedEventShouldNotTriggerDecrease() throws Exception {
         MailboxListener.Expunged expunged = mock(MailboxListener.Expunged.class);
-        when(expunged.getUids()).thenAnswer(new Answer<List<Long>>() {
-            @Override
-            public List<Long> answer(InvocationOnMock invocationOnMock) throws Throwable {
-                return Lists.newArrayList();
-            }
-        });
-        when(expunged.getMailboxPath()).thenAnswer(new Answer<MailboxPath>() {
-            @Override
-            public MailboxPath answer(InvocationOnMock invocationOnMock) throws Throwable {
-                return MAILBOX_PATH;
-            }
-        });
-        when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenAnswer(new Answer<QuotaRoot>() {
-            @Override
-            public QuotaRoot answer(InvocationOnMock invocationOnMock) throws Throwable {
-                return QUOTA_ROOT;
-            }
-        });
+        when(expunged.getUids()).thenReturn(Lists.<MessageUid>newArrayList());
+        when(expunged.getMailboxPath()).thenReturn(MAILBOX_PATH);
+        when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenReturn(QUOTA_ROOT);
         testee.event(expunged);
         verify(mockedCurrentQuotaManager, never()).decrease(QUOTA_ROOT, 0, 0);
     }
@@ -160,24 +94,9 @@ public class ListeningCurrentQuotaUpdaterTest {
     @Test
     public void emptyAddedEventShouldNotTriggerDecrease() throws Exception {
         MailboxListener.Added added = mock(MailboxListener.Added.class);
-        when(added.getUids()).thenAnswer(new Answer<List<Long>>() {
-            @Override
-            public List<Long> answer(InvocationOnMock invocationOnMock) throws Throwable {
-                return Lists.newArrayList();
-            }
-        });
-        when(added.getMailboxPath()).thenAnswer(new Answer<MailboxPath>() {
-            @Override
-            public MailboxPath answer(InvocationOnMock invocationOnMock) throws Throwable {
-                return MAILBOX_PATH;
-            }
-        });
-        when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenAnswer(new Answer<QuotaRoot>() {
-            @Override
-            public QuotaRoot answer(InvocationOnMock invocationOnMock) throws Throwable {
-                return QUOTA_ROOT;
-            }
-        });
+        when(added.getUids()).thenReturn(Lists.<MessageUid>newArrayList());
+        when(added.getMailboxPath()).thenReturn(MAILBOX_PATH);
+        when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenReturn(QUOTA_ROOT);
         testee.event(added);
         verify(mockedCurrentQuotaManager, never()).increase(QUOTA_ROOT, 0, 0);
     }


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