KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > queue > RWLockEventQueueDecoratorTest


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21
22 package org.jacorb.test.notification.queue;
23
24 import junit.framework.Test;
25 import junit.framework.TestCase;
26 import junit.framework.TestSuite;
27
28 import org.easymock.MockControl;
29 import org.jacorb.notification.interfaces.Message;
30 import org.jacorb.notification.queue.MessageQueueAdapter;
31 import org.jacorb.notification.queue.RWLockEventQueueDecorator;
32
33 public class RWLockEventQueueDecoratorTest extends TestCase
34 {
35     private RWLockEventQueueDecorator objectUnderTest_;
36
37     private MockControl controlInitialQueue_;
38
39     private MessageQueueAdapter mockInitialQueue_;
40
41     private MockControl controlReplacementQueue_;
42
43     private MessageQueueAdapter mockReplacementQueue_;
44
45     public RWLockEventQueueDecoratorTest(String JavaDoc name)
46     {
47         super(name);
48     }
49
50     protected void setUp() throws Exception JavaDoc
51     {
52         super.setUp();
53
54         controlInitialQueue_ = MockControl.createControl(MessageQueueAdapter.class);
55         mockInitialQueue_ = (MessageQueueAdapter) controlInitialQueue_.getMock();
56         objectUnderTest_ = new RWLockEventQueueDecorator(mockInitialQueue_);
57
58         controlReplacementQueue_ = MockControl.createControl(MessageQueueAdapter.class);
59         mockReplacementQueue_ = (MessageQueueAdapter) controlReplacementQueue_.getMock();
60     }
61
62     public void testReplaceEmpty() throws Exception JavaDoc
63     {
64         mockInitialQueue_.hasPendingMessages();
65         controlInitialQueue_.setReturnValue(false);
66         controlInitialQueue_.replay();
67         controlReplacementQueue_.replay();
68
69         objectUnderTest_.replaceDelegate(mockReplacementQueue_);
70     }
71
72     public void testReplaceNonEmpty() throws Exception JavaDoc
73     {
74         MockControl controlMessage = MockControl.createControl(Message.class);
75         Message mockMessage = (Message) controlMessage.getMock();
76         Message[] mesgs = new Message[] { mockMessage };
77
78         mockInitialQueue_.hasPendingMessages();
79         controlInitialQueue_.setReturnValue(true);
80
81         mockInitialQueue_.getAllMessages();
82         controlInitialQueue_.setReturnValue(mesgs);
83         
84         controlInitialQueue_.replay();
85         
86         mockReplacementQueue_.enqeue(mockMessage);
87         
88         controlReplacementQueue_.replay();
89         
90         objectUnderTest_.replaceDelegate(mockReplacementQueue_);
91     }
92     
93     public static Test suite() throws Exception JavaDoc
94     {
95         return new TestSuite(RWLockEventQueueDecoratorTest.class);
96     }
97 }
98
Popular Tags