james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r595928 - in /james/server/trunk/core-library/src: main/java/org/apache/james/mailboxmanager/ main/java/org/apache/james/mailboxmanager/impl/ test/java/org/apache/james/mailboxmanager/
Date Sat, 17 Nov 2007 09:45:58 GMT
Author: rdonkin
Date: Sat Nov 17 01:45:57 2007
New Revision: 595928

URL: http://svn.apache.org/viewvc?rev=595928&view=rev
Log:
Implemented MessageResultImpl#getIncludedResults. The included results will be automatically
added as data is. This means that the result will accurately reflect the data included in
the result but will only match the results requested when the backend has been implemented
fully.

Added:
    james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultImplIncludedResultsTest.java
    james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultUtilsIsIncludedTest.java
Modified:
    james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/MessageResult.java
    james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/MessageResultUtils.java
    james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/MessageResult.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/MessageResult.java?rev=595928&r1=595927&r2=595928&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/MessageResult.java
(original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/MessageResult.java
Sat Nov 17 01:45:57 2007
@@ -98,9 +98,12 @@
     
     public static final int BODY_CONTENT = 0x400;
     
+    /**
+     * Gets the results set.
+     * @return bitwise indication of result set
+     * @see {@link MessageResultUtils#isIncluded(MessageResult, int)}
+     */
     int getIncludedResults();
-
-    boolean contains(int result);
 
     MimeMessage getMimeMessage();
 

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/MessageResultUtils.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/MessageResultUtils.java?rev=595928&r1=595927&r2=595928&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/MessageResultUtils.java
(original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/MessageResultUtils.java
Sat Nov 17 01:45:57 2007
@@ -105,4 +105,146 @@
         }
         return results;
     }
+    
+    /**
+     * Is the given datum included in these results?
+     * @param result <code>MessageResult</code>, possibly null
+     * @param datum {@link MessageResult} datum constant
+     * @return true if <code>MessageResult</code> includes 
+     * the given datum, false if <code>MessageResult</code> is null
+     * or does not contain this datum
+     */
+    public static boolean isIncluded(final MessageResult message, final int datum) {
+        final boolean result;
+        if (message == null) {
+            result = false;
+        } else if (datum == MessageResult.NOTHING) {
+            result = true;
+        } else {
+            final int includes = message.getIncludedResults();
+            result = (includes & datum) == datum;
+        }
+        return result;
+    }
+    
+    /**
+     * Is {@link MessageResult#BODY_CONTENT} included in these results?
+     * @param result <code>MessageResult</code>, possibly null
+     * @return true if <code>MessageResult</code> includes 
+     * BODY_CONTENT, false if <code>MessageResult</code> is null
+     * or does not contain BODY_CONTENT
+     * @see {@link #isIncluded(MessageResult, int)}
+     */
+    public static boolean isBodyContentIncluded(final MessageResult message) {
+        return isIncluded(message, MessageResult.BODY_CONTENT);
+    }
+    
+    /**
+     * Is {@link MessageResult#FLAGS} included in these results?
+     * @param result <code>MessageResult</code>, possibly null
+     * @return true if <code>MessageResult</code> includes 
+     * FLAGS, false if <code>MessageResult</code> is null
+     * or does not contain FLAGS
+     * @see {@link #isIncluded(MessageResult, int)}
+     */
+    public static boolean isFlagsIncluded(final MessageResult message) {
+        return isIncluded(message, MessageResult.FLAGS);
+    }
+    
+    /**
+     * Is {@link MessageResult#FULL_CONTENT} included in these results?
+     * @param result <code>MessageResult</code>, possibly null
+     * @return true if <code>MessageResult</code> includes 
+     * FULL_CONTENT, false if <code>MessageResult</code> is null
+     * or does not contain FULL_CONTENT
+     * @see {@link #isIncluded(MessageResult, int)}
+     */
+    public static boolean isFullContentIncluded(final MessageResult message) {
+        return isIncluded(message, MessageResult.FULL_CONTENT);
+    }
+    
+    /**
+     * Is {@link MessageResult#HEADERS} included in these results?
+     * @param result <code>MessageResult</code>, possibly null
+     * @return true if <code>MessageResult</code> includes 
+     * HEADERS, false if <code>MessageResult</code> is null
+     * or does not contain HEADERS
+     * @see {@link #isIncluded(MessageResult, int)}
+     */
+    public static boolean isHeadersIncluded(final MessageResult message) {
+        return isIncluded(message, MessageResult.HEADERS);
+    }
+    
+    /**
+     * Is {@link MessageResult#KEY} included in these results?
+     * @param result <code>MessageResult</code>, possibly null
+     * @return true if <code>MessageResult</code> includes 
+     * KEY, false if <code>MessageResult</code> is null
+     * or does not contain KEY
+     * @see {@link #isIncluded(MessageResult, int)}
+     */
+    public static boolean isKeyIncluded(final MessageResult message) {
+        return isIncluded(message, MessageResult.KEY);
+    }
+    
+    /**
+     * Is {@link MessageResult#INTERNAL_DATE} included in these results?
+     * @param result <code>MessageResult</code>, possibly null
+     * @return true if <code>MessageResult</code> includes 
+     * INTERNAL_DATE, false if <code>MessageResult</code> is null
+     * or does not contain INTERNAL_DATE
+     * @see {@link #isIncluded(MessageResult, int)}
+     */
+    public static boolean isInternalDateIncluded(final MessageResult message) {
+        return isIncluded(message, MessageResult.INTERNAL_DATE);
+    }
+    
+    /**
+     * Is {@link MessageResult#MIME_MESSAGE} included in these results?
+     * @param result <code>MessageResult</code>, possibly null
+     * @return true if <code>MessageResult</code> includes 
+     * MIME_MESSAGE, false if <code>MessageResult</code> is null
+     * or does not contain MIME_MESSAGE
+     * @see {@link #isIncluded(MessageResult, int)}
+     */
+    public static boolean isMimeMessageIncluded(final MessageResult message) {
+        return isIncluded(message, MessageResult.MIME_MESSAGE);
+    }   
+    
+    /**
+     * Is {@link MessageResult#SIZE} included in these results?
+     * @param result <code>MessageResult</code>, possibly null
+     * @return true if <code>MessageResult</code> includes 
+     * SIZE, false if <code>MessageResult</code> is null
+     * or does not contain SIZE
+     * @see {@link #isIncluded(MessageResult, int)}
+     */
+    public static boolean isSizeIncluded(final MessageResult message) {
+        return isIncluded(message, MessageResult.SIZE);
+    }
+    
+    
+    /**
+     * Is {@link MessageResult#UID} included in these results?
+     * @param result <code>MessageResult</code>, possibly null
+     * @return true if <code>MessageResult</code> includes 
+     * UID, false if <code>MessageResult</code> is null
+     * or does not contain UID
+     * @see {@link #isIncluded(MessageResult, int)}
+     */
+    public static boolean isUidIncluded(final MessageResult message) {
+        return isIncluded(message, MessageResult.UID);
+    }
+    
+    /**
+     * Is {@link MessageResult#MSN} included in these results?
+     * @param result <code>MessageResult</code>, possibly null
+     * @return true if <code>MessageResult</code> includes 
+     * MSN, false if <code>MessageResult</code> is null
+     * or does not contain MSN
+     * @see {@link #isIncluded(MessageResult, int)}
+     */
+    public static boolean isMsnIncluded(final MessageResult message) {
+        return isIncluded(message, MessageResult.MSN);
+    }
 }

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java?rev=595928&r1=595927&r2=595928&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java
(original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java
Sat Nov 17 01:45:57 2007
@@ -27,9 +27,15 @@
 import javax.mail.Flags.Flag;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.commons.collections.IteratorUtils;
 import org.apache.james.mailboxmanager.MessageResult;
+import org.apache.james.mailboxmanager.MessageResultUtils;
 import org.apache.mailet.Mail;
 
+/**
+ * Bean based implementation.
+ * {@link #getIncludedResults()} is updated when setters are called.
+ */
 public class MessageResultImpl implements MessageResult {
     
     private MimeMessage mimeMessage;
@@ -42,34 +48,55 @@
     private List headers;
     private Content messageBody;
     private Content fullMessage;
-    
+    private int includedResults = NOTHING;
 
     public MessageResultImpl(long uid) {
-        this.uid=uid;
+        setUid(uid);
     }
 
     public MessageResultImpl() {
     }
 
     public MessageResultImpl(long uid, Flags flags) {
-        this.uid=uid;
-        this.flags=flags;
+        setUid(uid);
+        setFlags(flags);
     }
 
-    public MessageResultImpl(MessageResult origMr) {
-        this.uid=origMr.getUid();
-        this.flags=origMr.getFlags();
-        this.mimeMessage=origMr.getMimeMessage();
+    public MessageResultImpl(MessageResult result) {
+        if (MessageResultUtils.isUidIncluded(result)) {
+            setUid(result.getUid()); 
+        }
+        if (MessageResultUtils.isFlagsIncluded(result)) {
+            setFlags(result.getFlags());
+        }
+        if (MessageResultUtils.isMimeMessageIncluded(result)) {
+            setMimeMessage(result.getMimeMessage());
+        }
+        if (MessageResultUtils.isMsnIncluded(result)) {
+            setMsn(result.getMsn());
+        }
+        if (MessageResultUtils.isSizeIncluded(result)) {
+            setSize(result.getSize());
+        }
+        if (MessageResultUtils.isInternalDateIncluded(result)) {
+            setInternalDate(result.getInternalDate());
+        }
+        if (MessageResultUtils.isKeyIncluded(result)) {
+            setKey(result.getKey());
+        }
+        if (MessageResultUtils.isHeadersIncluded(result)) {
+            setHeaders(IteratorUtils.toList(result.iterateHeaders()));
+        }
+        if (MessageResultUtils.isFullContentIncluded(result)) {
+            setFullMessage(result.getFullMessage());
+        }
+        if (MessageResultUtils.isBodyContentIncluded(result)) {
+            setMessageBody(result.getMessageBody());
+        }
     }
 
     public int getIncludedResults() {
-        // TODO Auto-generated method stub
-        return 0;
-    }
-
-    public boolean contains(int result) {
-        // TODO Auto-generated method stub
-        return false;
+        return includedResults;
     }
 
     public MimeMessage getMimeMessage() {
@@ -78,15 +105,17 @@
 
     public void setMimeMessage(MimeMessage mimeMessage) {
         this.mimeMessage=mimeMessage;
+        if (mimeMessage != null) {
+            includedResults |= MIME_MESSAGE;
+        }
     }
-
     
     public long getUid() {
         return uid;
     }
 
     public long getUidValidity() {
-        // TODO Auto-generated method stub
+        // TODO implement or remove
         return 0;
     }
 
@@ -103,7 +132,7 @@
     }
 
     public Mail getMail() {
-        // TODO Auto-generated method stub
+        // TODO implement or remove
         return null;
     }
 
@@ -113,9 +142,12 @@
 
     public void setUid(long uid) {
         this.uid=uid;
+        includedResults |= UID;
+        
     }
     public void setMsn(int msn) {
         this.msn=msn;
+        includedResults |= MSN;
     }
     public int getSize() {
         return size;
@@ -123,13 +155,21 @@
 
     public void setFlags(Flags flags) {
         this.flags=flags;
+        if (flags != null) {
+            includedResults |= FLAGS;
+        }
     }
 
     public int compareTo(Object o) {
         MessageResult that=(MessageResult)o;
         if (this.uid>0 && that.getUid()>0) {
+            // TODO: this seems inefficient
             return new Long(uid).compareTo(new Long(that.getUid()));    
         } else {
+            // TODO: throwing an undocumented untyped runtime seems wrong
+            // TODO: if uids must be greater than zero then this should be enforced
+            // TODO: on the way in
+            // TODO: probably an IllegalArgumentException would be better
             throw new RuntimeException("can't compare");
         }
         
@@ -137,10 +177,14 @@
 
     public void setSize(int size) {
         this.size=size;
+        includedResults = SIZE;
     }
 
     public void setInternalDate(Date internalDate) {
         this.internalDate = internalDate;
+        if (internalDate != null) {
+            includedResults |= INTERNAL_DATE;
+        }
     }
     
     public String toString() {
@@ -187,6 +231,9 @@
 
     public void setKey(String key) {
         this.key=key;
+        if (key != null) {
+            includedResults |= KEY;
+        }
     }
 
     public Iterator iterateHeaders() {
@@ -199,6 +246,9 @@
 
     public void setHeaders(List headers) {
         this.headers = headers;
+        if (headers != null) {
+            includedResults |= HEADERS;
+        }
     }
 
     public final Content getFullMessage() {
@@ -207,6 +257,9 @@
 
     public final void setFullMessage(Content fullMessage) {
         this.fullMessage = fullMessage;
+        if (fullMessage != null) {
+            includedResults |= FULL_CONTENT;
+        }
     }
 
     public final Content getMessageBody() {
@@ -215,5 +268,8 @@
 
     public final void setMessageBody(Content messageBody) {
         this.messageBody = messageBody;
+        if (messageBody != null) {
+            includedResults |= BODY_CONTENT;
+        }
     }
 }

Added: james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultImplIncludedResultsTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultImplIncludedResultsTest.java?rev=595928&view=auto
==============================================================================
--- james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultImplIncludedResultsTest.java
(added)
+++ james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultImplIncludedResultsTest.java
Sat Nov 17 01:45:57 2007
@@ -0,0 +1,143 @@
+/****************************************************************
+ * 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.mailboxmanager;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Properties;
+
+import javax.mail.Flags;
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.james.mailboxmanager.MessageResult;
+import org.apache.james.mailboxmanager.impl.MessageResultImpl;
+import org.jmock.MockObjectTestCase;
+
+import junit.framework.TestCase;
+
+public class MessageResultImplIncludedResultsTest extends MockObjectTestCase {
+
+    MessageResultImpl result;
+    MessageResult.Content content;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        result = new MessageResultImpl();
+        content = (MessageResult.Content) mock(MessageResult.Content.class).proxy();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+    
+    public void testShouldIncludedResultsWhenMimeMessageSet() {
+        MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()));
+        result.setMimeMessage(null);
+        assertEquals(MessageResult.NOTHING, result.getIncludedResults());
+        result.setMimeMessage(message);
+        assertEquals(MessageResult.MIME_MESSAGE, result.getIncludedResults());
+        MessageResultImpl result = new MessageResultImpl(this.result);
+        assertEquals(MessageResult.MIME_MESSAGE, result.getIncludedResults());
+    }
+
+    public void testShouldIncludedResultsWhenUidSet() {
+        result.setUid(100);
+        assertEquals(MessageResult.UID, result.getIncludedResults());
+        MessageResultImpl result = new MessageResultImpl(77);
+        assertEquals(MessageResult.UID, result.getIncludedResults());
+        result = new MessageResultImpl(77, null);
+        assertEquals(MessageResult.UID, result.getIncludedResults());
+        result = new MessageResultImpl(result);
+        assertEquals(MessageResult.UID, result.getIncludedResults());
+    }
+
+    public void testShouldIncludedResultsWhenMsnSet() {
+        result.setMsn(100);
+        assertEquals(MessageResult.MSN, result.getIncludedResults());
+        MessageResultImpl result = new MessageResultImpl(this.result);
+        assertEquals(MessageResult.MSN, result.getIncludedResults());
+    }
+
+    public void testShouldIncludedResultsWhenFlagsSet() {
+        result.setFlags(null);
+        assertEquals(MessageResult.NOTHING, result.getIncludedResults());
+        Flags flags = new Flags();
+        result.setFlags(flags);
+        assertEquals(MessageResult.FLAGS, result.getIncludedResults());
+        MessageResultImpl result = new MessageResultImpl(77, flags);
+        assertEquals(MessageResult.UID | MessageResult.FLAGS, result.getIncludedResults());
+        result = new MessageResultImpl(this.result);
+        assertEquals(MessageResult.FLAGS, result.getIncludedResults());
+    }
+
+    public void testShouldIncludedResultsWhenSizeSet() {
+        result.setSize(100);
+        assertEquals(MessageResult.SIZE, result.getIncludedResults());
+        MessageResultImpl result = new MessageResultImpl(this.result);
+        assertEquals(MessageResult.SIZE, result.getIncludedResults());
+    }
+
+    public void testShouldIncludedResultsWhenInternalDateSet() {
+        result.setInternalDate(null);
+        assertEquals(MessageResult.NOTHING, result.getIncludedResults());
+        Date date = new Date();
+        result.setInternalDate(date);
+        assertEquals(MessageResult.INTERNAL_DATE, result.getIncludedResults());
+        result = new MessageResultImpl(this.result);
+        assertEquals(MessageResult.INTERNAL_DATE, result.getIncludedResults());
+    }
+
+    public void testShouldIncludedResultsWhenKeySet() {
+        result.setKey(null);
+        assertEquals(MessageResult.NOTHING, result.getIncludedResults());
+        result.setKey("KEY");
+        assertEquals(MessageResult.KEY, result.getIncludedResults());
+        result = new MessageResultImpl(this.result);
+        assertEquals(MessageResult.KEY, result.getIncludedResults());
+    }
+
+    public void testShouldIncludedResultsWhenHeadersSet() {
+        result.setHeaders(null);
+        assertEquals(MessageResult.NOTHING, result.getIncludedResults());
+        result.setHeaders(new ArrayList());
+        assertEquals(MessageResult.HEADERS, result.getIncludedResults());
+        result = new MessageResultImpl(this.result);
+        assertEquals(MessageResult.HEADERS, result.getIncludedResults());
+    }
+    
+    public void testShouldIncludedResultsWhenFullMessageSet() {
+        result.setFullMessage(null);
+        assertEquals(MessageResult.NOTHING, result.getIncludedResults());
+        result.setFullMessage(content);
+        assertEquals(MessageResult.FULL_CONTENT, result.getIncludedResults());
+        result = new MessageResultImpl(this.result);
+        assertEquals(MessageResult.FULL_CONTENT, result.getIncludedResults());
+    }
+
+    public void testShouldIncludedResultsWhenMessageBodySet() {
+        result.setMessageBody(null);
+        assertEquals(MessageResult.NOTHING, result.getIncludedResults());
+        result.setMessageBody(content);
+        assertEquals(MessageResult.BODY_CONTENT, result.getIncludedResults());
+        result = new MessageResultImpl(this.result);
+        assertEquals(MessageResult.BODY_CONTENT, result.getIncludedResults());
+    }
+}

Added: james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultUtilsIsIncludedTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultUtilsIsIncludedTest.java?rev=595928&view=auto
==============================================================================
--- james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultUtilsIsIncludedTest.java
(added)
+++ james/server/trunk/core-library/src/test/java/org/apache/james/mailboxmanager/MessageResultUtilsIsIncludedTest.java
Sat Nov 17 01:45:57 2007
@@ -0,0 +1,120 @@
+/****************************************************************
+ * 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.mailboxmanager;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.mail.MessagingException;
+
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+
+import junit.framework.TestCase;
+
+public class MessageResultUtilsIsIncludedTest extends MockObjectTestCase {
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testShouldReturnFalseWhenNull() throws Exception {
+        assertFalse(MessageResultUtils.isIncluded(null, MessageResult.FLAGS));
+    }
+   
+    public void testBodyContentIncluded() throws Exception {
+        assertFalse(MessageResultUtils.isIncluded(mock(MessageResult.NOTHING), MessageResult.BODY_CONTENT));
+        assertFalse(MessageResultUtils.isIncluded(mock(MessageResult.FLAGS), MessageResult.BODY_CONTENT));
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.BODY_CONTENT), MessageResult.BODY_CONTENT));
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.MSN | MessageResult.BODY_CONTENT),
MessageResult.BODY_CONTENT));
+    }
+   
+    public void testMsnIncluded() throws Exception {
+        assertFalse(MessageResultUtils.isIncluded(mock(MessageResult.NOTHING), MessageResult.MSN));
+        assertFalse(MessageResultUtils.isIncluded(mock(MessageResult.FLAGS), MessageResult.MSN));
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.MSN), MessageResult.MSN));
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.MSN | MessageResult.BODY_CONTENT),
MessageResult.MSN));
+    }
+    
+    public void testFlagsIncluded() throws Exception {
+        assertFalse(MessageResultUtils.isIncluded(mock(MessageResult.NOTHING), MessageResult.FLAGS));
+        assertFalse(MessageResultUtils.isIncluded(mock(MessageResult.BODY_CONTENT), MessageResult.FLAGS));
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.FLAGS), MessageResult.FLAGS));
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.FLAGS | MessageResult.BODY_CONTENT),
MessageResult.FLAGS));
+    }
+    
+    public void testFULL_CONTENTIncluded() throws Exception {
+        assertFalse(MessageResultUtils.isIncluded(mock(MessageResult.NOTHING), MessageResult.FULL_CONTENT));
+        assertFalse(MessageResultUtils.isIncluded(mock(MessageResult.BODY_CONTENT), MessageResult.FULL_CONTENT));
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.FULL_CONTENT), MessageResult.FULL_CONTENT));
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.FLAGS | MessageResult.FULL_CONTENT),
MessageResult.FULL_CONTENT));
+    }
+    
+    public void testHEADERSIncluded() throws Exception {
+        assertFalse(MessageResultUtils.isIncluded(mock(MessageResult.NOTHING), MessageResult.HEADERS));
+        assertFalse(MessageResultUtils.isIncluded(mock(MessageResult.BODY_CONTENT), MessageResult.HEADERS));
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.HEADERS), MessageResult.HEADERS));
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.FLAGS | MessageResult.HEADERS),
MessageResult.HEADERS));
+    }
+    
+    public void testINTERNAL_DATEIncluded() throws Exception {
+        assertFalse(MessageResultUtils.isIncluded(mock(MessageResult.NOTHING), MessageResult.INTERNAL_DATE));
+        assertFalse(MessageResultUtils.isIncluded(mock(MessageResult.BODY_CONTENT), MessageResult.INTERNAL_DATE));
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.INTERNAL_DATE), MessageResult.INTERNAL_DATE));
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.FLAGS | MessageResult.INTERNAL_DATE),
MessageResult.INTERNAL_DATE));
+    }
+    
+    public void testMIME_MESSAGEIncluded() throws Exception {
+        assertFalse(MessageResultUtils.isIncluded(mock(MessageResult.NOTHING), MessageResult.MIME_MESSAGE));
+        assertFalse(MessageResultUtils.isIncluded(mock(MessageResult.BODY_CONTENT), MessageResult.MIME_MESSAGE));
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.MIME_MESSAGE), MessageResult.MIME_MESSAGE));
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.FLAGS | MessageResult.MIME_MESSAGE),
MessageResult.MIME_MESSAGE));
+    }
+    
+    public void testShouldNOTHINGAlwaysBeIncluded() throws Exception {
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.NOTHING, false), MessageResult.NOTHING));
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.BODY_CONTENT, false),
MessageResult.NOTHING));
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.INTERNAL_DATE, false),
MessageResult.NOTHING));
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.FLAGS | MessageResult.MIME_MESSAGE,
false), MessageResult.NOTHING));
+    }
+    
+    public void testMultipleData() throws Exception {
+        assertFalse(MessageResultUtils.isIncluded(mock(MessageResult.NOTHING), MessageResult.MIME_MESSAGE
| MessageResult.FLAGS));
+        assertFalse(MessageResultUtils.isIncluded(mock(MessageResult.BODY_CONTENT), MessageResult.MIME_MESSAGE
| MessageResult.FLAGS));
+        assertFalse(MessageResultUtils.isIncluded(mock(MessageResult.MIME_MESSAGE), MessageResult.MIME_MESSAGE
| MessageResult.FLAGS));
+        assertTrue(MessageResultUtils.isIncluded(mock(MessageResult.FLAGS | MessageResult.MIME_MESSAGE),
MessageResult.MIME_MESSAGE | MessageResult.FLAGS));
+    }
+    
+    private MessageResult mock(int included) {
+        return mock(included, true);
+    }
+    
+    private MessageResult mock(int included, boolean willBeCalled) {
+        Mock result = mock(MessageResult.class);
+        if (willBeCalled) {
+            result.expects(once()).method("getIncludedResults").will(returnValue(included));
+        }
+        return (MessageResult) result.proxy();
+    }
+}



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