Created
August 19, 2021 16:23
-
-
Save jianhe-fun/91b41342cfeca93f89639bd007a30ae8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jian.he.recipe.services; | |
import jian.he.recipe.domain.Recipe; | |
import jian.he.recipe.repositroies.RecipeRepository; | |
import org.junit.jupiter.api.BeforeEach; | |
import org.junit.jupiter.api.Test; | |
import org.mockito.Mock; | |
import org.mockito.MockitoAnnotations; | |
import java.util.HashSet; | |
import java.util.Set; | |
import static org.junit.jupiter.api.Assertions.*; | |
import static org.mockito.Mockito.*; | |
class RecipeServiceImplTest { | |
RecipeServiceImpl recipeService; | |
@Mock | |
RecipeRepository repository; | |
@BeforeEach | |
void setUp() { | |
//set up an mock recipe repository. | |
MockitoAnnotations.openMocks(this); | |
recipeService = new RecipeServiceImpl(repository); | |
} | |
@Test | |
void getRecipes() { | |
Recipe recipe = new Recipe(); | |
HashSet receipeData = new HashSet(); | |
receipeData.add(recipe); | |
when(repository.findAll()).thenReturn(receipeData); | |
Set<Recipe> recipes =recipeService.getRecipes(); | |
assertEquals(recipes.size(),1); | |
verify(repository, times(1)).findAll(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment