Question
Below is a class for which I want to write JUnit test cases. Can anyone help me in writing test cases for the class? The
Below is a class for which I want to write JUnit test cases. Can anyone help me in writing test cases for the class?
The application is about the online parking garage. There are many classes. This is one of them which is used for Transaction after the reservation is done.
I am new with Junit, kindly help.
package comp.design.parkingsystem;
import java.math.BigInteger;
import java.sql.Date;
import java.sql.SQLException;
import java.util.Calendar;
public class Transaction {
BigInteger id;
public Date time;
public Money amount;
public double tax;
public BigInteger accountNumber, routingNumber;
public Money total() {
return new Money();
}
private static final float RATE = 4; // Dollars per hour
private static final float MAX_DAY = 30;
// Purpose: Takes two calendar objects and returns the difference in time
public static float getTimeDifference(Calendar calFirst, Calendar calSecond) {
if (calFirst.after(calSecond)) {
return 0;
}
float time_in_milli = calFirst.getTimeInMillis();
float time_out_milli = calSecond.getTimeInMillis();
float time_total_milli = time_out_milli - time_in_milli;
float time_total_hour = time_total_milli / 1000 / 60 / 60; // convert milliseconds to hour
return time_total_hour;
}
public static float getPrice(Reservation r) {
Calendar reservedTimeIn = r.reservationInformation().get(0);
Calendar reservedTimeOut = r.reservationInformation().get(1);
Calendar actualTimeIn = r.reservationInformation().get(2);
Calendar actualTimeOut = r.reservationInformation().get(3);
float earlyTime = getTimeDifference(actualTimeIn, reservedTimeIn);
float reservedTime = getTimeDifference(reservedTimeIn, reservedTimeOut);
float extraTime = getTimeDifference(reservedTimeOut, actualTimeOut);
float totalCost = (RATE * earlyTime) + (RATE * reservedTime);
if (totalCost > MAX_DAY) {
totalCost = MAX_DAY;
}
return totalCost;
}
public static float chargeCustomer(Reservation r) throws ClassNotFoundException, SQLException {
// Calculate price
double price = Transaction.getPrice(r);
// update Database
/* update Reservation Object
/*
* update Reservation Object update Reservation Database
*/
return (float) price;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started