Cook book written in Java
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.9 KiB

10 years ago
  1. package ksiazka.kucharska;
  2. import static org.junit.Assert.*;
  3. import java.io.File;
  4. import ksiazka.kucharska.CB_View;
  5. import org.junit.AfterClass;
  6. import org.junit.BeforeClass;
  7. import org.junit.Test;
  8. import db.Cookbook;
  9. public class ViewRecipeTest {
  10. static CB_View theView;
  11. static CB_Model theModel;
  12. static CB_Controller theController;
  13. @BeforeClass
  14. public static void addExamples()
  15. {
  16. theView = new CB_View();
  17. theModel = new CB_Model();
  18. theController = new CB_Controller(theView, theModel);
  19. File f1 = new File("cookbook.db");
  20. File f2 = new File("cookbook-bkp.db");
  21. if (f1.exists())
  22. f1.renameTo(f2);
  23. Cookbook myCb = new Cookbook();
  24. RecipeManager rm = new RecipeManager();
  25. rm.setRecipeBuilder(new ExampleRecipeBuilder(theView));
  26. rm.constructRecipe();
  27. CB_Model obj = rm.getRecipe();
  28. myCb.insertRecipe(obj);
  29. theView.setRecipesListItem(obj.getName());
  30. myCb.closeConnection();
  31. }
  32. @SuppressWarnings("static-access")
  33. @Test
  34. public void testView() {
  35. theView.getRecipesList().setSelectedIndex(theView.getRecipesList().getModel().getSize()-1);
  36. theController.fillComponents(theView.getRecipesList().getSelectedValue().toString());
  37. RecipeManager rm = new RecipeManager();
  38. rm.setRecipeBuilder(new ExampleRecipeBuilder(theView));
  39. rm.constructRecipe();
  40. CB_Model testObj = rm.getRecipe();
  41. assertEquals(testObj.getName(), theView.getRecipeTitle());
  42. assertEquals(testObj.getIngredients(), theView.getRecipeIngredients());
  43. assertEquals(testObj.getDescription(), theView.getRecipeDescription());
  44. assertEquals(testObj.getTags(), theView.getRecipeTags());
  45. }
  46. @AfterClass
  47. public static void delExamples()
  48. {
  49. Cookbook myCb = new Cookbook();
  50. myCb.deleteRecipe("Kanapka");
  51. myCb.closeConnection();
  52. File f1 = new File("cookbook.db");
  53. File f2 = new File("cookbook-bkp.db");
  54. f1.delete();
  55. if (f2.exists())
  56. f2.renameTo(f1);
  57. }
  58. }