|
@@ -0,0 +1,96 @@
|
|
|
|
|
+package org.leumasjaffe.recipe.model;
|
|
|
|
|
+
|
|
|
|
|
+import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
|
+import static org.hamcrest.MatcherAssert.*;
|
|
|
|
|
+import static org.hamcrest.core.Is.*;
|
|
|
|
|
+import static org.hamcrest.core.IsCollectionContaining.*;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Arrays;
|
|
|
|
|
+import java.util.Optional;
|
|
|
|
|
+
|
|
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
|
|
+
|
|
|
|
|
+class CardTest {
|
|
|
|
|
+ private static final Amount _1g = new Amount("1 g");
|
|
|
|
|
+ private static final Duration dur = new Duration(Duration.Display.SECONDS, false, 10, 20);
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void cannotAddNullPreparation() {
|
|
|
|
|
+ final Card card = new Card();
|
|
|
|
|
+ assertThrows(NullPointerException.class, () -> card.setPreparation(null));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void testDurationIsZeroByDefault() {
|
|
|
|
|
+ final Card card = new Card();
|
|
|
|
|
+ assertEquals(Duration.ZERO, card.getDuration());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void testSumsTogetherStepDurations() {
|
|
|
|
|
+ final Card card = new Card();
|
|
|
|
|
+ final Step step = new Step();
|
|
|
|
|
+ step.setDuration(dur);
|
|
|
|
|
+ card.setCooking(Arrays.asList(step, step));
|
|
|
|
|
+ assertEquals(new Duration(Duration.Display.SECONDS, false, 20, 40),
|
|
|
|
|
+ card.getDuration());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void testDoesNotAddPrepDurationIfPresent() {
|
|
|
|
|
+ final Card card = new Card();
|
|
|
|
|
+ final Preparation prep = new Preparation();
|
|
|
|
|
+ prep.setDuration(dur);
|
|
|
|
|
+ card.setPreparation(prep);
|
|
|
|
|
+ assertEquals(Duration.ZERO, card.getDuration());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void testDoesNotAddRestDurationIfPresent() {
|
|
|
|
|
+ final Card card = new Card();
|
|
|
|
|
+ final Rest rest = new Rest();
|
|
|
|
|
+ rest.setWhere(Rest.Where.REFRIGERATOR);
|
|
|
|
|
+ rest.setDuration(dur);
|
|
|
|
|
+ card.setRest(Optional.of(rest));
|
|
|
|
|
+ assertEquals(Duration.ZERO, card.getDuration());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void testMergesLikeIngredients() {
|
|
|
|
|
+ final Card card = new Card();
|
|
|
|
|
+ final Step step = new Step();
|
|
|
|
|
+ step.setIngredients(Arrays.asList(new Ingredient("TEST", "", _1g)));
|
|
|
|
|
+ card.setCooking(Arrays.asList(step, step));
|
|
|
|
|
+ // TODO Figure out why hamcrest-all isn't loading...
|
|
|
|
|
+ assertThat(card.getIngredients().size(), is(1));
|
|
|
|
|
+ assertThat(card.getIngredients(),
|
|
|
|
|
+ hasItem(new Ingredient("TEST", "", new Amount("2 g"))));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void testDoesNotMergeIngredientsWithDifferentPrep() {
|
|
|
|
|
+ final Card card = new Card();
|
|
|
|
|
+ final Step step = new Step();
|
|
|
|
|
+ step.setIngredients(Arrays.asList(
|
|
|
|
|
+ new Ingredient("TEST", "A", _1g),
|
|
|
|
|
+ new Ingredient("TEST", "B", _1g)));
|
|
|
|
|
+ card.setCooking(Arrays.asList(step));
|
|
|
|
|
+ // TODO Figure out why hamcrest-all isn't loading...
|
|
|
|
|
+ assertThat(card.getIngredients().size(), is(2));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void testPrepIngredientsAreCardIngredientsWithPrep() {
|
|
|
|
|
+ final Card card = new Card();
|
|
|
|
|
+ final Step step = new Step();
|
|
|
|
|
+ step.setIngredients(Arrays.asList(
|
|
|
|
|
+ new Ingredient("A", "", _1g),
|
|
|
|
|
+ new Ingredient("B", "TEST", _1g)));
|
|
|
|
|
+ card.setCooking(Arrays.asList(step));
|
|
|
|
|
+ card.setPreparation(new Preparation());
|
|
|
|
|
+ assertThat(card.getIngredients().size(), is(2));
|
|
|
|
|
+ final Preparation prep = card.getPreparation().get();
|
|
|
|
|
+ assertThat(prep.getIngredients().size(), is(1));
|
|
|
|
|
+ assertThat(prep.getIngredients(), hasItem(new Ingredient("B", "TEST", _1g)));
|
|
|
|
|
+ }
|
|
|
|
|
+}
|