zohaibbadarpura / Hotel-Debugging

ITC515 Professional Programming Project
0 stars 0 forks source link

On successful checkout customer still be able to charged with services. #3

Closed zohaibbadarpura closed 5 years ago

zohaibbadarpura commented 5 years ago

After customer's / guest's checked out, he still available to be charged with Hotel Services. Which is an issue.

Pre Condition: Customer booked, and checked in against hotel ID. Customer successfully checked out.

Post Condition: Customer must not be able to be charged with services, after confirming successful sign out.

zohaibbadarpura commented 5 years ago

Now there are two possible ways to debug this issue:-

  1. From Price assignment to reporting the price
  2. From reporting to assignment of price but before that, Unit Test to be designed so we can check that issue is fixed?
zohaibbadarpura commented 5 years ago

Unit Test

package hotel;
import static org.junit.Assert.*;
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import hotel.credit.CreditCard;
import hotel.credit.CreditCardType;
import hotel.entities.Booking;
import hotel.entities.Guest;
import hotel.entities.Room;
import hotel.entities.RoomType;
import hotel.entities.ServiceCharge;
import hotel.entities.ServiceType;

public class CheckoutServiceCostTesting {
    static Booking bookingTest;
    static Guest guest;
    static Room room;
    static Date bookedArrival; 
    static int stayLength;
    static int numberOfOccupants;
    static long confirmationNumber;
    static CreditCard testCreditCard;
    static CreditCardType type;
    static int creditcardNumber = 555555555;
    static int ccv;
    static int roomId;
    static List <ServiceCharge> actualCharge;

    @BeforeClass
    public static void beforeClass() {
        bookedArrival = new Date(); 
        stayLength = 10;
        numberOfOccupants=2;
        roomId = 1234;
        type = type.VISA;
        ccv = 786;
        testCreditCard = new CreditCard(type, creditcardNumber, ccv);
        guest = new Guest("Adrian", "Melburn", 123456);
        room = new Room(roomId, RoomType.SINGLE);
    }

    @AfterClass
    public static void tearDownAfterClass() {

    }

    @Before
    public void setUp(){
        bookingTest = new Booking (guest, room, bookedArrival, stayLength, numberOfOccupants, testCreditCard);
    }

    @After
    public void tearDown(){
        bookingTest = null;

    }
    @Test
    public void testCheckoutServiceCost(){
        double actualServiceCost = 45.6;
        bookingTest.addServiceCharge(ServiceType.ROOM_SERVICE, actualServiceCost);
        bookingTest.checkOut();
        assertEquals(bookingTest.getCharges().get(0).getCost(), actualServiceCost, 0.0000);
    }
}
zohaibbadarpura commented 5 years ago

Using this test case, I came to know that value being return by the following function is 0.0 $

public double getCost() {
        return cost;
    }

Which means that value being saved should be checked

zohaibbadarpura commented 5 years ago

Now at this state, function of class booking is check which add services that is addServiceCharge(ServiceType, Cost)

bookingTest.addServiceCharge(ServiceType.ROOM_SERVICE, 45.6);

Looking at this function, issue is found that there is typo mistake that was as follows:- image

![Uploading image.png…]()

zohaibbadarpura commented 5 years ago

Now testing test I have checked that now it shows pass result. image

zohaibbadarpura commented 5 years ago

Console Output Booking Process with Parameters:-

image

image

zohaibbadarpura commented 5 years ago

Check-in Process after providing parameters

image

zohaibbadarpura commented 5 years ago

Recording Service against room ID

image

zohaibbadarpura commented 5 years ago

Checking Out and we can see the used services are zero

image

zohaibbadarpura commented 5 years ago

Result after bug Fix 👍 image