@Test public void testRecipeEdit() throws SQLException { Recipe r = RecipeUnitTest.createGenericRecipe("My Recipe", "Kyle Woo", 0, 0, 5, false); Recipe edited_r = RecipeUnitTest.createGenericRecipe("My Recipe", "Kyle Woo", 1, 1, 5, false); Step edited_s = StepUnitTest.createGenericStep(1, 1, 5, false, 0); List<Step> steps = new ArrayList<>(); steps.add(edited_s); mAccessor.storeRecipe(r); mAccessor.checkInvariants(); Recipe result = mAccessor.loadRecipe("My Recipe", "Kyle Woo"); mAccessor.checkInvariants(); assertEquals(r, result); r.setSteps(steps); mAccessor.editRecipe(r); mAccessor.checkInvariants(); result = mAccessor.loadRecipe("My Recipe", "Kyle Woo"); mAccessor.checkInvariants(); assertEquals(edited_r, result); }
/** * Update the meals shown on screen. Shows filtered meals if the user types in the search bar or * shows all the meals if nothing is entered */ private void updateVisibleMeals() { final String query = mSearchView.getQuery().toString(); // Make all meals visible mVisibleRecipes.clear(); if (!query.isEmpty()) { final List<Recipe> filteredRecipes = new ArrayList<>(); // Limit mVisibleMeals to the meals whose titles contain the query // Case insensitive final String lowerQuery = query.toLowerCase(Locale.getDefault()); for (Recipe recipe : mRecipes) { final String lowerTitle = recipe.getTitle().toLowerCase(Locale.getDefault()); if (lowerTitle.contains(lowerQuery)) { filteredRecipes.add(recipe); } } mVisibleRecipes.addAll(filteredRecipes); } else { // Empty query mVisibleRecipes.addAll(mRecipes); } }