forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BAEL-4600 | Add examples to demonstrate the difference between Array … (
eugenp#10211) * BAEL-4600 | Add examples to demonstrate the difference between Array Size vs ArrayList Capacity * BAEL-4600 | Refactor | Remove ArrayCreator and ArrayListCreator
- Loading branch information
1 parent
f441017
commit bd3f54e
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
...s-array-list/src/test/java/com/baeldung/listcapacityvsarraysize/ArrayCreatorUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.baeldung.listcapacityvsarraysize; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class ArrayCreatorUnitTest { | ||
|
||
@Test | ||
void whenSizeOfAnArrayIsNonZero_thenReturnNewArrayOfGivenSize() { | ||
Integer[] array = new Integer[10]; | ||
assertEquals(10, array.length); | ||
} | ||
|
||
@Test | ||
void whenSizeOfAnArrayIsLessThanZero_thenThrowException() { | ||
assertThrows(NegativeArraySizeException.class, () -> { Integer[] array = new Integer[-1]; }); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ray-list/src/test/java/com/baeldung/listcapacityvsarraysize/ArrayListCreatorUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.baeldung.listcapacityvsarraysize; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class ArrayListCreatorUnitTest { | ||
|
||
@Test | ||
void givenValidCapacityOfList_whenCreateListInvoked_thenCreateNewArrayListWithGivenCapacity() { | ||
ArrayList<Integer> list = new ArrayList<>(100); | ||
|
||
assertNotNull(list); | ||
} | ||
|
||
@Test | ||
void givenInvalidCapacityOfList_whenCreateListInvoked_thenThrowException() { | ||
assertThrows(IllegalArgumentException.class, () -> new ArrayList<>(-1)); | ||
} | ||
|
||
@Test | ||
void givenValidCapacityOfList_whenCreateListInvoked_thenCreateNewArrayListWithSizeZero() { | ||
assertEquals(0, new ArrayList<Integer>(100).size()); | ||
} | ||
} |