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 testBasicInsert() {

listWithNull.insert(0, Integer.valueOf(5));

listCustomCapacity.insert(0, 100);

assertEquals("should insert 5 to the list", 5, listWithNull.data[0]);

assertEquals("should increment size", 11, listWithNull.size);

assertEquals("check that if the capacity is updated", 20, listWithNull.data.length);

assertEquals("should insert 5 to the list", 100, listCustomCapacity.data[0]);

assertEquals("should increment size", 1, listCustomCapacity.size);

assertEquals("capacity of the list should not change when insert one elem", 3, listCustomCapacity.data.length);

}

How do I insert a out of bounds index with unit testing?

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!