1 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 name) 46 { 47 super(name); 48 } 49 50 protected void setUp() throws Exception 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 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 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 94 { 95 return new TestSuite(RWLockEventQueueDecoratorTest.class); 96 } 97 } 98 | Popular Tags |