I have an interface test class that implements another super-class. In the test class I have a method that is supposed to retrieve all objects in the ArrayList. First it checks to see if it is empty. If not, it should return the whole list. Here is what I have attempted.
public class ProductDBImpl implements ProductDB {
// field declarations
ArrayList<Product> products = new ArrayList<Product>();
@Override
public List<Product> getAllProducts()
{
// TODO Auto-generated method stub
// TODO Auto-generated method stub
// create an iterator for the Arraylist
if (products.isEmpty())
{
return new ArrayList<Product>() ;
}
return products;
}
Unfortunately, when I run my test script (tests the interface test class and super-class) the getAllProducts() method is not working the way it should and it is returning a productdb.util.AssertionFailedError: expected:<1> but was:<0> message. Here is the way the test script is testing the getAllProducts() method:
// testing getAllProducts()
List<Product> productList = productDB.getAllProducts();
int size = productList.size();
productList.remove(0);
productList = productDB.getAllProducts();
Assert.assertEquals(size, productList.size());
Please help me identify my error. Thanks.