-
Notifications
You must be signed in to change notification settings - Fork 0
/
RestaurantTest.java
65 lines (53 loc) · 2.68 KB
/
RestaurantTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.time.LocalTime;
import static org.junit.jupiter.api.Assertions.*;
class RestaurantTest {
Restaurant restaurant;
//REFACTOR ALL THE REPEATED LINES OF CODE
//>>>>>>>>>>>>>>>>>>>>>>>>>OPEN/CLOSED<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
//-------FOR THE 2 TESTS BELOW, YOU MAY USE THE CONCEPT OF MOCKING, IF YOU RUN INTO ANY TROUBLE
@Test
public void is_restaurant_open_should_return_true_if_time_is_between_opening_and_closing_time(){
//WRITE UNIT TEST CASE HERE
}
@Test
public void is_restaurant_open_should_return_false_if_time_is_outside_opening_and_closing_time(){
//WRITE UNIT TEST CASE HERE
}
//<<<<<<<<<<<<<<<<<<<<<<<<<OPEN/CLOSED>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>MENU<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@Test
public void adding_item_to_menu_should_increase_menu_size_by_1(){
LocalTime openingTime = LocalTime.parse("10:30:00");
LocalTime closingTime = LocalTime.parse("22:00:00");
restaurant =new Restaurant("Amelie's cafe","Chennai",openingTime,closingTime);
restaurant.addToMenu("Sweet corn soup",119);
restaurant.addToMenu("Vegetable lasagne", 269);
int initialMenuSize = restaurant.getMenu().size();
restaurant.addToMenu("Sizzling brownie",319);
assertEquals(initialMenuSize+1,restaurant.getMenu().size());
}
@Test
public void removing_item_from_menu_should_decrease_menu_size_by_1() throws itemNotFoundException {
LocalTime openingTime = LocalTime.parse("10:30:00");
LocalTime closingTime = LocalTime.parse("22:00:00");
restaurant =new Restaurant("Amelie's cafe","Chennai",openingTime,closingTime);
restaurant.addToMenu("Sweet corn soup",119);
restaurant.addToMenu("Vegetable lasagne", 269);
int initialMenuSize = restaurant.getMenu().size();
restaurant.removeFromMenu("Vegetable lasagne");
assertEquals(initialMenuSize-1,restaurant.getMenu().size());
}
@Test
public void removing_item_that_does_not_exist_should_throw_exception() {
LocalTime openingTime = LocalTime.parse("10:30:00");
LocalTime closingTime = LocalTime.parse("22:00:00");
restaurant =new Restaurant("Amelie's cafe","Chennai",openingTime,closingTime);
restaurant.addToMenu("Sweet corn soup",119);
restaurant.addToMenu("Vegetable lasagne", 269);
assertThrows(itemNotFoundException.class,
()->restaurant.removeFromMenu("French fries"));
}
//<<<<<<<<<<<<<<<<<<<<<<<MENU>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
}