-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
494 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
backend/src/test/java/com/group1/cuisines/DishControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.group1.cuisines; | ||
|
||
import com.group1.cuisines.controllers.DishController; | ||
import com.group1.cuisines.dao.response.ErrorResponse; | ||
import com.group1.cuisines.dao.response.SuccessResponse; | ||
import com.group1.cuisines.dto.DishDto; | ||
import com.group1.cuisines.services.DishService; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class DishControllerTest { | ||
|
||
@InjectMocks | ||
private DishController dishController; | ||
|
||
@Mock | ||
private DishService dishService; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@Test | ||
public void testGetDishById_Found() { | ||
String dishId = "test-id"; | ||
DishDto mockDish = DishDto.builder() | ||
.id(dishId) | ||
.name("Test Dish") | ||
.description("Delicious dish") | ||
.image("./image.jpg") | ||
.countries("USA") | ||
.ingredients("Ingredients") | ||
.foodTypes("Type") | ||
.cuisines("Cuisine") | ||
.build(); | ||
|
||
when(dishService.getDishById(dishId)).thenReturn(mockDish); | ||
|
||
SuccessResponse<DishDto> response = (SuccessResponse<DishDto>) dishController.getDishById(dishId).getBody(); | ||
|
||
DishDto actualDish = response.getData(); | ||
|
||
assertEquals(200, response.getStatus()); | ||
assertEquals(mockDish, actualDish); | ||
} | ||
|
||
@Test | ||
public void testGetDishById_NotFound() { | ||
String dishId = "test-id"; | ||
when(dishService.getDishById(dishId)).thenReturn(null); | ||
|
||
ErrorResponse response = (ErrorResponse) dishController.getDishById(dishId).getBody(); | ||
|
||
assertEquals(400, response.getStatus()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.