package guittests;

import static java.nio.file.Files.readAllBytes;
import static java.util.Optional.of;
import static mealplaner.commons.NonnegativeInteger.nonNegative;
import static mealplaner.model.Meal.createMeal;
import static mealplaner.recipes.model.Ingredient.ingredient;
import static mealplaner.recipes.model.IngredientType.SPICE;
import static mealplaner.recipes.model.Measure.NONE;
import static org.assertj.core.api.Assertions.assertThat;
import static testcommons.CommonFunctions.getRecipe1;

import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

import org.assertj.swing.fixture.DialogFixture;
import org.junit.Test;

import guittests.helpers.AssertJMealplanerTestCase;
import mealplaner.model.Meal;
import mealplaner.model.enums.CookingPreference;
import mealplaner.model.enums.CookingTime;
import mealplaner.model.enums.ObligatoryUtensil;
import mealplaner.model.enums.Sidedish;
import mealplaner.recipes.model.Ingredient;

public class MenuItemsTest extends AssertJMealplanerTestCase {

  @Test
  public void createMenu() {
    Meal meal1 = createMeal("Bla", CookingTime.LONG, Sidedish.PASTA, ObligatoryUtensil.CASSEROLE,
        CookingPreference.RARE, nonNegative(2), "No comment", of(getRecipe1()));
    windowHelpers.enterMealFromMenu(meal1);
    List<Meal> meals = new ArrayList<>();
    meals.add(meal1);
    windowHelpers.compareDatabaseInTable(meals);
    window.close();
  }

  @Test
  public void createIngredient() throws IOException {
    Ingredient ingredient = ingredient("Test4", SPICE, NONE);

    window.menuItem("MenuFile").click();
    window.menuItem("MenuItemInsertIngredients").click();
    DialogFixture enterIngredientDialog = window.dialog();
    enterIngredientDialog.textBox("InputFieldNonemptyTextIngredientName")
        .setText(ingredient.getName());
    enterIngredientDialog.comboBox("InputFieldComboBoxIngredientType")
        .selectItem(ingredient.getType().toString());
    enterIngredientDialog.comboBox("InputFieldComboBoxIngredientMeasure")
        .selectItem(ingredient.getMeasure().toString());
    enterIngredientDialog.button("ButtonPanelIngredientsInput0").click();
    enterIngredientDialog.button("ButtonPanelIngredientsInput1").click();

    assertThat(new String(readAllBytes(Paths.get(DESTINATION_INGREDIENT_FILE_PATH))))
        .isEqualTo(new String(readAllBytes(Paths.get("src/test/resources/ingredientsAdded.xml"))));
  }
}

@@ -54,19 +54,19 @@
 .readAll
-Byt
+Lin
 es;%0Aimpo
@@ -2267,37 +2267,26 @@
 ertThat(
-new String(
 readAll
-Byt
+Lin
 es(Paths
@@ -2325,17 +2325,16 @@
 _PATH)))
-)
 %0A       
@@ -2339,39 +2339,57 @@
    .
-isEqualTo(new String(
+containsExactlyElementsOf(%0A            
 readAll
-Byt
+Lin
 es(P
@@ -2441,17 +2441,16 @@
 .xml%22)))
-)
 ;%0A  %7D%0A%7D%0A

Fix PMD in tests