Need to add Unit test case methods for the given java file. And the refactoring needs to
Fantastic news! We've Found the answer you've been seeking!
Question:
Need to add Unit test case methods for the given java file. And the refactoring needs to be done to remove repeated lines of codes from each test.
The following test methods are to be implemented:
- HotelServiceTest.java
- searching_for_existing_hotel_should_return_expected_restaurant_object()
- To test iffindHotelByName()returns the expected restaurant object.
- searching_for_non_existing_hotel_should_throw_exception()
- To test iffindHotelByName()throws an exception when the restaurant cannot be found.
- searching_for_existing_hotel_should_return_expected_restaurant_object()
import org.junit.jupiter.api.*; import java.time.LocalTime; import static org.junit.jupiter.api.Assertions.*; class HotelServiceTest { HotelService service = new HotelService(); Hotel hotel; //REFACTOR ALL THE REPEATED LINES OF CODE and Write here //>>>>>>>>>>>>>>>>>>>>>>SEARCHING<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @Test public void searching_for_existing_hotel_should_return_expected_hotel_object() throws hotelNotFoundException { //WRITE UNIT TEST CASE HERE } @Test public void searching_for_non_existing_hotel_should_throw_exception() throws hotelNotFoundException { //WRITE UNIT TEST CASE HERE } //<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>> //>>>>>>>>>>>>>>>>>>>>>>ADMIN: ADDING & REMOVING HOTELS<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @Test public void remove_hotel_should_reduce_list_of_hotels_size_by_1() throws hotelNotFoundException { LocalTime openingTime = LocalTime.parse("10:30:00"); LocalTime closingTime = LocalTime.parse("22:00:00"); hotel = service.addHotel("Clarks Hotel","Poland",openingTime,closingTime); hotel.addToMenu("Sweet corn soup",119); hotel.addToMenu("Vegetable lasagne", 269); int initialNumberOfHotels = service.gethotels().size(); service.removeHotel("Clarks Hotel"); assertEquals(initialNumberOfHotels-1, service.getHotels().size()); } @Test public void removing_hotel_that_does_not_exist_should_throw_exception() throws hotelNotFoundException { LocalTime openingTime = LocalTime.parse("10:30:00"); LocalTime closingTime = LocalTime.parse("22:00:00"); hotel = service.addHotel("Clarks Hotel","Poland",openingTime,closingTime); hotel.addToMenu("Sweet corn soup",119); hotel.addToMenu("Vegetable lasagne", 269); assertThrows(hotelNotFoundException.class,()->service.removeHotel("Denn Hotel")); } @Test public void add_hotel_should_increase_list_of_hotels_size_by_1(){ LocalTime openingTime = LocalTime.parse("10:30:00"); LocalTime closingTime = LocalTime.parse("22:00:00"); hotel = service.addHotel("Clarks Hotel","Poland",openingTime,closingTime); hotel.addToMenu("Sweet corn soup",119); hotel.addToMenu("Vegetable lasagne", 269); int initialNumberOfHotels = service.getHotels().size(); service.addHotel("Pumpkin Tales","Poland",LocalTime.parse("12:00:00"),LocalTime.parse("23:00:00")); assertEquals(initialNumberOfhotels + 1,service.hotels().size()); } //<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>> }
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date: