Assume that I have a book store which sells books. I want to create an application to calculates min, max, and average price of sold books.
I want to build a JUnit test case to test min, max, average methods of this application, and throw an appropriate exception for each of the following cases.
• When populating the array of Book objects, application should throw a specific exception for array, not general exception, if test case passed more book objects than array capacity to application. Array capacity is defined as (nBooks = 5 ;). Do not use java scan. Build allocation programmatically.
• Use ONLY ARRAY. NOT LIST, NOT ARRAY List, or any other data structures for this assignment.
• When calculating the average sales, throw specific exception for divide by zero not general exception, if ZERO books were sold.
• Build test statistic, demonstrate how many test cases passed, and how many failed due to Assertion Error. Use logic to build test statistics and display it with Junit-5 Test Reporter object.
Assignment Process
1. Build Book class.
• Book
public class Book {
//instance variables // (int id; String name; double price)
//constructor
// getter/setter methods
}
2. Build application class to drive book objects.
• Application
public class BookApp {
//Class name in Java starts with uppercase letter (e.g. BookApp)
//Method name in java starts with lowercase
//(e.g. populateBooks)
//Build one method for each application ‘s functionality as follows.
//A method to populate Array of Book objects.
//A method to calculate the minimum price of books.
//A method to calculate the maximum price of books.
// A method to calculate the average price of books.
}
3. Build JUnit Test case to test the book application.
• TestCase
public BookTestCase {
// instance/class variables
// constructor
@BeforeEach // or @BeforeAll
@Test
// Build one test method for each
// application’s method
//method name starts with lower case “test”
// (e.g.
public void testPopulateBooks () {…}
@AfterEach // or @AfterAll
}
4. Build and run eclipse project.
• Create a java project and name it ,“book”.
• Create a package under the project and name it.
• (e.g. “susan.assignment1.junit5.book.test”).
• Compile and run the test case as
i. “JUnit Test”.