-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
Copy pathIngredientCommandToIngredientTest.java
85 lines (66 loc) · 2.65 KB
/
IngredientCommandToIngredientTest.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.commands.UnitOfMeasureCommand;
import guru.springframework.domain.Ingredient;
import guru.springframework.domain.Recipe;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import static org.junit.jupiter.api.Assertions.*;
public class IngredientCommandToIngredientTest {
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 ID_VALUE = new Long(1L);
public static final Long UOM_ID = new Long(2L);
IngredientCommandToIngredient converter;
@BeforeEach
public void setUp() throws Exception {
converter = new IngredientCommandToIngredient(new UnitOfMeasureCommandToUnitOfMeasure());
}
@Test
public void testNullObject() throws Exception {
assertNull(converter.convert(null));
}
@Test
public void testEmptyObject() throws Exception {
assertNotNull(converter.convert(new IngredientCommand()));
}
@Test
public void convert() throws Exception {
//given
IngredientCommand command = new IngredientCommand();
command.setId(ID_VALUE);
command.setAmount(AMOUNT);
command.setDescription(DESCRIPTION);
UnitOfMeasureCommand unitOfMeasureCommand = new UnitOfMeasureCommand();
unitOfMeasureCommand.setId(UOM_ID);
command.setUom(unitOfMeasureCommand);
//when
Ingredient ingredient = converter.convert(command);
//then
assertNotNull(ingredient);
assertNotNull(ingredient.getUom());
assertEquals(ID_VALUE, ingredient.getId());
assertEquals(AMOUNT, ingredient.getAmount());
assertEquals(DESCRIPTION, ingredient.getDescription());
assertEquals(UOM_ID, ingredient.getUom().getId());
}
@Test
public void convertWithNullUOM() throws Exception {
//given
IngredientCommand command = new IngredientCommand();
command.setId(ID_VALUE);
command.setAmount(AMOUNT);
command.setDescription(DESCRIPTION);
UnitOfMeasureCommand unitOfMeasureCommand = new UnitOfMeasureCommand();
//when
Ingredient ingredient = converter.convert(command);
//then
assertNotNull(ingredient);
assertNull(ingredient.getUom());
assertEquals(ID_VALUE, ingredient.getId());
assertEquals(AMOUNT, ingredient.getAmount());
assertEquals(DESCRIPTION, ingredient.getDescription());
}
}