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.

69 lines
1.3 KiB

10 years ago
  1. package ksiazka.kucharska;
  2. import static org.junit.Assert.*;
  3. import java.io.File;
  4. import java.util.List;
  5. import ksiazka.kucharska.CB_View;
  6. import org.junit.AfterClass;
  7. import org.junit.BeforeClass;
  8. import org.junit.Test;
  9. import db.Cookbook;
  10. import db.SearchRecipe;
  11. import db.SearchRecipeAll;
  12. public class SearchTest {
  13. @BeforeClass
  14. public static void addExamples()
  15. {
  16. File f1 = new File("cookbook.db");
  17. File f2 = new File("cookbook-bkp.db");
  18. if (f1.exists())
  19. f1.renameTo(f2);
  20. Cookbook myCb = new Cookbook();
  21. CB_View theView = new CB_View();
  22. RecipeManager rm = new RecipeManager();
  23. rm.setRecipeBuilder(new ExampleRecipeBuilder(theView));
  24. rm.constructRecipe();
  25. CB_Model obj = rm.getRecipe();
  26. myCb.insertRecipe(obj);
  27. myCb.insertRecipe(obj);
  28. myCb.closeConnection();
  29. }
  30. @Test
  31. public void testSearch() {
  32. CB_View theView = new CB_View();
  33. Cookbook myCb = new Cookbook();
  34. SearchRecipe sr;
  35. sr = new SearchRecipeAll(theView);
  36. List<String> names = sr.obtainRecipeNames();
  37. myCb.closeConnection();
  38. assertEquals(2, names.size());
  39. }
  40. @AfterClass
  41. public static void delExamples()
  42. {
  43. Cookbook myCb = new Cookbook();
  44. myCb.deleteRecipe("Kanapka");
  45. myCb.closeConnection();
  46. File f1 = new File("cookbook.db");
  47. File f2 = new File("cookbook-bkp.db");
  48. f1.delete();
  49. if (f2.exists())
  50. f2.renameTo(f1);
  51. }
  52. }