레스토랑 예약 사이트 만들기 7 - 멀티모듈

dependencies {
implementation project(':eatgo-common')

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-validation
implementation 'org.springframework.boot:spring-boot-starter-validation'

compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
jar {
enabled = true
}

bootJar {
enabled = false
}
@Test
public void 레스토랑에_해당되는_메뉴들을_반환한다() {
List<MenuItem> mockMenuItems = new ArrayList<>();
mockMenuItems.add(MenuItem.builder()
.name("Kimchi")
.build());

given(menuItemRepository.findAllByRestaurantId(1004L)).willReturn(mockMenuItems);

List<MenuItem> menuItems = menuItemService.getMenuItems(1004L);
MenuItem menuItem = menuItems.get(0);
assertThat(menuItem.getName()).isEqualTo("Kimchi");
}
public List<MenuItem> getMenuItems(Long restaurantId) {
return menuItemRepository.findAllByRestaurantId(restaurantId);
}

리뷰 정보 가져오기

@GetMapping("/reviews")
public List<Review> list(){
List<Review> reviews = reivewService.getReviews();
return reviews;
}
@Test
public void 레스토랑에_해당되는_리뷰들을_가져온다() throws Exception {
List<Review> mockReviews = new ArrayList<>();
mockReviews.add(Review.builder()
.description("Cool!")
.build());

given(reviewService.getReviews()).willReturn(mockReviews);

mockMvc.perform(get("/reviews"))
.andExpect(status().isOk())
.andExpect(content().string(containsString("Cool!")));
}
public List<Review> getReviews() {
return reviewRepository.findAll();
}
@Test
public void 리뷰들을_가져온다(){
List<Review> mockReviews = new ArrayList<>();
mockReviews.add(Review.builder()
.description("Cool!")
.build());

given(reviewRepository.findAll()).willReturn(mockReviews);

List<Review> reviews = reviewService.getReviews();
Review review = reviews.get(0);

assertThat(review.getDescription()).isEqualTo("Cool!");
}
Share