Goal The goal of this assignment is to help students underst
Goal: The goal of this assignment is to help students understand the use of JUnit to test Java code.
Description: In this assignment you will create a set of unit tests, to test the behavior of the code written for Assignment 1. To keep things consistent, please use the solution to assignment 1 provided by the instructor. You can find the solution on TRACS, under Resources > Assignment-related material > Assignment Solutions.
A unit test is an automated piece of code that invokes a unit of work in the system and then checks a single assumption about the behavior of that unit of work. A unit of work is a single logical functional use case in the system that can be invoked by some public interface (in most cases). A unit of work can span a single method, a whole class or multiple classes working together to achieve one single logical purpose that can be verified.
Think of unit testing as a way to test the behavior of the code (or parts of the code) written, without actually having to run the program. For example, in the case of assignments 1, assume that the front-end (console user interface) part of the program and the back-end part of the program (dealership database management) are written by two different developers. How would the developer of the back-end be able to ensure that the code he/she has written does what it is supposed to do without having access to the front-end?
A good unit test is:
• Able to be fully automated
• Has full control over all the pieces running.
• Can be run in any order, if part of many other tests
• Runs in memory (no DB or File access, for example)
• Consistently returns the same result (You always run the same test, so no random numbers, for example.)
• Runs fast
• Tests a single logical concept in the system
• Readable
• Maintainable
• Trustworthy (when you see its result, you don’t need to debug the code just to be sure)
In this assignment, you are asked to create JUnit tests to test the classes and methods written for assignment 1. First you should consider testing the behavior of theses classes/methods under normal operation scenarios. For example, to test the method findCar(String vin) of the class Dealership, you may need to create a test method, which creates a mock Car object and adds it to the carList before the method findCar can be called to search for it. To ensure that everything worked as planned, you can then search for the car using its VIN and see if the correct car is found. Mock objects can be created either in the same test method or before any test methods are run, using the @BeforeClass annotation.
Subsequently, you can consider creating test cases for unusual scenarios, e.g. when a certain input or behavior is expected to cause an exception to be thrown, or when a user input is not as expected.
At the end create a TestRunner class, which has a main method that runs the unit tests that you have created, and prints out the test results.
Tasks:
1. Implement the JUnit tests to test only the class Dealership.java, including all its methods. Try to be creative by coming up with test cases that can test as many different situations as possible. You don’t need to test the classes Car.java and MainClass.java.
2. Use a standard Java coding style to improve your program’s visual appearance and make it more readable. I suggest the BlueJ coding style: http://www.bluej.org/objects-first/styleguide.html
3. Use Javadoc to document your code.
Dealership Program
import java.io.IOException;
import java.io.FileReader;
import java.io.PrintWriter;
import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;
/**
* This class is used to represent a database interface for a list of
* <CODE>Car</CODE>\'s. It using a plain-text file \"cars.txt\" to store and write
* car objects in readable text form. It contains an <CODE>ArrayList</CODE>
* called <CODE>carList</CODE> to store the database in a runtime friendly data
* structure. The <CODE>carList</CODE> is written to \"cars.txt\" at the end of
* the <CODE>Dealership</CODE> object\'s life by calling <CODE>flush()</CODE>.
* This class also provides methods for adding, remove, and searching for cars
* from the list.
*
* @author Vangelis Metsis
*/
public class Dealership {
private ArrayList<Car> carList;
/**
* This constructor is hard-coded to open \"<CODE>cars.txt</CODE>\" and
* initialize the <CODE>carList</CODE> with its contents. If no such file
* exists, then one is created. The contents of the file are \"loaded\" into
* the carList ArrayList in no particular order. The file is then closed
* during the duration of the program until <CODE>flush()</CODE> is called.
* @throws IOException
*/
public Dealership() throws IOException {
carList = new ArrayList<>();
Scanner carDatabase;
File dataFile = new File(\"cars.txt\");
// If data file does not exist, create it.
if (!dataFile.exists()) {
System.err.println(\"Cars.txt does not exist, creating one now . . .\");
//if the file doesn\'t exists, create it
PrintWriter pw = new PrintWriter(\"cars.txt\");
//close newly created file so we can reopen it
pw.close();
}
carDatabase = new Scanner(new FileReader(dataFile));
//Initialize the Array List with cars from cars.txt
while (carDatabase.hasNextLine()) {
// split values using the space character as separator
String[] temp = carDatabase.nextLine().split(\" \");
carList.add(new Car(temp[0], temp[1], temp[2], Integer.parseInt(temp[3]),
Integer.parseInt(temp[4]), Float.parseFloat(temp[5])));
}
//Cars list is now in the Array List Completely so we can close the file
carDatabase.close();
}
/**
* Method showCars displays the current list of cars in the Arraylist in no
* particular order.
*
*/
public void showCars() {
showCars(carList);
}
/**
* Private method used as an auxiliary method to display a given ArrayList
* of cars in a formatted manner.
*
* @param cars the car list to be displayed.
*/
private void showCars(ArrayList<Car> cars) {
System.out.println(\" __________________________________________________________________________________\");
System.out.println(\"| Entry | VIN | Make | Model | Year | Mileage | Price |\");
System.out.println(\"|----------------------------------------------------------------------------------|\");
for (int i = 0; i < cars.size(); i++) {
System.out.println(String.format(\"| %-6s| %-7s| %-15s| %-15s| %-5s| %-8s| $%-12s|\",
Integer.toString(i + 1), cars.get(i).getVin(), cars.get(i).getMake(), cars.get(i).getModel(),
Integer.toString(cars.get(i).getYear()), Integer.toString(cars.get(i).getMileage()),
String.format(\"%.2f\", cars.get(i).getPrice())));
}
System.out.println(\"|__________________________________________________________________________________|\ \");
}
/**
* This method displays cars that have a price within the range of
* <CODE>low</CODE> to <CODE>high</CODE>.
*
* @param low a float that is the lower bound price.
* @param high a float that is the upper bound price.
*/
public void showCarsRange(float low, float high) {
ArrayList<Car> cars = new ArrayList<>();
for (Car car : carList) {
if ((low <= car.getPrice()) && (car.getPrice() <= high)) {
cars.add(car);
}
}
showCars(cars);
}
/**
* This method can be used to search for a car in the Arraylist of cars.
*
* @param vin a <CODE>String</CODE> that represents the vehicle
* identification number of the car that to be searched for
* @return the <CODE>int</CODE> index of the car in the Arraylist of cars,
* or -1 if the search failed.
*/
public int findCar(String vin) {
int index = -1;
for (int i = 0; i < carList.size(); i++) {
String temp = carList.get(i).getVin();
if (vin.equalsIgnoreCase(temp)) {
index = i;
break;
}
}
return index;
}
/**
* This method is used to add a car to the carList ArrayList. In order for a
* car to be added to the ArrayList it must comply with the following:
* <p>
* 1. The car is not already in the ArrayList according to the VIN
* as the unique key.
* <p>
* 2. The VIN string matches the following regular expression:
* <CODE>\"[A-Za-z0-9]{5}\"</CODE> or in other words: it
* is 5 avinhanumeric characters.
* <p>
* 3. The make of the car is only alphanumeric characters.
* <p>
* 4. The model of the car is only alphanumeric or contains a dash \"-\".
* <p>
* 5. The year model must be exactly four digits.
* <p>
* 6. The price must be non-negative.
*
* @param toAdd the <CODE>Car</CODE> object to add to the
* <CODE>carList</CODE>
*/
public void addCar(String vin, String make, String model, String year, String mileage, String price) {
if (this.findCar(vin) != -1) {
System.err.println(\"Car already exists in database. \ \");
return;
}
if (!vin.matches(\"[A-Za-z0-9]{5}\")) {
System.err.println(\"Invalid VIN: not proper format.\"
+ \"VIN must be at least 5 alphanumeric characters.\");
return;
}
if (!make.matches(\"[A-Za-z0-9]+\")) {
System.err.println(\"Invalid make type:\ \"
+ \"The car\'s make must be an alphanumeric string.\");
return;
}
if (!model.matches(\"[A-Z0-9a-z\\\\-]+\")) {
System.err.println(\"Invalid model type:\ \"
+ \"The car\'s model must be a non-numeric alphabet string.\");
return;
}
if (!year.matches(\"[0-9]{4}\") ) {
System.err.println(\"Invalid year:\ \"
+ \"The car\'s year of manufacture must be a 4 digit number. \");
return;
}
if (!mileage.matches(\"[0-9]{1,6}\")) {
System.err.println(\"Invalid milage:\ \"
+ \"The car\'s mileage has to be an integer number between 0 and 999999. \");
return;
}
if (Float.parseFloat(price) < 0) {
System.err.println(\"The entered price cannot be negative.\");
return;
}
//If passed all the checks, add the car to the list
carList.add(new Car(vin, make, model, Integer.parseInt(year),
Integer.parseInt(mileage), Float.parseFloat(price)));
System.out.println(\"Car has been added.\ \");
}
/**
* This method will remove a car from the <CODE>carList</CODE> ArrayList. It
* will remove the first instance of a car that matches the car that was
* passed to this method in the <CODE>carList</CODE> using the
* <CODE>equals()</CODE> override in the class <CODE>Car</CODE>. If no such
* car exists, it will produce an error message.
*
* @param toDelete the <CODE>car</CODE> object to be removed.
*/
public void removeCar(Car toDelete) {
if (carList.remove(toDelete)) {
System.out.println(\"Car was removed.\ \");
} else {
System.err.println(\"Car does not exist in database.\");
}
}
/**
* This method is used to retrieve the Car object from the
* <CODE>carList</CODE> at a given index.
*
* @param i the index of the desired <CODE>car</CODE> object.
* @return the <CODE>car</CODE> object at the index or null if the index is
* invalid.
*/
public Car getCar(int i) {
if (i < carList.size() && i >= 0) {
return carList.get(i);
} else {
System.err.println(\"Invalid Index. Please enter another command or \'h\' to list the commands.\");
return null;
}
}
/**
* This should be the last method to be called from this class. It opens
* <CODE>\"cars.txt\"</CODE> and overwrites it with a text representation of
* all the cars in the <CODE>carList</CODE>.
* @throws IOException
*/
public void flush() throws IOException {
PrintWriter pw = new PrintWriter(\"cars.txt\");
for (Car c : carList) {
pw.print(c.toString());
}
pw.close();
}
}
Solution
MainClass.java
import java.util.InputMismatchException;
import java.util.Scanner;
public class MainClass {
/**
* This method will begin the user interface console. Main uses a loop to
* continue doing commands until the user types \'6\'. A lot of user input
* validation is done in the loop. At least enough to allow the interface
* with Dealership to be safe.
*
* @param args this program expects no command line arguments
* @throws Exception
*/
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
Dealership dealership = new Dealership();
String welcomeMessage = \"\ Welcome to the dealership database. Choose one of the following functions:\ \ \"
+ \"\\t1. Show all existing car records in the database\ \"
+ \"\\t2. Add a new car record to the database.\ \"
+ \"\\t3. Delete a car record from a database.\ \"
+ \"\\t4. Search for a car (given its VIN).\ \"
+ \"\\t5. Show a list of cars within a given price range.\ \"
+ \"\\t6. Exit program.\ \";
System.out.println(welcomeMessage);
int selection = in.next().charAt(0);
in.nextLine();
while (selection != \'6\') {
switch (selection) {
case \'1\':
dealership.showCars();
break;
case \'2\':
System.out.println(\"\ Please type description of car with the following pattern:\ \"
+ \"\ VIN MAKE MODEL YEAR MILEAGE PRICE\ \"
+ \"example:\ DAW12 Honda Civic 2007 52333 9500.00\ \");
String inTemp = in.nextLine();
String temp[] = inTemp.split(\" \");
if (temp.length != 6) {
System.out.println(\"Not correct number of fields to process.\");
break;
}
dealership.addCar(temp[0], temp[1], temp[2], temp[3], temp[4], temp[5]);
break;
case \'3\':
dealership.showCars();
System.out.println(\"\ Please select which number entry to delete from the database.\ \");
int numToDelete = in.nextInt();
in.nextLine(); //Skip new line character
dealership.removeCar(dealership.getCar(numToDelete - 1));
break;
case \'4\':
System.out.println(\"\ Enter the VIN of the car you wish to see.\ \");
String vin = in.next();
in.nextLine();
int index = dealership.findCar(vin);
if (index != -1) {
System.out.println(\"\ Here is the car that matched\ \"
+ dealership.getCar(index).toString()
+ \"\ \");
} else {
System.out.println(\"\ Search did not find a match.\ \");
}
break;
case \'5\':
float high = 0;
float low = 0;
System.out.println(\"\ Enter lower-bound price.\ \");
low = in.nextFloat();
System.out.println(\"\ Enter upper-bound price.\ \");
high = in.nextFloat();
in.nextLine();
dealership.showCarsRange(low, high);
break;
case \'h\':
System.out.println(welcomeMessage);
break;
default:
System.out.println(\"That is not a recognized command. Please enter another command or \'h\' to list the commands.\");
break;
}
System.out.println(\"Please enter another command or \'h\' to list the commands.\ \");
selection = in.next().charAt(0);
in.nextLine();
}
in.close();
dealership.flush();
System.out.println(\"Done!\");
}
}
Dealership.java
import java.io.IOException;
import java.io.FileReader;
import java.io.PrintWriter;
import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;
/**
* This class is used to represent a database interface for a list of
* <CODE>Car</CODE>\'s. It using a plain-text file \"cars.txt\" to store and write
* car objects in readable text form. It contains an <CODE>ArrayList</CODE>
* called <CODE>carList</CODE> to store the database in a runtime friendly data
* structure. The <CODE>carList</CODE> is written to \"cars.txt\" at the end of
* the <CODE>Dealership</CODE> object\'s life by calling <CODE>flush()</CODE>.
* This class also provides methods for adding, remove, and searching for cars
* from the list.
*
* @author Vangelis Metsis
*/
public class Dealership {
private ArrayList<Car> carList;
/**
* This constructor is hard-coded to open \"<CODE>cars.txt</CODE>\" and
* initialize the <CODE>carList</CODE> with its contents. If no such file
* exists, then one is created. The contents of the file are \"loaded\" into
* the carList ArrayList in no particular order. The file is then closed
* during the duration of the program until <CODE>flush()</CODE> is called.
* @throws IOException
*/
public Dealership() throws IOException {
carList = new ArrayList<>();
Scanner carDatabase;
File dataFile = new File(\"cars.txt\");
// If data file does not exist, create it.
if (!dataFile.exists()) {
System.err.println(\"Cars.txt does not exist, creating one now . . .\");
//if the file doesn\'t exists, create it
PrintWriter pw = new PrintWriter(\"cars.txt\");
//close newly created file so we can reopen it
pw.close();
}
carDatabase = new Scanner(new FileReader(dataFile));
//Initialize the Array List with cars from cars.txt
while (carDatabase.hasNextLine()) {
// split values using the space character as separator
String[] temp = carDatabase.nextLine().split(\" \");
carList.add(new Car(temp[0], temp[1], temp[2], Integer.parseInt(temp[3]),
Integer.parseInt(temp[4]), Float.parseFloat(temp[5])));
}
//Cars list is now in the Array List Completely so we can close the file
carDatabase.close();
}
/**
* Method showCars displays the current list of cars in the Arraylist in no
* particular order.
*
*/
public void showCars() {
showCars(carList);
}
/**
* Private method used as an auxiliary method to display a given ArrayList
* of cars in a formatted manner.
*
* @param cars the car list to be displayed.
*/
private void showCars(ArrayList<Car> cars) {
System.out.println(\" __________________________________________________________________________________\");
System.out.println(\"| Entry | VIN | Make | Model | Year | Mileage | Price |\");
System.out.println(\"|----------------------------------------------------------------------------------|\");
for (int i = 0; i < cars.size(); i++) {
System.out.println(String.format(\"| %-6s| %-7s| %-15s| %-15s| %-5s| %-8s| $%-12s|\",
Integer.toString(i + 1), cars.get(i).getVin(), cars.get(i).getMake(), cars.get(i).getModel(),
Integer.toString(cars.get(i).getYear()), Integer.toString(cars.get(i).getMileage()),
String.format(\"%.2f\", cars.get(i).getPrice())));
}
System.out.println(\"|__________________________________________________________________________________|\ \");
}
/**
* This method displays cars that have a price within the range of
* <CODE>low</CODE> to <CODE>high</CODE>.
*
* @param low a float that is the lower bound price.
* @param high a float that is the upper bound price.
*/
public void showCarsRange(float low, float high) {
ArrayList<Car> cars = new ArrayList<>();
for (Car car : carList) {
if ((low <= car.getPrice()) && (car.getPrice() <= high)) {
cars.add(car);
}
}
showCars(cars);
}
/**
* This method can be used to search for a car in the Arraylist of cars.
*
* @param vin a <CODE>String</CODE> that represents the vehicle
* identification number of the car that to be searched for
* @return the <CODE>int</CODE> index of the car in the Arraylist of cars,
* or -1 if the search failed.
*/
public int findCar(String vin) {
int index = -1;
for (int i = 0; i < carList.size(); i++) {
String temp = carList.get(i).getVin();
if (vin.equalsIgnoreCase(temp)) {
index = i;
break;
}
}
return index;
}
/**
* This method is used to add a car to the carList ArrayList. In order for a
* car to be added to the ArrayList it must comply with the following:
* <p>
* 1. The car is not already in the ArrayList according to the VIN
* as the unique key.
* <p>
* 2. The VIN string matches the following regular expression:
* <CODE>\"[A-Za-z0-9]{5}\"</CODE> or in other words: it
* is 5 avinhanumeric characters.
* <p>
* 3. The make of the car is only alphanumeric characters.
* <p>
* 4. The model of the car is only alphanumeric or contains a dash \"-\".
* <p>
* 5. The year model must be exactly four digits.
* <p>
* 6. The price must be non-negative.
*
* @param toAdd the <CODE>Car</CODE> object to add to the
* <CODE>carList</CODE>
*/
public void addCar(String vin, String make, String model, String year, String mileage, String price) {
if (this.findCar(vin) != -1) {
System.err.println(\"Car already exists in database. \ \");
return;
}
if (!vin.matches(\"[A-Za-z0-9]{5}\")) {
System.err.println(\"Invalid VIN: not proper format.\"
+ \"VIN must be at least 5 alphanumeric characters.\");
return;
}
if (!make.matches(\"[A-Za-z0-9]+\")) {
System.err.println(\"Invalid make type:\ \"
+ \"The car\'s make must be an alphanumeric string.\");
return;
}
if (!model.matches(\"[A-Z0-9a-z\\\\-]+\")) {
System.err.println(\"Invalid model type:\ \"
+ \"The car\'s model must be a non-numeric alphabet string.\");
return;
}
if (!year.matches(\"[0-9]{4}\") ) {
System.err.println(\"Invalid year:\ \"
+ \"The car\'s year of manufacture must be a 4 digit number. \");
return;
}
if (!mileage.matches(\"[0-9]{1,6}\")) {
System.err.println(\"Invalid milage:\ \"
+ \"The car\'s mileage has to be an integer number between 0 and 999999. \");
return;
}
if (Float.parseFloat(price) < 0) {
System.err.println(\"The entered price cannot be negative.\");
return;
}
//If passed all the checks, add the car to the list
carList.add(new Car(vin, make, model, Integer.parseInt(year),
Integer.parseInt(mileage), Float.parseFloat(price)));
System.out.println(\"Car has been added.\ \");
}
/**
* This method will remove a car from the <CODE>carList</CODE> ArrayList. It
* will remove the first instance of a car that matches the car that was
* passed to this method in the <CODE>carList</CODE> using the
* <CODE>equals()</CODE> override in the class <CODE>Car</CODE>. If no such
* car exists, it will produce an error message.
*
* @param toDelete the <CODE>car</CODE> object to be removed.
*/
public void removeCar(Car toDelete) {
if (carList.remove(toDelete)) {
System.out.println(\"Car was removed.\ \");
} else {
System.err.println(\"Car does not exist in database.\");
}
}
/**
* This method is used to retrieve the Car object from the
* <CODE>carList</CODE> at a given index.
*
* @param i the index of the desired <CODE>car</CODE> object.
* @return the <CODE>car</CODE> object at the index or null if the index is
* invalid.
*/
public Car getCar(int i) {
if (i < carList.size() && i >= 0) {
return carList.get(i);
} else {
System.err.println(\"Invalid Index. Please enter another command or \'h\' to list the commands.\");
return null;
}
}
/**
* This should be the last method to be called from this class. It opens
* <CODE>\"cars.txt\"</CODE> and overwrites it with a text representation of
* all the cars in the <CODE>carList</CODE>.
* @throws IOException
*/
public void flush() throws IOException {
PrintWriter pw = new PrintWriter(\"cars.txt\");
for (Car c : carList) {
pw.print(c.toString());
}
pw.close();
}
}
Car.java
public class Car {
private final String vin;
private final String make;
private final String model;
private final int year;
private final int mileage;
private final float price;
/**
* This constructor initializes the car object. The constructor provides no
* user input validation. That should be handled by the class that creates a
* car object.
*
* @param vin a <b><CODE>String</CODE></b> that represents the license plate
* @param make a <b><CODE>String</CODE></b> that represents the make
* @param model a <b><CODE>String</CODE></b> that represents the model
* @param year a 4 digit <b><CODE>int</CODE></b> that represents the year
* model
* @param mileage an <b><CODE>int</CODE></b> that represents the mileage of
* the vehicle
* @param price a <b><CODE>float</CODE></b> that represents the price of the
* vehicle
*/
public Car(String vin, String make, String model, int year, int mileage, float price) {
this.vin = vin;
this.make = make;
this.model = model;
this.year = year;
this.mileage = mileage;
this.price = price;
}
/**
* This method returns the car\'s license plate.
*
* @return a <b><CODE>String</CODE></b> that is the VIN of the car.
*/
public String getVin() {
return vin;
}
/**
* This method returns the car\'s make.
*
* @return a <b><CODE>String</CODE></b> that is the car\'s make.
*/
public String getMake() {
return make;
}
/**
* This method returns the car\'s model.
*
* @return a <b><CODE>String</CODE></b> that is the car\'s model.
*/
public String getModel() {
return model;
}
/**
* This method returns the car\'s model year.
*
* @return an <b><CODE>int</CODE></b> that is the car\'s year model
*/
public int getYear() {
return year;
}
/**
* This method returns the car\'s mileage.
*
* @return an <b><CODE>int</CODE></b> that is the car\'s mileage
*/
public int getMileage() {
return mileage;
}
/**
* This method returns the car\'s price.
*
* @return a <b><CODE>float</CODE></b> that is the car\'s price
*/
public float getPrice() {
return price;
}
/**
* This method returns the car\'s fields as a string representation.
*
* @return a <b><CODE>String</CODE></b> that lists the fields of the car
* object delineated by a space and in the same order as the constructor
*/
@Override
public String toString() {
return vin + \" \" + make + \" \" + model + \" \" + year + \" \" + mileage
+ \" \" + String.format(\"%.2f\", price) + \"\ \";
}
/**
* This method provides a way to compare two car objects.
*
* @param c a <b><CODE>Car</CODE></b> object that is used to compare to
* <b><CODE>this</CODE></b> car. two cars are equal if their VIN is the
* same.
* @return the <CODE>boolean</CODE> value of the comparison.
*/
public boolean equals(Car c) {
return c.getVin().equals(this.vin);
}
}
DealershipTest.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.IOException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.ArrayList;
public class DealershipTest {
private static ArrayList<Car> carList = new ArrayList<Car>();
public DealershipTest() {
}
@BeforeClass
public static void setUpClass() {
carList.add(new Car(\"AJS172\", \"Honda\", \"Civic\", 1998, 20145, 7898.90F));
carList.add(new Car(\"ZZC974\", \"Toyota\", \"Celica\", 2001, 100304, 9400.90F));
carList.add(new Car(\"ABS669\", \"Ford\", \"Mustang\", 1963, 400321, 3400.90F));
System.out.println(\"Set up environment\");
}
@AfterClass
public static void tearDownClass() {
System.out.println(\"Cleared environment\");
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of showCars method, of class Dealership.
*/
@Test
public void testShowCars() {
System.out.println(\"This is a test.\");
}
/**
* Test of showCarsRange method, of class Dealership.
* @throws java.io.IOException
*/
@Test
public void testShowCarsRange() throws IOException {
System.out.println(\"showCarsRange\");
//Test normal functionality
float low = 0.0F;
float high = 30000.0F;
Dealership instance = new Dealership();
instance.showCarsRange(low, high);
//Test negative low
low = -5.0F;
instance.showCarsRange(low, high);
//Test high < low
low = 3.0F;
high = 2.0F;
instance.showCarsRange(low, high);
}
/**
* Test of findCar method, of class Dealership.
* @throws java.io.IOException
*/
@Test
public void testFindCar() throws IOException {
System.out.println(\"findCar\");
String vin = \"ZZC974\";
Dealership instance = new Dealership();
int expResult = 2;
int result = instance.findCar(vin);
assertEquals(expResult, result);
}
/**
* Test of addCar method, of class Dealership.
* @throws java.io.IOException
*/
@Test
public void testAddCar() throws IOException {
System.out.println(\"addCar\");
String vin = \"\";
String make = \"\";
String model = \"\";
String year = \"\";
String mileage = \"\";
String price = \"\";
Dealership instance = new Dealership();
instance.addCar(vin, make, model, year, mileage, price);
//Test vin > 5 characters
vin = \"Helloo\";
instance.addCar(vin, make, model, year, mileage, price);
}
/**
* Test of removeCar method, of class Dealership.
* @throws java.io.IOException
*/
@Test
public void testRemoveCar() throws IOException {
System.out.println(\"removeCar\");
Car toDelete = null;
Dealership instance = new Dealership();
instance.removeCar(toDelete);
//Add Car, then delete it
instance.addCar(null, null, null, null, null, null);
instance.removeCar(null);
}
/**
* Test of getCar method, of class Dealership.
* @throws java.io.IOException
*/
@Test
public void testGetCar() throws IOException {
System.out.println(\"getCar\");
Dealership instance = new Dealership();
//Add a car and then search for it
instance.addCar(null, null, null, null, null, null);
int i = 1;
Car expResult = null;
Car result = instance.getCar(i);
assertEquals(expResult, result);
}
/**
* Test of flush method, of class Dealership.
* @throws java.lang.Exception
*/
@Test
public void testFlush() throws Exception {
System.out.println(\"flush\");
Dealership instance = new Dealership();
instance.flush();
}
}















