33
33
import org .junit .jupiter .api .Test ;
34
34
35
35
import static org .awaitility .Awaitility .await ;
36
+ import static org .hamcrest .CoreMatchers .is ;
36
37
import static org .hamcrest .MatcherAssert .assertThat ;
37
38
import static org .junit .jupiter .api .Assertions .assertEquals ;
38
39
import static org .junit .jupiter .api .Assertions .assertFalse ;
43
44
public class BlockingArrayQueueTest
44
45
{
45
46
@ Test
46
- public void testWrap () throws Exception
47
+ public void testWrap ()
47
48
{
48
49
BlockingArrayQueue <String > queue = new BlockingArrayQueue <>(3 );
49
50
@@ -83,7 +84,7 @@ public void testWrap() throws Exception
83
84
}
84
85
85
86
@ Test
86
- public void testRemove () throws Exception
87
+ public void testRemove ()
87
88
{
88
89
BlockingArrayQueue <String > queue = new BlockingArrayQueue <>(3 , 3 );
89
90
@@ -105,7 +106,7 @@ public void testRemove() throws Exception
105
106
}
106
107
107
108
@ Test
108
- public void testLimit () throws Exception
109
+ public void testLimit ()
109
110
{
110
111
BlockingArrayQueue <String > queue = new BlockingArrayQueue <>(1 , 0 , 1 );
111
112
@@ -118,7 +119,7 @@ public void testLimit() throws Exception
118
119
}
119
120
120
121
@ Test
121
- public void testGrow () throws Exception
122
+ public void testGrow ()
122
123
{
123
124
BlockingArrayQueue <String > queue = new BlockingArrayQueue <>(3 , 2 );
124
125
assertEquals (3 , queue .getCapacity ());
@@ -344,7 +345,7 @@ public void testRemoveObjectFromEmptyQueue()
344
345
}
345
346
346
347
@ Test
347
- public void testRemoveObjectWithWrappedTail () throws Exception
348
+ public void testRemoveObjectWithWrappedTail ()
348
349
{
349
350
BlockingArrayQueue <String > queue = new BlockingArrayQueue <>(6 );
350
351
// Wrap the tail
@@ -366,7 +367,7 @@ public void testRemoveObjectWithWrappedTail() throws Exception
366
367
}
367
368
368
369
@ Test
369
- public void testRemoveObject () throws Exception
370
+ public void testRemoveObject ()
370
371
{
371
372
BlockingArrayQueue <String > queue = new BlockingArrayQueue <>(4 , 0 , 4 );
372
373
@@ -400,7 +401,7 @@ public void testRemoveObject() throws Exception
400
401
}
401
402
402
403
@ Test
403
- public void testRemoveWithMaxCapacityOne () throws Exception
404
+ public void testRemoveWithMaxCapacityOne ()
404
405
{
405
406
BlockingArrayQueue <String > queue = new BlockingArrayQueue <>(1 );
406
407
@@ -413,7 +414,7 @@ public void testRemoveWithMaxCapacityOne() throws Exception
413
414
}
414
415
415
416
@ Test
416
- public void testIteratorWithModification () throws Exception
417
+ public void testIteratorWithModification ()
417
418
{
418
419
BlockingArrayQueue <String > queue = new BlockingArrayQueue <>(4 , 0 , 4 );
419
420
int count = queue .getMaxCapacity () - 1 ;
@@ -435,7 +436,7 @@ public void testIteratorWithModification() throws Exception
435
436
}
436
437
437
438
@ Test
438
- public void testListIterator () throws Exception
439
+ public void testListIterator ()
439
440
{
440
441
BlockingArrayQueue <String > queue = new BlockingArrayQueue <>(4 , 0 , 4 );
441
442
String element1 = "A" ;
@@ -469,7 +470,7 @@ public void testListIterator() throws Exception
469
470
}
470
471
471
472
@ Test
472
- public void testListIteratorWithWrappedHead () throws Exception
473
+ public void testListIteratorWithWrappedHead ()
473
474
{
474
475
BlockingArrayQueue <String > queue = new BlockingArrayQueue <>(4 , 0 , 4 );
475
476
// This sequence of offers and polls wraps the head around the array
@@ -509,7 +510,7 @@ public void testListIteratorWithWrappedHead() throws Exception
509
510
}
510
511
511
512
@ Test
512
- public void testDrainTo () throws Exception
513
+ public void testDrainTo ()
513
514
{
514
515
BlockingArrayQueue <String > queue = new BlockingArrayQueue <>();
515
516
queue .add ("one" );
@@ -530,4 +531,30 @@ public void testDrainTo() throws Exception
530
531
assertThat (queue .size (), Matchers .is (0 ));
531
532
assertThat (queue , Matchers .empty ());
532
533
}
534
+
535
+ @ Test
536
+ public void testDrainToAtDefaultGrowthSize ()
537
+ {
538
+ BlockingArrayQueue <Integer > queue = new BlockingArrayQueue <>();
539
+ for (int i = 0 ; i < BlockingArrayQueue .DEFAULT_GROWTH * 2 ; i ++)
540
+ {
541
+ queue .add (i );
542
+ }
543
+
544
+ List <Integer > list = new ArrayList <>();
545
+ assertThat (queue .drainTo (list ), is (BlockingArrayQueue .DEFAULT_GROWTH * 2 ));
546
+ assertThat (list .size (), is (BlockingArrayQueue .DEFAULT_GROWTH * 2 ));
547
+ assertThat (queue .size (), is (0 ));
548
+ }
549
+
550
+ @ Test
551
+ public void testDrainToAtZeroSize ()
552
+ {
553
+ BlockingArrayQueue <Integer > queue = new BlockingArrayQueue <>();
554
+
555
+ List <Integer > list = new ArrayList <>();
556
+ assertThat (queue .drainTo (list ), is (0 ));
557
+ assertThat (list .size (), is (0 ));
558
+ assertThat (queue .size (), is (0 ));
559
+ }
533
560
}
0 commit comments