title: How can I test for -- void add(Object val) and Object at(int index) using jUnit testing(java)?
body: <p>I am new to jUnit testing and I have the below code that requires being tested. I am trying to test for add(Object val) and Object at(int index).
  How do I go about those?</p>
  
  <pre><code>public class ResizingArray
  {
     // declare the one stack.
     private Object[] Stack;     
     private int length; //array length       
     private int n; //number of elements
  
     public ResizingArray(int n) //Constructor
     {
        //Create a new stack with n elements of ints.
        Stack = new Object[n];
  
        length = 0;       //no items yet      
     }
  
         //return numbers of elements in stack.
     public int length()
     {
        return length;
     }
  
         //Return the object at the indicated index of the array.
     public Object at(int index)
     {
        if(index &lt; length)
        {
           return Stack[index];
        }
        else
        {
           throw new ArrayIndexOutOfBoundsException();
        }
     }
  
         //add an object at the next available index 
     public void add(Object val)
     {
        //increment length
        if(length() &lt; Stack.length)
        {
           length++;
        }
     }
  
  jUnit Test //This is the jUnit testing
  
  import org.junit.Assert;
  import static org.junit.Assert.*;
  import org.junit.Before;
  import org.junit.Test;
  
  public class ResizingArrayTest 
  {
     protected ResizingArray newStack2;   
  
      public ResizingArrayTest()
      {      
      }
  
     atTest
     public void testLength()
     {
           int[] newStack1 = new int[100]; //a new stack with 100 elements
         //use the for loop to inialize 100 elements
        for(int i = 0; i &lt;= newStack1.length; ++i)
        {
           assertEquals((100),newStack1.length); //test for length.
           newStack1.add(i+1);         //test for add
         }
     }
  }
  </code></pre>