コード例 #1
0
  @Test
  public void testGetSides() {
    Recipe side = new Recipe(2, 1, "Test Side", 4, 100, true, null, "", null);
    List<Recipe> list = svc.getRecipeList();
    testRecipe.addSide(side);
    list.add(side);
    try {
      OutputStream out = new FileOutputStream(svc.getPath() + "recipes.dat");
      OutputStream buffer = new BufferedOutputStream(out);
      ObjectOutput output = new ObjectOutputStream(buffer);
      try {
        output.writeObject(list);
      } finally {
        output.close();
      }
    } catch (IOException ex) {
      ex.printStackTrace();
    }
    addTestRecipe();

    List<Recipe> expected = new ArrayList();
    list = svc.getRecipeList();
    for (Recipe recipe : list) {
      if (recipe.getId() == side.getId()) {
        expected.add(recipe);
      }
    }
    List<Recipe> actual = svc.getSides(testRecipe);
    assertEquals(expected, actual);

    deleteRecipe(side);
  }
コード例 #2
0
 private void deleteRecipe(Recipe recipe) {
   List<Recipe> list = svc.getRecipeList();
   for (Recipe r : list) {
     if (recipe.getId() == recipe.getId()) {
       list.remove(r);
       break;
     }
   }
   svc.writeToFile(list);
 }
コード例 #3
0
 @Test
 public void testDelete() {
   addTestRecipe();
   svc.delete(testRecipe);
   Recipe actual = null;
   List<Recipe> list = svc.getRecipeList();
   for (Recipe recipe : list) {
     if (recipe.getId() == testRecipe.getId()) {
       actual = recipe;
       break;
     }
   }
   assertNull(actual);
 }
コード例 #4
0
 @Test
 public void testEdit() {
   addTestRecipe();
   Recipe expected = testRecipe;
   expected.setName("Edited Recipe");
   svc.edit(expected);
   Recipe actual = null;
   List<Recipe> list = svc.getRecipeList();
   for (Recipe recipe : list) {
     if (recipe.getId() == testRecipe.getId()) {
       actual = recipe;
     }
   }
   assertEquals(expected, actual);
 }
コード例 #5
0
  @Test
  public void removeDeletedSideFromRecipe_Pass() {
    Recipe side = new Recipe(2, 1, "Test Side", 4, 100, true, null, "", null);
    List<Recipe> list = svc.getRecipeList();
    testRecipe.addSide(side);
    list.add(side);
    try {
      OutputStream out = new FileOutputStream(svc.getPath() + "recipes.dat");
      OutputStream buffer = new BufferedOutputStream(out);
      ObjectOutput output = new ObjectOutputStream(buffer);
      try {
        output.writeObject(list);
      } finally {
        output.close();
      }
    } catch (IOException ex) {
      ex.printStackTrace();
    }
    addTestRecipe();
    deleteRecipe(side);

    int expected = 0;
    int actual = svc.getSides(testRecipe).size();

    assertEquals(expected, actual);
  }
コード例 #6
0
 @Test
 public void testRemoveIngredient() {
   addTestRecipe();
   Ingredient remove = new Ingredient(.5, Measurements.tsp, "Sugar");
   svc.removeIngredient(testRecipe, remove);
   testRecipe.removeIngredient(remove);
   Recipe actual = null;
   List<Recipe> list = svc.getRecipeList();
   for (Recipe recipe : list) {
     if (recipe.getId() == testRecipe.getId()) {
       actual = recipe;
       break;
     }
   }
   assertEquals(actual, testRecipe);
 }
コード例 #7
0
 @Test
 public void testCreate() {
   try {
     svc.create(testRecipe);
   } catch (IdAlreadyExistsException e) {
     System.out.println("Recipe ID already exists");
     fail();
   }
   Recipe actual = null;
   List<Recipe> list = svc.getRecipeList();
   for (Recipe recipe : list) {
     if (recipe.getId() == testRecipe.getId()) {
       actual = recipe;
     }
     assertNotNull(actual);
   }
 }
コード例 #8
0
  @Test
  public void testAddIngredient() {
    addTestRecipe();
    Ingredient add = new Ingredient(1, Measurements.tbsp, "Olive Oil");
    svc.addIngredient(testRecipe, add);
    testRecipe.addIngredient(add);
    Recipe actual = null;

    List<Recipe> list = svc.getRecipeList();
    for (Recipe recipe : list) {
      if (recipe.getId() == testRecipe.getId()) {
        actual = recipe;
        break;
      }
    }
    assertEquals(testRecipe, actual);
  }
コード例 #9
0
 @Test
 public void testFind() {
   addTestRecipe();
   Recipe actual = null;
   try {
     actual = (Recipe) svc.find(testRecipe.getId());
   } catch (RecipeNotFoundException e) {
     fail();
   }
   assertEquals(testRecipe, actual);
 }
コード例 #10
0
  @Test
  public void testAddSide() {
    addTestRecipe();
    Recipe side = new Recipe(2, 1, "Test Side", 4, 100, true, null, "", null);
    List<Recipe> list = svc.getRecipeList();

    svc.addSide(testRecipe, side);
    testRecipe.addSide(side);

    int actual = 0;
    list = svc.getRecipeList();
    for (Recipe recipe : list) {
      if (recipe.getId() == testRecipe.getId()) {
        actual = recipe.getSides().get(0);
        break;
      }
    }

    assertEquals(side.getId(), actual);
    testRecipe.setSides(null);
  }
コード例 #11
0
  @Test
  public void testRemoveSide() {
    Recipe side = new Recipe(2, 1, "Test Side", 4, 100, true, null, "", null);
    testRecipe.addSide(side);
    addTestRecipe();
    svc.removeSide(testRecipe, side);

    Recipe actual = null;
    List<Recipe> list = svc.getRecipeList();
    for (Recipe recipe : list) {
      if (recipe.getId() == testRecipe.getId()) {
        actual = recipe;
        break;
      }
    }

    assertEquals(0, actual.getSides().size());
    testRecipe.setSides(null);
  }
コード例 #12
0
 @Test
 public void testGetIngredients() {
   addTestRecipe();
   assertEquals(svc.getIngredients(testRecipe), testRecipe.getIngredients());
 }