Refactored recipe controller to use services
This commit is contained in:
parent
0050671944
commit
e9b6d81a27
2 changed files with 36 additions and 84 deletions
|
|
@ -13,9 +13,8 @@ import org.springframework.http.HttpStatus;
|
|||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import server.WebSocketConfig;
|
||||
import server.database.IngredientRepository;
|
||||
import server.database.RecipeIngredientRepository;
|
||||
import server.database.RecipeRepository;
|
||||
import server.service.RecipeService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -38,30 +37,27 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
// This is required to enable WebSocket messaging in tests
|
||||
//
|
||||
// Without this line, Spring screams about missing SimpMessagingTemplate bean
|
||||
@Import(WebSocketConfig.class)
|
||||
@Import({WebSocketConfig.class, RecipeService.class})
|
||||
public class RecipeControllerTest {
|
||||
|
||||
private final RecipeService recipeService;
|
||||
private final RecipeRepository recipeRepository;
|
||||
private final SimpMessagingTemplate template;
|
||||
private RecipeController controller;
|
||||
|
||||
private List<Recipe> recipes;
|
||||
private final RecipeRepository recipeRepository;
|
||||
private List<Long> recipeIds;
|
||||
public static final int NUM_RECIPES = 10;
|
||||
private final IngredientRepository ingredientRepository;
|
||||
private final RecipeIngredientRepository recipeIngredientRepository;
|
||||
|
||||
// Injects a test repository into the test class
|
||||
@Autowired
|
||||
public RecipeControllerTest(
|
||||
RecipeService recipeService,
|
||||
RecipeRepository recipeRepository,
|
||||
SimpMessagingTemplate template,
|
||||
IngredientRepository ingredientRepository,
|
||||
RecipeIngredientRepository recipeIngredientRepository
|
||||
SimpMessagingTemplate template
|
||||
) {
|
||||
this.recipeService = recipeService;
|
||||
this.recipeRepository = recipeRepository;
|
||||
this.template = template;
|
||||
this.ingredientRepository = ingredientRepository;
|
||||
this.recipeIngredientRepository = recipeIngredientRepository;
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
|
|
@ -71,10 +67,8 @@ public class RecipeControllerTest {
|
|||
.mapToObj(x -> new Recipe(null, "Recipe " + x, List.of(), List.of()))
|
||||
.toList();
|
||||
controller = new RecipeController(
|
||||
recipeRepository,
|
||||
template,
|
||||
ingredientRepository,
|
||||
recipeIngredientRepository
|
||||
recipeService,
|
||||
template
|
||||
);
|
||||
Set<String> tags = info.getTags();
|
||||
List<Long> ids = new ArrayList<>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue