-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
Copy pathRecipeCommandToRecipeTest.java
105 lines (85 loc) · 3.78 KB
/
RecipeCommandToRecipeTest.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package guru.springframework.converters;
import guru.springframework.commands.CategoryCommand;
import guru.springframework.commands.IngredientCommand;
import guru.springframework.commands.NotesCommand;
import guru.springframework.commands.RecipeCommand;
import guru.springframework.domain.Difficulty;
import guru.springframework.domain.Recipe;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class RecipeCommandToRecipeTest {
public static final Long RECIPE_ID = 1L;
public static final Integer COOK_TIME = Integer.valueOf("5");
public static final Integer PREP_TIME = Integer.valueOf("7");
public static final String DESCRIPTION = "My Recipe";
public static final String DIRECTIONS = "Directions";
public static final Difficulty DIFFICULTY = Difficulty.EASY;
public static final Integer SERVINGS = Integer.valueOf("3");
public static final String SOURCE = "Source";
public static final String URL = "Some URL";
public static final Long CAT_ID_1 = 1L;
public static final Long CAT_ID2 = 2L;
public static final Long INGRED_ID_1 = 3L;
public static final Long INGRED_ID_2 = 4L;
public static final Long NOTES_ID = 9L;
RecipeCommandToRecipe converter;
@BeforeEach
public void setUp() throws Exception {
converter = new RecipeCommandToRecipe(new CategoryCommandToCategory(),
new IngredientCommandToIngredient(new UnitOfMeasureCommandToUnitOfMeasure()),
new NotesCommandToNotes());
}
@Test
public void testNullObject() throws Exception {
assertNull(converter.convert(null));
}
@Test
public void testEmptyObject() throws Exception {
assertNotNull(converter.convert(new RecipeCommand()));
}
@Test
public void convert() throws Exception {
//given
RecipeCommand recipeCommand = new RecipeCommand();
recipeCommand.setId(RECIPE_ID);
recipeCommand.setCookTime(COOK_TIME);
recipeCommand.setPrepTime(PREP_TIME);
recipeCommand.setDescription(DESCRIPTION);
recipeCommand.setDifficulty(DIFFICULTY);
recipeCommand.setDirections(DIRECTIONS);
recipeCommand.setServings(SERVINGS);
recipeCommand.setSource(SOURCE);
recipeCommand.setUrl(URL);
NotesCommand notes = new NotesCommand();
notes.setId(NOTES_ID);
recipeCommand.setNotes(notes);
CategoryCommand category = new CategoryCommand();
category.setId(CAT_ID_1);
CategoryCommand category2 = new CategoryCommand();
category2.setId(CAT_ID2);
recipeCommand.getCategories().add(category);
recipeCommand.getCategories().add(category2);
IngredientCommand ingredient = new IngredientCommand();
ingredient.setId(INGRED_ID_1);
IngredientCommand ingredient2 = new IngredientCommand();
ingredient2.setId(INGRED_ID_2);
recipeCommand.getIngredients().add(ingredient);
recipeCommand.getIngredients().add(ingredient2);
//when
Recipe recipe = converter.convert(recipeCommand);
assertNotNull(recipe);
assertEquals(RECIPE_ID, recipe.getId());
assertEquals(COOK_TIME, recipe.getCookTime());
assertEquals(PREP_TIME, recipe.getPrepTime());
assertEquals(DESCRIPTION, recipe.getDescription());
assertEquals(DIFFICULTY, recipe.getDifficulty());
assertEquals(DIRECTIONS, recipe.getDirections());
assertEquals(SERVINGS, recipe.getServings());
assertEquals(SOURCE, recipe.getSource());
assertEquals(URL, recipe.getUrl());
assertEquals(NOTES_ID, recipe.getNotes().getId());
assertEquals(2, recipe.getCategories().size());
assertEquals(2, recipe.getIngredients().size());
}
}