KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > mailboxmanager > wrapper > SessionMailboxWrapperTest


1 /****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one *
3  * or more contributor license agreements. See the NOTICE file *
4  * distributed with this work for additional information *
5  * regarding copyright ownership. The ASF licenses this file *
6  * to you under the Apache License, Version 2.0 (the *
7  * "License"); you may not use this file except in compliance *
8  * with the License. You may obtain a copy of the License at *
9  * *
10  * http://www.apache.org/licenses/LICENSE-2.0 *
11  * *
12  * Unless required by applicable law or agreed to in writing, *
13  * software distributed under the License is distributed on an *
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15  * KIND, either express or implied. See the License for the *
16  * specific language governing permissions and limitations *
17  * under the License. *
18  ****************************************************************/

19
20 package org.apache.james.mailboxmanager.wrapper;
21
22 import org.apache.james.mailboxmanager.GeneralMessageSet;
23 import org.apache.james.mailboxmanager.MailboxManagerException;
24 import org.apache.james.mailboxmanager.MessageResult;
25 import org.apache.james.mailboxmanager.impl.MessageResultImpl;
26 import org.apache.james.mailboxmanager.mailbox.GeneralMailbox;
27 import org.jmock.Mock;
28 import org.jmock.MockObjectTestCase;
29 import org.jmock.core.Constraint;
30 import org.jmock.core.constraint.IsEqual;
31 import org.jmock.core.constraint.IsInstanceOf;
32 import org.jmock.core.constraint.IsSame;
33
34 public class SessionMailboxWrapperTest extends MockObjectTestCase {
35
36     public void testAddsAndRemovesListener() throws MailboxManagerException {
37         
38         SessionMailboxWrapper sessionMailboxWrapper = new SessionMailboxWrapper();
39         
40         Mock generalMailboxMock = mock(GeneralMailbox.class);
41         Constraint[] listenerArgs={new IsSame(sessionMailboxWrapper.getListenerObject()),new IsEqual(new Integer JavaDoc(MessageResult.UID))};
42
43         generalMailboxMock.expects(once()).method("addListener").with(listenerArgs);
44         
45         Constraint[] getMessagesArgs={new IsInstanceOf(GeneralMessageSet.class),new IsInstanceOf(Integer JavaDoc.class)};
46         
47         MessageResult[] result={new MessageResultImpl()};
48         
49         generalMailboxMock.expects(once()).method("getMessages").with(getMessagesArgs).after("addListener").will(returnValue(result));
50         generalMailboxMock.expects(once()).method("removeListener").with(listenerArgs[0]).after("getMessages");
51         
52         sessionMailboxWrapper.setMailbox((GeneralMailbox) generalMailboxMock
53                 .proxy());
54         sessionMailboxWrapper.init();
55         sessionMailboxWrapper.close();
56     }
57
58 }
59
Popular Tags