-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
Copy pathIngredientToIngredientCommandTest.java
85 lines (70 loc) · 2.72 KB
/
IngredientToIngredientCommandTest.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
package guru.springframework.converters;
import guru.springframework.commands.IngredientCommand;
import guru.springframework.domain.Ingredient;
import guru.springframework.domain.Recipe;
import guru.springframework.domain.UnitOfMeasure;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import static org.junit.jupiter.api.Assertions.*;
/**
* Created by jt on 6/21/17.
*/
public class IngredientToIngredientCommandTest {
public static final Recipe RECIPE = new Recipe();
public static final BigDecimal AMOUNT = new BigDecimal("1");
public static final String DESCRIPTION = "Cheeseburger";
public static final Long UOM_ID = new Long(2L);
public static final Long ID_VALUE = new Long(1L);
IngredientToIngredientCommand converter;
@BeforeEach
public void setUp() throws Exception {
converter = new IngredientToIngredientCommand(new UnitOfMeasureToUnitOfMeasureCommand());
}
@Test
public void testNullConvert() throws Exception {
assertNull(converter.convert(null));
}
@Test
public void testEmptyObject() throws Exception {
assertNotNull(converter.convert(new Ingredient()));
}
@Test
public void testConvertNullUOM() throws Exception {
//given
Ingredient ingredient = new Ingredient();
ingredient.setId(ID_VALUE);
ingredient.setRecipe(RECIPE);
ingredient.setAmount(AMOUNT);
ingredient.setDescription(DESCRIPTION);
ingredient.setUom(null);
//when
IngredientCommand ingredientCommand = converter.convert(ingredient);
//then
assertNull(ingredientCommand.getUom());
assertEquals(ID_VALUE, ingredientCommand.getId());
assertEquals(AMOUNT, ingredientCommand.getAmount());
assertEquals(DESCRIPTION, ingredientCommand.getDescription());
}
@Test
public void testConvertWithUom() throws Exception {
//given
Ingredient ingredient = new Ingredient();
ingredient.setId(ID_VALUE);
ingredient.setRecipe(RECIPE);
ingredient.setAmount(AMOUNT);
ingredient.setDescription(DESCRIPTION);
UnitOfMeasure uom = new UnitOfMeasure();
uom.setId(UOM_ID);
ingredient.setUom(uom);
//when
IngredientCommand ingredientCommand = converter.convert(ingredient);
//then
assertEquals(ID_VALUE, ingredientCommand.getId());
assertNotNull(ingredientCommand.getUom());
assertEquals(UOM_ID, ingredientCommand.getUom().getId());
// assertEquals(RECIPE, ingredientCommand.get);
assertEquals(AMOUNT, ingredientCommand.getAmount());
assertEquals(DESCRIPTION, ingredientCommand.getDescription());
}
}