Question: Using JAVA: Given the Code for the Interface & the Custom ArrayList; write junit test cases for testing all the functionality. ------- Interface code: public

Using JAVA: Given the Code for the Interface & the Custom ArrayList; write junit test cases for testing all the functionality.

-------

Interface code:

public interface Interface

{

boolean add (T item);

boolean add (int index, T item) throws IndexOutOfBoundsException;

int getSize();

T get(int index) throws IndexOutOfBoundsException;

T remove(int index) throws IndexOutOfBoundsException;

}

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Custom ArrayList

import java.util.*;

public class CustomArrayList implements Interface

{

ArrayList arrayList = new ArrayList();

public boolean add(String item)

{

arrayList.add(item);

return true;

}

public boolean add(int index, String item)

{

arrayList.add(index, item);

return true;

}

public int getSize()

{

int size = arrayList.size();

return size;

}

public String get(int index)

{

String value = (arrayList.get(index)).toString();

return value;

}

public String remove(int index)

{

String removeitem = (arrayList.remove(index)).toString();

return removeitem;

}

public void printArray()

{

for (String element: arrayList)

{

System.out.println(element);

}

}

public static void main(String args[])

{

CustomArrayList object = new CustomArrayList();

System.out.println("the value added : " + object.add("a"));

System.out.println("the value added : " + object.add("b"));

System.out.println("the value added : " + object.add("c"));

System.out.println("the value added : " + object.add(2, "d"));

System.out.println(" --------Printing the Array--------");

object.printArray();

System.out.println(" Array Size: " + object.getSize());

System.out.println("Getting the Value at Index1 : " + object.get(1));

System.out.println("Removing the Value at Index1: " + object.remove(1));

System.out.println(" --------Printing the Array--------");

object.printArray();

System.out.println(" Array Size: " + object.getSize());

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 Programming Questions!