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

assertEquals("Should get 3 from the list", 3, listWithInt.get(2));

assertEquals("Should get 2 from the list", 2, listWithInt.get(1));

assertEquals("Should get 1 from the list", 1, listWithInt.get(0));

assertEquals("Should get null from the list", null, listWithNull.get(1));

}

How do I get an element at an 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!