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(arrInts);

}

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!