package ksiazka.kucharska; import static org.junit.Assert.*; import java.io.File; import ksiazka.kucharska.CB_View; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import db.Cookbook; public class ViewRecipeTest { static CB_View theView; static CB_Model theModel; static CB_Controller theController; @BeforeClass public static void addExamples() { theView = new CB_View(); theModel = new CB_Model(); theController = new CB_Controller(theView, theModel); File f1 = new File("cookbook.db"); File f2 = new File("cookbook-bkp.db"); if (f1.exists()) f1.renameTo(f2); Cookbook myCb = new Cookbook(); RecipeManager rm = new RecipeManager(); rm.setRecipeBuilder(new ExampleRecipeBuilder(theView)); rm.constructRecipe(); CB_Model obj = rm.getRecipe(); myCb.insertRecipe(obj); theView.setRecipesListItem(obj.getName()); myCb.closeConnection(); } @SuppressWarnings("static-access") @Test public void testView() { theView.getRecipesList().setSelectedIndex(theView.getRecipesList().getModel().getSize()-1); theController.fillComponents(theView.getRecipesList().getSelectedValue().toString()); RecipeManager rm = new RecipeManager(); rm.setRecipeBuilder(new ExampleRecipeBuilder(theView)); rm.constructRecipe(); CB_Model testObj = rm.getRecipe(); assertEquals(testObj.getName(), theView.getRecipeTitle()); assertEquals(testObj.getIngredients(), theView.getRecipeIngredients()); assertEquals(testObj.getDescription(), theView.getRecipeDescription()); assertEquals(testObj.getTags(), theView.getRecipeTags()); } @AfterClass public static void delExamples() { Cookbook myCb = new Cookbook(); myCb.deleteRecipe("Kanapka"); myCb.closeConnection(); File f1 = new File("cookbook.db"); File f2 = new File("cookbook-bkp.db"); f1.delete(); if (f2.exists()) f2.renameTo(f1); } }