|
| 1 | +package com.codedifferently.lesson16.benjaminscott; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 6 | + |
| 7 | +import org.junit.jupiter.api.Test; |
| 8 | + |
| 9 | +class RestaurantTest { |
| 10 | + |
| 11 | + @Test |
| 12 | + void testAddMenuItem() { |
| 13 | + String[] initialMenu = new String[5]; |
| 14 | + Restaurant restaurant = new Restaurant("Test Restaurant", initialMenu, 20, 0, true); |
| 15 | + |
| 16 | + boolean firstAdd = restaurant.addMenuItem("Burger"); |
| 17 | + boolean secondAdd = restaurant.addMenuItem("Pizza"); |
| 18 | + |
| 19 | + assertTrue(firstAdd, "Should successfully add first item"); |
| 20 | + assertTrue(secondAdd, "Should successfully add second item"); |
| 21 | + String[] menu = restaurant.getMenuitems(); |
| 22 | + assertEquals("Burger", menu[0]); |
| 23 | + assertEquals("Pizza", menu[1]); |
| 24 | + } |
| 25 | + |
| 26 | + @Test |
| 27 | + void testDisplayMenu() { |
| 28 | + String[] initialMenu = {"Burger", "Pizza", null, null, null}; |
| 29 | + Restaurant restaurant = new Restaurant("Test Restaurant", initialMenu, 20, 0, true); |
| 30 | + |
| 31 | + String displayedMenu = restaurant.displayMenu(); |
| 32 | + |
| 33 | + assertTrue(displayedMenu.contains("Burger")); |
| 34 | + assertTrue(displayedMenu.contains("Pizza")); |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + void testSeatGuests() { |
| 39 | + Restaurant restaurant = new Restaurant("Test Restaurant", new String[5], 20, 0, true); |
| 40 | + boolean seated = restaurant.seatGuests(4); |
| 41 | + assertTrue(seated, "Should successfully seat guests"); |
| 42 | + assertEquals(1, restaurant.getCurrentTables()); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + void testSeatGuestsWhenFull() { |
| 47 | + Restaurant restaurant = new Restaurant("Test Restaurant", new String[5], 1, 1, true); |
| 48 | + boolean seated = restaurant.seatGuests(4); |
| 49 | + assertFalse(seated, "Should not seat guests when full"); |
| 50 | + assertEquals(1, restaurant.getCurrentTables()); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + void testAddMenuItemWhenClosed() { |
| 55 | + Restaurant restaurant = new Restaurant("Test Restaurant", new String[5], 20, 0, false); |
| 56 | + boolean added = restaurant.addMenuItem("Burger"); |
| 57 | + assertFalse(added, "Should not add items when restaurant is closed"); |
| 58 | + String[] menu = restaurant.getMenuitems(); |
| 59 | + assertEquals(null, menu[0]); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + void testAddMenuItemWhenFull() { |
| 64 | + String[] initialMenu = {"Item1", "Item2", "Item3", "Item4", "Item5"}; |
| 65 | + Restaurant restaurant = new Restaurant("Test Restaurant", initialMenu, 20, 0, true); |
| 66 | + boolean added = restaurant.addMenuItem("Extra Item"); |
| 67 | + assertFalse(added, "Should not add items when menu is full"); |
| 68 | + } |
| 69 | + |
| 70 | + @Test |
| 71 | + void testCheckCapacityWhenNotFull() { |
| 72 | + Restaurant restaurant = new Restaurant("Test Restaurant", new String[5], 5, 3, true); |
| 73 | + restaurant.checkCapacity(); |
| 74 | + assertTrue(restaurant.isOpen(), "Restaurant should remain open when not at capacity"); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + void testCheckCapacityWhenFull() { |
| 79 | + Restaurant restaurant = new Restaurant("Test Restaurant", new String[5], 5, 5, true); |
| 80 | + restaurant.checkCapacity(); |
| 81 | + assertFalse(restaurant.isOpen(), "Restaurant should close when at capacity"); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + void testSeatGuestsWithZeroGuests() { |
| 86 | + Restaurant restaurant = new Restaurant("Test Restaurant", new String[5], 20, 0, true); |
| 87 | + boolean seated = restaurant.seatGuests(0); |
| 88 | + assertFalse(seated, "Should not seat zero guests"); |
| 89 | + assertEquals(0, restaurant.getCurrentTables(), "Table count should not change"); |
| 90 | + } |
| 91 | + |
| 92 | + @Test |
| 93 | + void testSeatGuestsWithNegativeGuests() { |
| 94 | + Restaurant restaurant = new Restaurant("Test Restaurant", new String[5], 20, 0, true); |
| 95 | + boolean seated = restaurant.seatGuests(-1); |
| 96 | + assertFalse(seated, "Should not seat negative number of guests"); |
| 97 | + assertEquals(0, restaurant.getCurrentTables(), "Table count should not change"); |
| 98 | + } |
| 99 | + |
| 100 | + @Test |
| 101 | + void testDisplayEmptyMenu() { |
| 102 | + String[] emptyMenu = new String[5]; |
| 103 | + Restaurant restaurant = new Restaurant("Test Restaurant", emptyMenu, 20, 0, true); |
| 104 | + String displayedMenu = restaurant.displayMenu(); |
| 105 | + assertEquals("Menu Items:\n", displayedMenu, "Empty menu should only show header"); |
| 106 | + } |
| 107 | + |
| 108 | + @Test |
| 109 | + void testRestaurantTypeValues() { |
| 110 | + Restaurant.RestaurantType[] types = Restaurant.RestaurantType.values(); |
| 111 | + assertEquals(5, types.length, "Should have 5 restaurant types"); |
| 112 | + assertEquals(Restaurant.RestaurantType.FAST_FOOD, types[0]); |
| 113 | + assertEquals(Restaurant.RestaurantType.CASUAL_DINING, types[1]); |
| 114 | + assertEquals(Restaurant.RestaurantType.FINE_DINING, types[2]); |
| 115 | + assertEquals(Restaurant.RestaurantType.CAFE, types[3]); |
| 116 | + assertEquals(Restaurant.RestaurantType.BUFFET, types[4]); |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + void testGetName() { |
| 121 | + String restaurantName = "Test Restaurant"; |
| 122 | + Restaurant restaurant = new Restaurant(restaurantName, new String[5], 20, 0, true); |
| 123 | + assertEquals( |
| 124 | + restaurantName, restaurant.getName(), "getName should return the correct restaurant name"); |
| 125 | + } |
| 126 | +} |
0 commit comments