From 0b1c96677e11593682400b020d6bd2de19fa66f1 Mon Sep 17 00:00:00 2001 From: "Simanta.Sarma" Date: Fri, 21 Oct 2022 09:55:08 +0530 Subject: [PATCH] Updated to Java 17, Spring Boot 2.7.2, and JUnit 5 --- pom.xml | 4 ++-- src/main/resources/application.properties | 5 ++++- .../Spring5RecipeAppApplicationTests.java | 5 ++--- .../controllers/ImageControllerTest.java | 8 ++++---- .../controllers/IndexControllerTest.java | 10 +++++----- .../controllers/IngredientControllerTest.java | 8 ++++---- .../controllers/RecipeControllerTest.java | 8 ++++---- .../converters/CategoryCommandToCategoryTest.java | 11 ++++++----- .../converters/CategoryToCategoryCommandTest.java | 10 +++++----- .../IngredientCommandToIngredientTest.java | 13 +++++++------ .../IngredientToIngredientCommandTest.java | 13 +++++++------ .../converters/NotesCommandToNotesTest.java | 10 +++++----- .../converters/NotesToNotesCommandTest.java | 11 ++++++----- .../converters/RecipeCommandToRecipeTest.java | 9 +++++---- .../converters/RecipeToRecipeCommandTest.java | 8 ++++---- .../UnitOfMeasureCommandToUnitOfMeasureTest.java | 11 ++++++----- .../UnitOfMeasureToUnitOfMeasureCommandTest.java | 10 +++++----- .../guru/springframework/domain/CategoryTest.java | 9 +++++---- .../repositories/UnitOfMeasureRepositoryIT.java | 10 ++++------ .../services/ImageServiceImplTest.java | 10 +++++----- .../services/IngredientServiceImplTest.java | 10 +++++----- .../springframework/services/RecipeServiceIT.java | 7 ++----- .../services/RecipeServiceImplTest.java | 10 +++++----- .../services/UnitOfMeasureServiceImplTest.java | 10 +++++----- 24 files changed, 112 insertions(+), 108 deletions(-) diff --git a/pom.xml b/pom.xml index 30280172f3..3af7656b0f 100644 --- a/pom.xml +++ b/pom.xml @@ -14,14 +14,14 @@ org.springframework.boot spring-boot-starter-parent - 2.1.0.RELEASE + 2.7.2 UTF-8 UTF-8 - 1.8 + 17 diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e45c5013c5..7d80715172 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1,4 @@ -logging.level.guru.springframework=debug \ No newline at end of file +logging.level.guru.springframework=debug +spring.h2.console.enabled=true +spring.datasource.url=jdbc:h2:mem:mydb +spring.jpa.defer-datasource-initialization=true \ No newline at end of file diff --git a/src/test/java/guru/springframework/Spring5RecipeAppApplicationTests.java b/src/test/java/guru/springframework/Spring5RecipeAppApplicationTests.java index 775dc5feef..ecdca7f03f 100644 --- a/src/test/java/guru/springframework/Spring5RecipeAppApplicationTests.java +++ b/src/test/java/guru/springframework/Spring5RecipeAppApplicationTests.java @@ -1,11 +1,10 @@ package guru.springframework; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) + @SpringBootTest public class Spring5RecipeAppApplicationTests { diff --git a/src/test/java/guru/springframework/controllers/ImageControllerTest.java b/src/test/java/guru/springframework/controllers/ImageControllerTest.java index 1e292fdbc6..4b758d3bf6 100644 --- a/src/test/java/guru/springframework/controllers/ImageControllerTest.java +++ b/src/test/java/guru/springframework/controllers/ImageControllerTest.java @@ -3,8 +3,8 @@ import guru.springframework.commands.RecipeCommand; import guru.springframework.services.ImageService; import guru.springframework.services.RecipeService; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.springframework.mock.web.MockMultipartFile; @@ -28,9 +28,9 @@ public class ImageControllerTest { MockMvc mockMvc; - @Before + @BeforeEach public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); controller = new ImageController(imageService, recipeService); mockMvc = MockMvcBuilders.standaloneSetup(controller).build(); diff --git a/src/test/java/guru/springframework/controllers/IndexControllerTest.java b/src/test/java/guru/springframework/controllers/IndexControllerTest.java index 8f314563d2..b86ee4cb46 100644 --- a/src/test/java/guru/springframework/controllers/IndexControllerTest.java +++ b/src/test/java/guru/springframework/controllers/IndexControllerTest.java @@ -2,8 +2,8 @@ import guru.springframework.domain.Recipe; import guru.springframework.services.RecipeService; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -14,7 +14,7 @@ import java.util.HashSet; import java.util.Set; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -33,9 +33,9 @@ public class IndexControllerTest { IndexController controller; - @Before + @BeforeEach public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); controller = new IndexController(recipeService); } diff --git a/src/test/java/guru/springframework/controllers/IngredientControllerTest.java b/src/test/java/guru/springframework/controllers/IngredientControllerTest.java index 8a82548ee5..a410dab432 100644 --- a/src/test/java/guru/springframework/controllers/IngredientControllerTest.java +++ b/src/test/java/guru/springframework/controllers/IngredientControllerTest.java @@ -5,8 +5,8 @@ import guru.springframework.services.IngredientService; import guru.springframework.services.RecipeService; import guru.springframework.services.UnitOfMeasureService; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.springframework.http.MediaType; @@ -36,9 +36,9 @@ public class IngredientControllerTest { MockMvc mockMvc; - @Before + @BeforeEach public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); controller = new IngredientController(ingredientService, recipeService, unitOfMeasureService); mockMvc = MockMvcBuilders.standaloneSetup(controller).build(); diff --git a/src/test/java/guru/springframework/controllers/RecipeControllerTest.java b/src/test/java/guru/springframework/controllers/RecipeControllerTest.java index 0073d3b2e8..daf6be4de6 100644 --- a/src/test/java/guru/springframework/controllers/RecipeControllerTest.java +++ b/src/test/java/guru/springframework/controllers/RecipeControllerTest.java @@ -3,8 +3,8 @@ import guru.springframework.commands.RecipeCommand; import guru.springframework.domain.Recipe; import guru.springframework.services.RecipeService; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.springframework.http.MediaType; @@ -30,9 +30,9 @@ public class RecipeControllerTest { MockMvc mockMvc; - @Before + @BeforeEach public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); controller = new RecipeController(recipeService); mockMvc = MockMvcBuilders.standaloneSetup(controller).build(); diff --git a/src/test/java/guru/springframework/converters/CategoryCommandToCategoryTest.java b/src/test/java/guru/springframework/converters/CategoryCommandToCategoryTest.java index cc7298e5c7..246a822337 100644 --- a/src/test/java/guru/springframework/converters/CategoryCommandToCategoryTest.java +++ b/src/test/java/guru/springframework/converters/CategoryCommandToCategoryTest.java @@ -2,18 +2,19 @@ import guru.springframework.commands.CategoryCommand; import guru.springframework.domain.Category; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; -import static org.junit.Assert.*; public class CategoryCommandToCategoryTest { - public static final Long ID_VALUE = new Long(1L); + public static final Long ID_VALUE = Long.valueOf(1L); public static final String DESCRIPTION = "description"; CategoryCommandToCategory conveter; - @Before + @BeforeEach public void setUp() throws Exception { conveter = new CategoryCommandToCategory(); } diff --git a/src/test/java/guru/springframework/converters/CategoryToCategoryCommandTest.java b/src/test/java/guru/springframework/converters/CategoryToCategoryCommandTest.java index 1cf4445b95..b838d1fd32 100644 --- a/src/test/java/guru/springframework/converters/CategoryToCategoryCommandTest.java +++ b/src/test/java/guru/springframework/converters/CategoryToCategoryCommandTest.java @@ -2,21 +2,21 @@ import guru.springframework.commands.CategoryCommand; import guru.springframework.domain.Category; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Created by jt on 6/21/17. */ public class CategoryToCategoryCommandTest { - public static final Long ID_VALUE = new Long(1L); + public static final Long ID_VALUE = Long.valueOf(1L); public static final String DESCRIPTION = "descript"; CategoryToCategoryCommand convter; - @Before + @BeforeEach public void setUp() throws Exception { convter = new CategoryToCategoryCommand(); } diff --git a/src/test/java/guru/springframework/converters/IngredientCommandToIngredientTest.java b/src/test/java/guru/springframework/converters/IngredientCommandToIngredientTest.java index ec7c275d70..38b8147de8 100644 --- a/src/test/java/guru/springframework/converters/IngredientCommandToIngredientTest.java +++ b/src/test/java/guru/springframework/converters/IngredientCommandToIngredientTest.java @@ -4,24 +4,25 @@ import guru.springframework.commands.UnitOfMeasureCommand; import guru.springframework.domain.Ingredient; import guru.springframework.domain.Recipe; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.math.BigDecimal; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; + public class IngredientCommandToIngredientTest { public static final Recipe RECIPE = new Recipe(); public static final BigDecimal AMOUNT = new BigDecimal("1"); public static final String DESCRIPTION = "Cheeseburger"; - public static final Long ID_VALUE = new Long(1L); - public static final Long UOM_ID = new Long(2L); + public static final Long ID_VALUE = Long.valueOf(1L); + public static final Long UOM_ID = Long.valueOf(2L); IngredientCommandToIngredient converter; - @Before + @BeforeEach public void setUp() throws Exception { converter = new IngredientCommandToIngredient(new UnitOfMeasureCommandToUnitOfMeasure()); } diff --git a/src/test/java/guru/springframework/converters/IngredientToIngredientCommandTest.java b/src/test/java/guru/springframework/converters/IngredientToIngredientCommandTest.java index 40601af92f..e004713d91 100644 --- a/src/test/java/guru/springframework/converters/IngredientToIngredientCommandTest.java +++ b/src/test/java/guru/springframework/converters/IngredientToIngredientCommandTest.java @@ -4,12 +4,13 @@ import guru.springframework.domain.Ingredient; import guru.springframework.domain.Recipe; import guru.springframework.domain.UnitOfMeasure; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.math.BigDecimal; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; + /** * Created by jt on 6/21/17. @@ -19,13 +20,13 @@ public class IngredientToIngredientCommandTest { public static final Recipe RECIPE = new Recipe(); public static final BigDecimal AMOUNT = new BigDecimal("1"); public static final String DESCRIPTION = "Cheeseburger"; - public static final Long UOM_ID = new Long(2L); - public static final Long ID_VALUE = new Long(1L); + public static final Long UOM_ID = Long.valueOf(2L); + public static final Long ID_VALUE = Long.valueOf(1L); IngredientToIngredientCommand converter; - @Before + @BeforeEach public void setUp() throws Exception { converter = new IngredientToIngredientCommand(new UnitOfMeasureToUnitOfMeasureCommand()); } diff --git a/src/test/java/guru/springframework/converters/NotesCommandToNotesTest.java b/src/test/java/guru/springframework/converters/NotesCommandToNotesTest.java index 855f02ed11..67bef39890 100644 --- a/src/test/java/guru/springframework/converters/NotesCommandToNotesTest.java +++ b/src/test/java/guru/springframework/converters/NotesCommandToNotesTest.java @@ -2,18 +2,18 @@ import guru.springframework.commands.NotesCommand; import guru.springframework.domain.Notes; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class NotesCommandToNotesTest { - public static final Long ID_VALUE = new Long(1L); + public static final Long ID_VALUE = Long.valueOf(1L); public static final String RECIPE_NOTES = "Notes"; NotesCommandToNotes converter; - @Before + @BeforeEach public void setUp() throws Exception { converter = new NotesCommandToNotes(); diff --git a/src/test/java/guru/springframework/converters/NotesToNotesCommandTest.java b/src/test/java/guru/springframework/converters/NotesToNotesCommandTest.java index bac0ac0d36..2b2b61547d 100644 --- a/src/test/java/guru/springframework/converters/NotesToNotesCommandTest.java +++ b/src/test/java/guru/springframework/converters/NotesToNotesCommandTest.java @@ -2,21 +2,22 @@ import guru.springframework.commands.NotesCommand; import guru.springframework.domain.Notes; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; -import static org.junit.Assert.*; /** * Created by jt on 6/21/17. */ public class NotesToNotesCommandTest { - public static final Long ID_VALUE = new Long(1L); + public static final Long ID_VALUE = Long.valueOf(1L); public static final String RECIPE_NOTES = "Notes"; NotesToNotesCommand converter; - @Before + @BeforeEach public void setUp() throws Exception { converter = new NotesToNotesCommand(); } diff --git a/src/test/java/guru/springframework/converters/RecipeCommandToRecipeTest.java b/src/test/java/guru/springframework/converters/RecipeCommandToRecipeTest.java index bbacedba5c..3ad281ae9a 100644 --- a/src/test/java/guru/springframework/converters/RecipeCommandToRecipeTest.java +++ b/src/test/java/guru/springframework/converters/RecipeCommandToRecipeTest.java @@ -6,10 +6,11 @@ import guru.springframework.commands.RecipeCommand; import guru.springframework.domain.Difficulty; import guru.springframework.domain.Recipe; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; -import static org.junit.Assert.*; public class RecipeCommandToRecipeTest { public static final Long RECIPE_ID = 1L; @@ -30,7 +31,7 @@ public class RecipeCommandToRecipeTest { RecipeCommandToRecipe converter; - @Before + @BeforeEach public void setUp() throws Exception { converter = new RecipeCommandToRecipe(new CategoryCommandToCategory(), new IngredientCommandToIngredient(new UnitOfMeasureCommandToUnitOfMeasure()), diff --git a/src/test/java/guru/springframework/converters/RecipeToRecipeCommandTest.java b/src/test/java/guru/springframework/converters/RecipeToRecipeCommandTest.java index 9bf0d75d14..c3c74aa011 100644 --- a/src/test/java/guru/springframework/converters/RecipeToRecipeCommandTest.java +++ b/src/test/java/guru/springframework/converters/RecipeToRecipeCommandTest.java @@ -2,10 +2,10 @@ import guru.springframework.commands.RecipeCommand; import guru.springframework.domain.*; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class RecipeToRecipeCommandTest { @@ -25,7 +25,7 @@ public class RecipeToRecipeCommandTest { public static final Long NOTES_ID = 9L; RecipeToRecipeCommand converter; - @Before + @BeforeEach public void setUp() throws Exception { converter = new RecipeToRecipeCommand( new CategoryToCategoryCommand(), diff --git a/src/test/java/guru/springframework/converters/UnitOfMeasureCommandToUnitOfMeasureTest.java b/src/test/java/guru/springframework/converters/UnitOfMeasureCommandToUnitOfMeasureTest.java index 820f5d52bf..ae6cd38a6a 100644 --- a/src/test/java/guru/springframework/converters/UnitOfMeasureCommandToUnitOfMeasureTest.java +++ b/src/test/java/guru/springframework/converters/UnitOfMeasureCommandToUnitOfMeasureTest.java @@ -2,19 +2,20 @@ import guru.springframework.commands.UnitOfMeasureCommand; import guru.springframework.domain.UnitOfMeasure; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; -import static org.junit.Assert.*; public class UnitOfMeasureCommandToUnitOfMeasureTest { public static final String DESCRIPTION = "description"; - public static final Long LONG_VALUE = new Long(1L); + public static final Long LONG_VALUE = Long.valueOf(1L); UnitOfMeasureCommandToUnitOfMeasure converter; - @Before + @BeforeEach public void setUp() throws Exception { converter = new UnitOfMeasureCommandToUnitOfMeasure(); diff --git a/src/test/java/guru/springframework/converters/UnitOfMeasureToUnitOfMeasureCommandTest.java b/src/test/java/guru/springframework/converters/UnitOfMeasureToUnitOfMeasureCommandTest.java index 68a3257077..cea508ab8b 100644 --- a/src/test/java/guru/springframework/converters/UnitOfMeasureToUnitOfMeasureCommandTest.java +++ b/src/test/java/guru/springframework/converters/UnitOfMeasureToUnitOfMeasureCommandTest.java @@ -2,10 +2,10 @@ import guru.springframework.commands.UnitOfMeasureCommand; import guru.springframework.domain.UnitOfMeasure; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Created by jt on 6/21/17. @@ -13,11 +13,11 @@ public class UnitOfMeasureToUnitOfMeasureCommandTest { public static final String DESCRIPTION = "description"; - public static final Long LONG_VALUE = new Long(1L); + public static final Long LONG_VALUE = Long.valueOf(1L); UnitOfMeasureToUnitOfMeasureCommand converter; - @Before + @BeforeEach public void setUp() throws Exception { converter = new UnitOfMeasureToUnitOfMeasureCommand(); } diff --git a/src/test/java/guru/springframework/domain/CategoryTest.java b/src/test/java/guru/springframework/domain/CategoryTest.java index 11badc457f..1cd7612134 100644 --- a/src/test/java/guru/springframework/domain/CategoryTest.java +++ b/src/test/java/guru/springframework/domain/CategoryTest.java @@ -1,9 +1,10 @@ package guru.springframework.domain; -import org.junit.Before; -import org.junit.Test; -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Created by jt on 6/17/17. @@ -12,7 +13,7 @@ public class CategoryTest { Category category; - @Before + @BeforeEach public void setUp(){ category = new Category(); } diff --git a/src/test/java/guru/springframework/repositories/UnitOfMeasureRepositoryIT.java b/src/test/java/guru/springframework/repositories/UnitOfMeasureRepositoryIT.java index b934959591..fd96ac3c18 100644 --- a/src/test/java/guru/springframework/repositories/UnitOfMeasureRepositoryIT.java +++ b/src/test/java/guru/springframework/repositories/UnitOfMeasureRepositoryIT.java @@ -1,28 +1,26 @@ package guru.springframework.repositories; import guru.springframework.domain.UnitOfMeasure; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.junit4.SpringRunner; import java.util.Optional; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Created by jt on 6/17/17. */ -@RunWith(SpringRunner.class) @DataJpaTest public class UnitOfMeasureRepositoryIT { @Autowired UnitOfMeasureRepository unitOfMeasureRepository; - @Before + @BeforeEach public void setUp() throws Exception { } diff --git a/src/test/java/guru/springframework/services/ImageServiceImplTest.java b/src/test/java/guru/springframework/services/ImageServiceImplTest.java index a8e5c90a77..5d9276c0d2 100644 --- a/src/test/java/guru/springframework/services/ImageServiceImplTest.java +++ b/src/test/java/guru/springframework/services/ImageServiceImplTest.java @@ -2,8 +2,8 @@ import guru.springframework.domain.Recipe; import guru.springframework.repositories.RecipeRepository; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -12,7 +12,7 @@ import java.util.Optional; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; @@ -23,9 +23,9 @@ public class ImageServiceImplTest { ImageService imageService; - @Before + @BeforeEach public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); imageService = new ImageServiceImpl(recipeRepository); } diff --git a/src/test/java/guru/springframework/services/IngredientServiceImplTest.java b/src/test/java/guru/springframework/services/IngredientServiceImplTest.java index 49d53b16b9..4ebcadeb47 100644 --- a/src/test/java/guru/springframework/services/IngredientServiceImplTest.java +++ b/src/test/java/guru/springframework/services/IngredientServiceImplTest.java @@ -9,14 +9,14 @@ import guru.springframework.domain.Recipe; import guru.springframework.repositories.RecipeRepository; import guru.springframework.repositories.UnitOfMeasureRepository; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.util.Optional; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.*; @@ -39,9 +39,9 @@ public IngredientServiceImplTest() { this.ingredientCommandToIngredient = new IngredientCommandToIngredient(new UnitOfMeasureCommandToUnitOfMeasure()); } - @Before + @BeforeEach public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); ingredientService = new IngredientServiceImpl(ingredientToIngredientCommand, ingredientCommandToIngredient, recipeRepository, unitOfMeasureRepository); diff --git a/src/test/java/guru/springframework/services/RecipeServiceIT.java b/src/test/java/guru/springframework/services/RecipeServiceIT.java index f8702b99c2..635586fe5e 100644 --- a/src/test/java/guru/springframework/services/RecipeServiceIT.java +++ b/src/test/java/guru/springframework/services/RecipeServiceIT.java @@ -5,20 +5,17 @@ import guru.springframework.converters.RecipeToRecipeCommand; import guru.springframework.domain.Recipe; import guru.springframework.repositories.RecipeRepository; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; -import static org.junit.Assert.assertEquals; - +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Created by jt on 6/21/17. */ -@RunWith(SpringRunner.class) @SpringBootTest public class RecipeServiceIT { diff --git a/src/test/java/guru/springframework/services/RecipeServiceImplTest.java b/src/test/java/guru/springframework/services/RecipeServiceImplTest.java index 151a42197d..6da49c8b94 100644 --- a/src/test/java/guru/springframework/services/RecipeServiceImplTest.java +++ b/src/test/java/guru/springframework/services/RecipeServiceImplTest.java @@ -6,8 +6,8 @@ import guru.springframework.converters.RecipeToRecipeCommand; import guru.springframework.domain.Recipe; import guru.springframework.repositories.RecipeRepository; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -15,9 +15,9 @@ import java.util.Optional; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; +import static org.springframework.test.util.AssertionErrors.assertNotNull; /** * Created by jt on 6/17/17. @@ -35,7 +35,7 @@ public class RecipeServiceImplTest { @Mock RecipeCommandToRecipe recipeCommandToRecipe; - @Before + @BeforeEach public void setUp() throws Exception { MockitoAnnotations.initMocks(this); diff --git a/src/test/java/guru/springframework/services/UnitOfMeasureServiceImplTest.java b/src/test/java/guru/springframework/services/UnitOfMeasureServiceImplTest.java index d055bd519b..5c0130ed4f 100644 --- a/src/test/java/guru/springframework/services/UnitOfMeasureServiceImplTest.java +++ b/src/test/java/guru/springframework/services/UnitOfMeasureServiceImplTest.java @@ -4,15 +4,15 @@ import guru.springframework.converters.UnitOfMeasureToUnitOfMeasureCommand; import guru.springframework.domain.UnitOfMeasure; import guru.springframework.repositories.UnitOfMeasureRepository; -import org.junit.Before; -import org.junit.Test; +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.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; public class UnitOfMeasureServiceImplTest { @@ -23,9 +23,9 @@ public class UnitOfMeasureServiceImplTest { @Mock UnitOfMeasureRepository unitOfMeasureRepository; - @Before + @BeforeEach public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); service = new UnitOfMeasureServiceImpl(unitOfMeasureRepository, unitOfMeasureToUnitOfMeasureCommand); }