-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpoonacularEngineTest.java
64 lines (48 loc) · 2.25 KB
/
SpoonacularEngineTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package recipe;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.json.JSONException;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.util.ArrayList;
import java.util.List;
public class SpoonacularEngineTest {
public static SpoonacularEngine mockedSpoonacularEngine;
public static List<FoodRecipe> result = new ArrayList<>();
public static List<AnalyzedRecipe> analyzedRecipe = new ArrayList<>();
static SpoonacularEngine x = new SpoonacularEngine();
@BeforeClass
public static void setUp() throws UnirestException{
mockedSpoonacularEngine = mock(SpoonacularEngine.class);
ArrayList<String> ings = new ArrayList<String>();
ings.add("Pasta");
ings.add("Prawns");
result.add(new FoodRecipe("Gnocchi With Shrimp, Asparagus and Pesto", 527293));
result.add(new FoodRecipe("Roasted Shrimp with Lemon Pasta", 592877));
result.add(new FoodRecipe("Grilled Oregano Shrimp", 5857));
analyzedRecipe = x.getRecipe(527293);
when(mockedSpoonacularEngine.findRecipeByIngredient(ings)).thenReturn(result);
when(mockedSpoonacularEngine.getRecipe(527293)).thenReturn(analyzedRecipe);
}
@Test
public void testFindRecipeByIngredient() throws UnirestException
{
ArrayList<String> ings = new ArrayList<String>();
ings.add("Pasta");
ings.add("Prawns");
List<FoodRecipe> feedback = mockedSpoonacularEngine.findRecipeByIngredient(ings);
assertEquals(3, feedback.size());
FoodRecipe recipeName = feedback.get(0);
assertEquals("Gnocchi With Shrimp, Asparagus and Pesto", recipeName.getTitle());
}
@Test
public void testGetRecipe() throws JSONException, UnirestException {
List<AnalyzedRecipe> analyzedRecipe = new ArrayList<>();
analyzedRecipe = mockedSpoonacularEngine.getRecipe(527293);
System.out.println(analyzedRecipe);
ArrayList<String> sample = analyzedRecipe.get(0).getSteps();
assertEquals("Heat olive oil in a skillet over medium heat.", sample.get(0));
assertEquals("Add asparagus and saute for 3 minutes. Then add shrimp, season everything with salt and (lots of!) freshly ground black pepper, and continue sauteing until shrimp are cooked (pink and no longer translucent).", sample.get(1));
}
}