Chidi U.

asked • 10/25/21

I need help with class IdLookup and its test case

interface Lookup is included at the bottom of the page

public class IdLookup implements Lookup
{
/**
* Constructor for objects of class IdLookup.
* @param newId The id to lookup.
*/
public IdLookup(String newId)
{
/*# insert code here */
}
/**
* Return true if the given product's id matches exactly the id
* passed into our constructor, false otherwise.
* @param product The product to be matched.
* @return true or false.
*/
public boolean matches (Product product)
{
/*# insert code here */
return false;
}
}



public class IdLookupTest
{
/**
* Default constructor for test class IdLookupTest.
*/
public IdLookupTest()
{
/*# insert code here */
}

/**
* Sets up the test fixture.
*
* Called before every test case method.
*/
@Before
public void setUp()
{
/*# insert code here */
}

/**
* Tears down the test fixture.
*
* Called after every test case method.
*/
@After
public void tearDown()
{
/*# insert code here */
}
/*# insert code here */
}


public interface Lookup
{
/**
* Return true if the given product matches our lookup criteria,
* false otherwise.
* @param product The product to be matched.
* @return true or false.
*/
boolean matches (Product product);

}

1 Expert Answer

By:

Kenneth R. answered • 06/21/24

Tutor
New to Wyzant

Math and Physics Tutoring

Kenneth R.

As for testing, you will need to add a couple of Product objects to have a Products to compare against. You can set these as properties of the test class. On the test method itself, test various ID values against these products with some matching and some not. The test would be assertTrue(lookup1.matches(product1)) where lookup1 is an object already created with an id and product1 is one of the products set as a property of the test class. Also make sure you test against a null lookup id and a product with a null id. You might also want to do a test for when a product.id of null is matched with a lookup id of null.
Report

06/21/24

Kenneth R.

One more comment on testing, you also want to test versus the product itself being null as that is one branch of the code. So: assertNotTrue(lookup1.matches(null));
Report

06/21/24

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.