package pl.mycalories.model;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import pl.mycalories.CalorieeCApplication;

import java.util.HashSet;
import java.util.Set;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = CalorieeCApplication.class)
@WebAppConfiguration
public class MealNutritionalValuesTest {

    private Meal meal;

    @Before
    public void setUp() {
        meal = new Meal();
        meal.setId(1L);
        meal.setName("test meal");
        meal.setProductMeals(addProductMeal());
        meal.setNutritionalValues(new NutritionalValues(meal));
    }

    @Test
    public void sumMacroTest() {
        Assert.assertEquals(1250, meal.getNutritionalValues().getCalories());
        Assert.assertEquals(250, meal.getNutritionalValues().getCarbs());
        Assert.assertEquals(500, meal.getNutritionalValues().getProteins());
        Assert.assertEquals(750, meal.getNutritionalValues().getFats());
    }


    private Set<ProductMeal> addProductMeal() {
        ProductMeal firstProduct = getProductMeal(10);
        ProductMeal secondProduct = getProductMeal(15);

        Set<ProductMeal> productMeals = new HashSet<>();
        productMeals.add(firstProduct);
        productMeals.add(secondProduct);

        return productMeals;
    }

    private ProductMeal getProductMeal(int quantity) {
        ProductMeal productMeal = new ProductMeal();
        productMeal.setAmount(quantity);
        productMeal.setProduct(getProduct());

        return productMeal;
    }

    private Product getProduct() {
        Product product = new Product();
        product.setId(1L);
        product.setName("test product");
        product.setNutritionalValues(new NutritionalValues(50, 20, 30, 10));

        return product;
    }
}

@@ -633,13 +633,12 @@
 oid 
-setUp
+init
 () %7B
@@ -882,102 +882,468 @@
 oid 
-sumMacroTest() %7B%0D%0A        Assert.assertEquals(1250, meal.getNutritionalValues().getCalories())
+macros_are_match() %7B%0D%0A        NutritionalValues expectedMacro = new NutritionalValues(1250, 500, 750, 250);%0D%0A        Assert.assertEquals(expectedMacro, meal.getNutritionalValues());%0D%0A    %7D%0D%0A%0D%0A    @Test%0D%0A    public void calories_are_match() %7B%0D%0A        int expectedCalories = 1250;%0D%0A        Assert.assertEquals(expectedCalories, meal.getNutritionalValues().getCalories());%0D%0A    %7D%0D%0A%0D%0A    @Test%0D%0A    public void carbs_are_match() %7B%0D%0A        int expectedCarbs = 250
 ;%0D%0A 
@@ -1369,19 +1369,29 @@
 tEquals(
-250
+expectedCarbs
 , meal.g
@@ -1422,24 +1422,121 @@
 tCarbs());%0D%0A
+    %7D%0D%0A%0D%0A    @Test%0D%0A    public void proteins_are_match() %7B%0D%0A        int expectedProteins = 500;%0D%0A
         Asse
@@ -1551,19 +1551,32 @@
 tEquals(
-500
+expectedProteins
 , meal.g
@@ -1610,24 +1610,113 @@
 oteins());%0D%0A
+    %7D%0D%0A%0D%0A    @Test%0D%0A    public void fats_are_match() %7B%0D%0A        int expectedFats = 750;%0D%0A
         Asse
@@ -1731,19 +1731,28 @@
 tEquals(
-750
+expectedFats
 , meal.g

add test cases to check all macros independent