How to use method of org.jmock.test.unit.lib.concurrent.internal.DeltaQueueTests class

Best Jmock-library code snippet using org.jmock.test.unit.lib.concurrent.internal.DeltaQueueTests.

Run Jmock-library automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1package org.jmock.test.unit.lib.concurrent.internal;
2
3import org.jmock.lib.concurrent.internal.DeltaQueue;
4
5import junit.framework.TestCase;
6
7
8public class DeltaQueueTests extends TestCase {
9    DeltaQueue<String> deltaQueue = new DeltaQueue<String>();
10    
11    String elementA = "a";
12    String elementB = "b";
13    String elementC = "c";
14    
15    
16    public void testIsCreatedEmpty() {
17        assertTrue("is empty", deltaQueue.isEmpty());
18    }
19    
20    public void testCanScheduleAnElement() {
21        final long delay = 10L;
22        
23        deltaQueue.add(delay, elementA);
24        
25        assertTrue("is not empty", !deltaQueue.isEmpty());
26        
27        assertSame("next", elementA, deltaQueue.next());
28        assertEquals("delay", delay, deltaQueue.delay());
29    }
30    
31    public void testTicksDownTimeUntilScheduledElement() {
32        deltaQueue.add(10L, elementA);
33        
34        assertEquals(0L, deltaQueue.tick(1L));
35        
36        assertSame("next", elementA, deltaQueue.next());
37        assertEquals("delay", 9L, deltaQueue.delay());
38        
39        assertEquals(0L, deltaQueue.tick(4L));
40        assertSame("next", elementA, deltaQueue.next());
41        assertEquals("delay", 5L, deltaQueue.delay());
42        
43        assertEquals(0L, deltaQueue.tick(4L));
44        assertSame("next", elementA, deltaQueue.next());
45        assertEquals("delay", 1L, deltaQueue.delay());
46
47        assertEquals(0L, deltaQueue.tick(1L));
48        assertSame("next", elementA, deltaQueue.next());
49        assertEquals("delay", 0L, deltaQueue.delay());
50    }
51    
52    public void testReturnsTimeAfterElementIfTickGreaterThanDelay() {
53        deltaQueue.add(10L, elementA);
54        
55        assertEquals(5L, deltaQueue.tick(15L));
56        assertSame("next", elementA, deltaQueue.next());
57        assertEquals("delay", 0L, deltaQueue.delay());
58    }
59    
60    public void testCanPopElementWhenDelayIsZero() {
61        deltaQueue.add(10L, elementA);
62        
63        deltaQueue.tick(10L);
64        assertSame("popped", elementA, deltaQueue.pop());
65        assertTrue("is empty", deltaQueue.isEmpty());
66    }
67    
68    public void testCanScheduleMultipleElementsInAnyOrder() {
69        deltaQueue.add(10L, elementB);
70        deltaQueue.add(5L, elementA);
71        deltaQueue.add(12L, elementC);
72        
73        assertSame("next", elementA, deltaQueue.next());
74        assertEquals("delay", 5L, deltaQueue.delay());
75        
76        deltaQueue.tick(5L);
77        assertSame("popped A", elementA, deltaQueue.pop());
78        
79        assertSame("next", elementB, deltaQueue.next());
80        assertEquals("delay", 5L, deltaQueue.delay());
81        
82        deltaQueue.tick(5L);
83        assertSame("popped B", elementB, deltaQueue.pop());
84        
85        assertSame("next", elementC, deltaQueue.next());
86        assertEquals("delay", 2L, deltaQueue.delay());
87        
88        deltaQueue.tick(2L);
89        assertSame("popped C", elementC, deltaQueue.pop());
90        
91        assertTrue("is empty", deltaQueue.isEmpty());
92    }
93    
94    public void testReportsScheduleAsString() {
95        deltaQueue.add(10L, elementB);
96        deltaQueue.add(5L, elementA);
97        deltaQueue.add(12L, elementC);
98        
99        assertEquals("DeltaQueue[+5: a, +5: b, +2: c]", deltaQueue.toString());
100    }
101    
102    public void testTickingDownAnEmptyDeltaQueueDoesNothingButConsumesAllOfTheTickedTime() {
103        assertEquals(0L, deltaQueue.tick(1L));
104        assertEquals(0L, deltaQueue.tick(2L));
105        assertEquals(0L, deltaQueue.tick(19L));
106    }
107    
108    public void testElementsScheduledWithSameDelayAreExecutedInTheOrderThatTheyWereScheduled() {
109        deltaQueue.add(1L, elementA);
110        deltaQueue.add(1L, elementB);
111        deltaQueue.add(1L, elementC);
112        
113        deltaQueue.tick(1L);
114        
115        assertSame(elementA, deltaQueue.pop());
116        assertSame(elementB, deltaQueue.pop());
117        assertSame(elementC, deltaQueue.pop());
118    }
119    
120    public void testCanRemoveScheduledElements() {
121        deltaQueue.add(1L, elementA);
122        deltaQueue.add(2L, elementB);
123        deltaQueue.add(3L, elementC);
124        
125        assertTrue(deltaQueue.remove(elementB));
126        
127        deltaQueue.tick(1L);
128        assertSame(elementA, deltaQueue.pop());
129        
130        deltaQueue.tick(2L);
131        assertSame(elementC, deltaQueue.pop());
132    }
133    
134    public void testCanRemoveHead() {
135        deltaQueue.add(1L, elementA);
136        deltaQueue.add(2L, elementB);
137        deltaQueue.add(3L, elementC);
138        
139        deltaQueue.remove(elementA);
140        
141        deltaQueue.tick(2L);
142        assertSame(elementB, deltaQueue.pop());
143        
144        deltaQueue.tick(1L);
145        assertSame(elementC, deltaQueue.pop());
146    }
147    
148    public void testCanRemoveTail() {
149        deltaQueue.add(1L, elementA);
150        deltaQueue.add(2L, elementB);
151        deltaQueue.add(3L, elementC);
152       
153        deltaQueue.remove(elementC);
154        
155        deltaQueue.tick(1L);
156        assertSame(elementA, deltaQueue.pop());
157        
158        deltaQueue.tick(1L);
159        assertSame(elementB, deltaQueue.pop());
160        
161        assertTrue("is empty", deltaQueue.isEmpty());
162    }
163    
164    public void testReturnsFalseIfElementAlreadyRemoved() {
165        deltaQueue.add(1L, elementA);
166        deltaQueue.add(2L, elementB);
167        
168        assertFalse(deltaQueue.remove(elementC));
169    }
170}
171
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)