package edu.ncsu.csc326.coffeemaker;
public interface RecipeBook {
public Recipe[] getRecipes();
public boolean addRecipe(Recipe r);
public String deleteRecipe(int recipeToDelete);
public String editRecipe(int recipeToEdit, Recipe newRecipe);
}
package edu.ncsu.csc326.coffeemaker;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
import org.junit.Before;
import org.junit.Test;
import edu.ncsu.csc326.coffeemaker.exceptions.RecipeException;
public class CoffeeMakerTest {
private Recipe recipe1;
private Recipe recipe2;
private Recipe recipe3;
private Recipe recipe4;
private Recipe recipe5;
private Recipe [] stubRecipies;
private CoffeeMaker coffeeMaker;
private RecipeBook recipeBookStub;
@Before
public void setUp() throws RecipeException {
recipeBookStub = mock(RecipeBook.class); //Getting error for this line of code
coffeeMaker = new CoffeeMaker(recipeBookStub, new Inventory());
//Set up for recipe1
recipe1 = new Recipe();
recipe1.setName("Coffee");
recipe1.setAmtChocolate("0");
recipe1.setAmtCoffee("3");
recipe1.setAmtMilk("1");
recipe1.setAmtSugar("1");
recipe1.setPrice("50");
//Set up for recipe2
recipe2 = new Recipe();
recipe2.setName("Mocha");
recipe2.setAmtChocolate("20");
recipe2.setAmtCoffee("3");
recipe2.setAmtMilk("1");
recipe2.setAmtSugar("1");
recipe2.setPrice("75");
stubRecipies = new Recipe [] {recipe1, recipe2, recipe3};
}
@Test
public void testMakeCoffee() {
when(recipeBookStub.getRecipes()).thenReturn(stubRecipies);
coffeeMaker.addRecipe(stubRecipies[0]);
assertEquals(10,coffeeMaker.makeCoffee(0, 40));
}
}
I am following Coursera course in Testing. This is code snippet from CoffeeMakerTest assignment and I need to write test case with help of mockito. The problem is whenever I run my testing class, the mock function which is supposed to give a object for RecipeBook is giving arror of ClassDefNotFound. This is my first time trying to learn testing so I have not much idea about solution. Coursera had provided the project(used Gradle), I am only supposed to run test with mockito and JUnit.