@@ -19,9 +19,9 @@ public void addNGet() {
19
19
CustomArrayList <Integer > list = new CustomArrayList <>();
20
20
assertThat (list .size ()).isEqualTo (0 );
21
21
assertTrue (list .isEmpty ());
22
- list .add (4 );
23
- list .add (5 );
24
- list .add (12 );
22
+ assertTrue ( list .add (4 ) );
23
+ assertTrue ( list .add (5 ) );
24
+ assertTrue ( list .add (12 ) );
25
25
26
26
assertThat (list .size ()).isEqualTo (3 );
27
27
assertFalse (list .isEmpty ());
@@ -329,4 +329,133 @@ public void testToString() {
329
329
330
330
assertThat (list .toString ()).isEqualTo ("[Andrei, Tikhon, Ilya]" );
331
331
}
332
+
333
+ @ Test
334
+ public void testContains () {
335
+ CustomArrayList <String > list = new CustomArrayList <>();
336
+ list .add ("Andrei" );
337
+ list .add ("Tikhon" );
338
+ list .add ("Ilya" );
339
+
340
+ assertThat (list .contains ("Tikhon" )).isTrue ();
341
+ assertThat (list .contains ("Andrei" )).isTrue ();
342
+ assertThat (list .contains ("Isaac" )).isFalse ();
343
+ }
344
+
345
+ @ Test
346
+ public void testContainsAll () {
347
+ CustomArrayList <String > list = new CustomArrayList <>();
348
+ list .add ("Andrei" );
349
+ list .add ("Tikhon" );
350
+ list .add ("Ilya" );
351
+
352
+ assertThat (list .containsAll (List .of ())).isTrue ();
353
+ assertThat (list .containsAll (List .of ("Ilya" , "Tikhon" ))).isTrue ();
354
+ assertThat (list .containsAll (List .of ("Ilya" , "Pavel" ))).isFalse ();
355
+ }
356
+
357
+ @ Test
358
+ public void testAddAllNoResize () {
359
+ CustomArrayList <String > list = new CustomArrayList <>();
360
+ list .add ("Andrei" );
361
+ list .add ("Tikhon" );
362
+ list .add ("Ilya" );
363
+
364
+ list .addAll (List .of ("Taisia" , "Nika" ));
365
+
366
+ assertThat (list .contains ("Andrei" )).isTrue ();
367
+ assertThat (list .contains ("Tikhon" )).isTrue ();
368
+ assertThat (list .contains ("Ilya" )).isTrue ();
369
+ assertThat (list .contains ("Taisia" )).isTrue ();
370
+ assertThat (list .contains ("Nika" )).isTrue ();
371
+ }
372
+
373
+ @ Test
374
+ public void testAddAllResizeRequired () {
375
+ CustomArrayList <String > list = new CustomArrayList <>();
376
+ list .add ("Andrei" );
377
+ list .add ("Tikhon" );
378
+ list .add ("Ilya" );
379
+
380
+ list .addAll (List .of ("Taisia" , "Nika" , "Taisia" , "Nika" , "Taisia" , "Alexey" , "Taisia" , "Nika" ));
381
+
382
+ assertThat (list .contains ("Andrei" )).isTrue ();
383
+ assertThat (list .contains ("Tikhon" )).isTrue ();
384
+ assertThat (list .contains ("Ilya" )).isTrue ();
385
+ assertThat (list .contains ("Taisia" )).isTrue ();
386
+ assertThat (list .contains ("Nika" )).isTrue ();
387
+ assertThat (list .contains ("Alexey" )).isTrue ();
388
+ }
389
+
390
+ @ Test
391
+ public void testRemoveAll () {
392
+ CustomArrayList <String > list = new CustomArrayList <>();
393
+ list .add ("Andrei" );
394
+ list .add ("Tikhon" );
395
+ list .add ("Ilya" );
396
+
397
+ list .removeAll (List .of ("Nina" , "Ilya" ));
398
+
399
+ assertThat (list .contains ("Andrei" )).isTrue ();
400
+ assertThat (list .contains ("Tikhon" )).isTrue ();
401
+ assertThat (list .contains ("Ilya" )).isFalse ();
402
+ assertThat (list .size ()).isEqualTo (2 );
403
+ }
404
+
405
+ @ Test
406
+ public void testRetainAll () {
407
+ CustomArrayList <String > list = new CustomArrayList <>();
408
+ list .add ("Andrei" );
409
+ list .add ("Tikhon" );
410
+ list .add ("Ilya" );
411
+
412
+ list .retainAll (List .of ("Tikhon" , "Nina" , "Andrei" ));
413
+
414
+ assertThat (list .contains ("Andrei" )).isTrue ();
415
+ assertThat (list .contains ("Tikhon" )).isTrue ();
416
+ assertThat (list .size ()).isEqualTo (2 );
417
+ }
418
+
419
+ @ Test
420
+ public void testToArray () {
421
+ CustomArrayList <String > list = new CustomArrayList <>();
422
+ list .add ("Andrei" );
423
+ list .add ("Tikhon" );
424
+ list .add ("Ilya" );
425
+
426
+ Object [] result = list .toArray ();
427
+
428
+ assertThat (result [0 ]).isEqualTo ("Andrei" );
429
+ assertThat (result [1 ]).isEqualTo ("Tikhon" );
430
+ assertThat (result [2 ]).isEqualTo ("Ilya" );
431
+ }
432
+
433
+ @ Test
434
+ public void testToArrayTyped () {
435
+ CustomArrayList <String > list = new CustomArrayList <>();
436
+ list .add ("Andrei" );
437
+ list .add ("Tikhon" );
438
+ list .add ("Ilya" );
439
+
440
+ String [] result = list .toArray (new String [0 ]);
441
+
442
+ assertThat (result [0 ]).isEqualTo ("Andrei" );
443
+ assertThat (result [1 ]).isEqualTo ("Tikhon" );
444
+ assertThat (result [2 ]).isEqualTo ("Ilya" );
445
+ }
446
+
447
+ @ Test
448
+ public void testToArrayTypedWhenLongArrayPassedAsParameter () {
449
+ CustomArrayList <String > list = new CustomArrayList <>();
450
+ list .add ("Andrei" );
451
+ list .add ("Tikhon" );
452
+ list .add ("Ilya" );
453
+
454
+ String [] result = list .toArray (new String []{"a" , "b" , "c" , "d" });
455
+
456
+ assertThat (result [0 ]).isEqualTo ("Andrei" );
457
+ assertThat (result [1 ]).isEqualTo ("Tikhon" );
458
+ assertThat (result [2 ]).isEqualTo ("Ilya" );
459
+ assertThat (list .size ()).isEqualTo (3 );
460
+ }
332
461
}
0 commit comments