Skip to content

Commit

Permalink
Added Test to Feature 15
Browse files Browse the repository at this point in the history
  • Loading branch information
efentress2025 committed Dec 6, 2023
1 parent ebef751 commit 530787a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/cse/gradle/local/login.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
abc
abc
bob2000
2000
41 changes: 41 additions & 0 deletions app/src/test/java/cse/gradle/Feature15Tests.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cse.gradle;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.List;

Expand Down Expand Up @@ -71,6 +72,46 @@ public void getRecipeListAToZTest() {
// System.out.println(recipeArrayList.get(1).getName());
assert(recipeArrayList.get(1).getName().equals("boiled potatoes"));
assert(recipeArrayList.get(2).getName().equals("Healthy Lunch"));
}

@Test
public void getRecipeListZToATest() {

// Create a new List<Recipe> with 3 recipes
List<Recipe> recipes = new ArrayList<Recipe>();

recipes.add(new Recipe("eggs, bacon", "cook for 10 minutes", "breakfast", "American breakfast"));
recipes.add(new Recipe("salmon, salad", "cook for 20 minutes", "lunch", "Healthy Lunch"));
recipes.add(new Recipe("potatoes", "boil the potatoes", "brunch", "boiled potatoes"));


// Create a new Mock Model that accesses test_user in the database
Model model = new MockModel();

// Add the recipes to the database
for (Recipe recipe : recipes) {
model.postRecipe(recipe);
}

// Get all the recipes from the database sorted alphabetically A-Z (not case sensitive)
String getAllResponse = model.getRecipeList("z-a", "");

// Delete the recipes from the database
for (Recipe recipe : recipes) {
model.deleteRecipe(recipe.getId().toString());
}

// Parse the getAllResponse into a List<Recipe>
List<Recipe> recipeArrayList = Recipe.parseRecipeListFromString(getAllResponse);

System.out.println("recipeArrayList: " + recipeArrayList);

// Check that the recieved recipes are sorted alphabetically A-Z (not case sensitive)
assertEquals(3, recipeArrayList.size());
assert(recipeArrayList.get(2).getName().equals("American breakfast"));
// System.out.println(recipeArrayList.get(1).getName());
assert(recipeArrayList.get(1).getName().equals("boiled potatoes"));
assert(recipeArrayList.get(0).getName().equals("Healthy Lunch"));

}
}

0 comments on commit 530787a

Please sign in to comment.