Question: import static org.junit.Assert.*; import org.junit.*; public class MyArrayListPublicTester { static final int DEFAULT_CAPACITY = 5; static final int MY_CAPACITY = 3; Object[] arr = new
import static org.junit.Assert.*;
import org.junit.*;
public class MyArrayListPublicTester {
static final int DEFAULT_CAPACITY = 5;
static final int MY_CAPACITY = 3;
Object[] arr = new Object[10];
Integer[] arrInts = { 1, 2, 3 };
private MyArrayList listEmpty, listDefaultCap, listCustomCapacity, listWithNull, listWithInt;
public void setUp() throws Exception {
listEmpty = new MyArrayList();
listDefaultCap = new MyArrayList(DEFAULT_CAPACITY);
listCustomCapacity = new MyArrayList(MY_CAPACITY);
listWithNull = new MyArrayList(arr);
listWithInt = new MyArrayList
}
public void testBasicPrependEmpty() {
listDefaultCap.prepend(3);
assertEquals("Check that prepended item", 3, listDefaultCap.data[0]);
assertEquals("Check list size after the prepend", 1, listDefaultCap.size);
assertEquals("Check that capacity is unchanged", 5, listDefaultCap.data.length);
}
Test if an element is correctly inserted at the beginning of the ArrayList, while preserving existing elements. Size and capacity should be updated to reflect the change to the ArrayList where applicable.
How do I prepend null element to the ArrayList using unit test?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
