-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
Copy pathRecipeToRecipeCommandTest.java
104 lines (83 loc) · 3.43 KB
/
RecipeToRecipeCommandTest.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
package guru.springframework.converters;
import guru.springframework.commands.RecipeCommand;
import guru.springframework.domain.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class RecipeToRecipeCommandTest {
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;
RecipeToRecipeCommand converter;
@BeforeEach
public void setUp() throws Exception {
converter = new RecipeToRecipeCommand(
new CategoryToCategoryCommand(),
new IngredientToIngredientCommand(new UnitOfMeasureToUnitOfMeasureCommand()),
new NotesToNotesCommand());
}
@Test
public void testNullObject() throws Exception {
assertNull(converter.convert(null));
}
@Test
public void testEmptyObject() throws Exception {
assertNotNull(converter.convert(new Recipe()));
}
@Test
public void convert() throws Exception {
//given
Recipe recipe = new Recipe();
recipe.setId(RECIPE_ID);
recipe.setCookTime(COOK_TIME);
recipe.setPrepTime(PREP_TIME);
recipe.setDescription(DESCRIPTION);
recipe.setDifficulty(DIFFICULTY);
recipe.setDirections(DIRECTIONS);
recipe.setServings(SERVINGS);
recipe.setSource(SOURCE);
recipe.setUrl(URL);
Notes notes = new Notes();
notes.setId(NOTES_ID);
recipe.setNotes(notes);
Category category = new Category();
category.setId(CAT_ID_1);
Category category2 = new Category();
category2.setId(CAT_ID2);
recipe.getCategories().add(category);
recipe.getCategories().add(category2);
Ingredient ingredient = new Ingredient();
ingredient.setId(INGRED_ID_1);
Ingredient ingredient2 = new Ingredient();
ingredient2.setId(INGRED_ID_2);
recipe.getIngredients().add(ingredient);
recipe.getIngredients().add(ingredient2);
//when
RecipeCommand command = converter.convert(recipe);
//then
assertNotNull(command);
assertEquals(RECIPE_ID, command.getId());
assertEquals(COOK_TIME, command.getCookTime());
assertEquals(PREP_TIME, command.getPrepTime());
assertEquals(DESCRIPTION, command.getDescription());
assertEquals(DIFFICULTY, command.getDifficulty());
assertEquals(DIRECTIONS, command.getDirections());
assertEquals(SERVINGS, command.getServings());
assertEquals(SOURCE, command.getSource());
assertEquals(URL, command.getUrl());
assertEquals(NOTES_ID, command.getNotes().getId());
assertEquals(2, command.getCategories().size());
assertEquals(2, command.getIngredients().size());
}
}