diff --git a/.circleci/config.yml b/.circleci/config.yml index 82d1a9df..f667ea36 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,7 +7,7 @@ jobs: build: docker: # specify the version you desire here - - image: circleci/openjdk:8-jdk + - image: cimg/openjdk:17.0.5 # Specify service dependencies here if necessary # CircleCI maintains a library of pre-built images diff --git a/build.gradle b/build.gradle index e53f89c3..d1718c14 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ buildscript { ext { - springBootVersion = '2.1.0.RELEASE' + springBootVersion = '2.7.2' } repositories { mavenCentral() @@ -19,7 +19,7 @@ apply plugin: 'io.spring.dependency-management' apply plugin: 'jacoco' version = '0.0.1-SNAPSHOT' -sourceCompatibility = 1.8 +sourceCompatibility = 17 repositories { mavenCentral() @@ -29,15 +29,20 @@ repositories { dependencies { - compile('org.springframework.boot:spring-boot-starter-data-mongodb') - compile('org.springframework.boot:spring-boot-starter-thymeleaf') - compile('org.springframework.boot:spring-boot-starter-web') - runtime('org.springframework.boot:spring-boot-devtools') - compile('de.flapdoodle.embed:de.flapdoodle.embed.mongo') - compile group: 'cz.jirutka.spring', name: 'embedmongo-spring', version: '1.3.1' - compile 'org.webjars:bootstrap:3.3.7-1' - compileOnly('org.projectlombok:lombok') - testCompile('org.springframework.boot:spring-boot-starter-test') + implementation('de.flapdoodle.embed:de.flapdoodle.embed.mongo') + testImplementation group: 'cz.jirutka.spring', name: 'embedmongo-spring', version: '1.3.1' + implementation('org.springframework.boot:spring-boot-starter-data-mongodb') + implementation('org.springframework.boot:spring-boot-starter-thymeleaf') + implementation('org.springframework.boot:spring-boot-starter-web') + runtimeOnly('org.springframework.boot:spring-boot-devtools') + implementation 'org.webjars:bootstrap:3.3.7-1' + compileOnly 'org.projectlombok:lombok:1.18.20' + annotationProcessor 'org.projectlombok:lombok:1.18.20' + testImplementation 'org.hamcrest:hamcrest:2.2' + testCompileOnly 'org.projectlombok:lombok:1.18.20' + testAnnotationProcessor 'org.projectlombok:lombok:1.18.20' + testImplementation('org.springframework.boot:spring-boot-starter-test') + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation', version: '2.7.5' } //export test coverage diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8a1dd3ed..e648dfb3 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-bin.zip \ No newline at end of file +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 87a7f361..aa1ea4ac 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,2 +1,3 @@ spring.data.mongodb.port=0 -spring.data.mongodb.host=localhost \ No newline at end of file +spring.data.mongodb.host=localhost +spring.mongodb.embedded.version=4.0.21 \ 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 d64988ad..0ec72e0d 100644 --- a/src/test/java/guru/springframework/Spring5RecipeAppApplicationTests.java +++ b/src/test/java/guru/springframework/Spring5RecipeAppApplicationTests.java @@ -1,12 +1,12 @@ 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 9b758824..2bba17f1 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.MockHttpServletResponse; @@ -12,7 +12,7 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -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.request.MockMvcRequestBuilders.multipart; @@ -30,9 +30,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) diff --git a/src/test/java/guru/springframework/controllers/IndexControllerTest.java b/src/test/java/guru/springframework/controllers/IndexControllerTest.java index f8197ad0..b459fa49 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,7 +33,7 @@ public class IndexControllerTest { IndexController controller; - @Before + @BeforeEach public void setUp() throws Exception { MockitoAnnotations.initMocks(this); diff --git a/src/test/java/guru/springframework/controllers/IngredientControllerTest.java b/src/test/java/guru/springframework/controllers/IngredientControllerTest.java index 9d748e80..535b7388 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 329402a3..77c587fc 100644 --- a/src/test/java/guru/springframework/controllers/RecipeControllerTest.java +++ b/src/test/java/guru/springframework/controllers/RecipeControllerTest.java @@ -4,8 +4,8 @@ import guru.springframework.domain.Recipe; import guru.springframework.exceptions.NotFoundException; 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; @@ -31,7 +31,7 @@ public class RecipeControllerTest { MockMvc mockMvc; - @Before + @BeforeEach public void setUp() throws Exception { MockitoAnnotations.initMocks(this); diff --git a/src/test/java/guru/springframework/converters/CategoryCommandToCategoryTest.java b/src/test/java/guru/springframework/converters/CategoryCommandToCategoryTest.java index 3b075cdc..00beb1f7 100644 --- a/src/test/java/guru/springframework/converters/CategoryCommandToCategoryTest.java +++ b/src/test/java/guru/springframework/converters/CategoryCommandToCategoryTest.java @@ -2,10 +2,12 @@ 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 com.mongodb.assertions.Assertions.assertNull; +import static org.hibernate.validator.internal.util.Contracts.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; public class CategoryCommandToCategoryTest { @@ -13,7 +15,7 @@ public class CategoryCommandToCategoryTest { 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 c52814ed..12a668fd 100644 --- a/src/test/java/guru/springframework/converters/CategoryToCategoryCommandTest.java +++ b/src/test/java/guru/springframework/converters/CategoryToCategoryCommandTest.java @@ -2,10 +2,12 @@ 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 com.mongodb.assertions.Assertions.assertNull; +import static org.hibernate.validator.internal.util.Contracts.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Created by jt on 6/21/17. @@ -16,7 +18,7 @@ public class CategoryToCategoryCommandTest { 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 3ee7f27d..cbae20ef 100644 --- a/src/test/java/guru/springframework/converters/IngredientCommandToIngredientTest.java +++ b/src/test/java/guru/springframework/converters/IngredientCommandToIngredientTest.java @@ -4,12 +4,14 @@ 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 com.mongodb.assertions.Assertions.assertNull; +import static org.hibernate.validator.internal.util.Contracts.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; public class IngredientCommandToIngredientTest { @@ -21,7 +23,7 @@ public class IngredientCommandToIngredientTest { 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 82a969e5..cf4e736b 100644 --- a/src/test/java/guru/springframework/converters/IngredientToIngredientCommandTest.java +++ b/src/test/java/guru/springframework/converters/IngredientToIngredientCommandTest.java @@ -4,12 +4,14 @@ 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 com.mongodb.assertions.Assertions.assertNull; +import static org.hibernate.validator.internal.util.Contracts.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Created by jt on 6/21/17. @@ -25,7 +27,7 @@ public class IngredientToIngredientCommandTest { 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 e2e05db2..9edd7cf0 100644 --- a/src/test/java/guru/springframework/converters/NotesCommandToNotesTest.java +++ b/src/test/java/guru/springframework/converters/NotesCommandToNotesTest.java @@ -2,10 +2,12 @@ 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 com.mongodb.assertions.Assertions.assertNull; +import static org.hibernate.validator.internal.util.Contracts.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; public class NotesCommandToNotesTest { @@ -13,7 +15,7 @@ public class NotesCommandToNotesTest { 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 55210799..6816060f 100644 --- a/src/test/java/guru/springframework/converters/NotesToNotesCommandTest.java +++ b/src/test/java/guru/springframework/converters/NotesToNotesCommandTest.java @@ -2,10 +2,12 @@ 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 com.mongodb.assertions.Assertions.assertNull; +import static org.hibernate.validator.internal.util.Contracts.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Created by jt on 6/21/17. @@ -16,7 +18,7 @@ public class NotesToNotesCommandTest { 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 267884b4..3c0eef8b 100644 --- a/src/test/java/guru/springframework/converters/RecipeCommandToRecipeTest.java +++ b/src/test/java/guru/springframework/converters/RecipeCommandToRecipeTest.java @@ -6,10 +6,12 @@ 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.Assert.*; +import static com.mongodb.assertions.Assertions.assertNull; +import static org.hibernate.validator.internal.util.Contracts.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; public class RecipeCommandToRecipeTest { public static final String RECIPE_ID = "1"; @@ -30,7 +32,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 285eb49d..e040e964 100644 --- a/src/test/java/guru/springframework/converters/RecipeToRecipeCommandTest.java +++ b/src/test/java/guru/springframework/converters/RecipeToRecipeCommandTest.java @@ -2,10 +2,13 @@ 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 com.mongodb.assertions.Assertions.assertNull; +import static org.hibernate.validator.internal.util.Contracts.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.Assert.*; public class RecipeToRecipeCommandTest { @@ -25,7 +28,7 @@ public class RecipeToRecipeCommandTest { public static final String NOTES_ID = "9"; 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 3d5c55a3..b96e06a2 100644 --- a/src/test/java/guru/springframework/converters/UnitOfMeasureCommandToUnitOfMeasureTest.java +++ b/src/test/java/guru/springframework/converters/UnitOfMeasureCommandToUnitOfMeasureTest.java @@ -2,10 +2,12 @@ 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 com.mongodb.assertions.Assertions.assertNull; +import static org.hibernate.validator.internal.util.Contracts.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; public class UnitOfMeasureCommandToUnitOfMeasureTest { @@ -14,7 +16,7 @@ public class UnitOfMeasureCommandToUnitOfMeasureTest { 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 b2895819..4576f178 100644 --- a/src/test/java/guru/springframework/converters/UnitOfMeasureToUnitOfMeasureCommandTest.java +++ b/src/test/java/guru/springframework/converters/UnitOfMeasureToUnitOfMeasureCommandTest.java @@ -2,10 +2,12 @@ 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 com.mongodb.assertions.Assertions.assertNull; +import static org.hibernate.validator.internal.util.Contracts.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Created by jt on 6/21/17. @@ -17,7 +19,7 @@ public class UnitOfMeasureToUnitOfMeasureCommandTest { 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 bb7bf476..b660ace3 100644 --- a/src/test/java/guru/springframework/domain/CategoryTest.java +++ b/src/test/java/guru/springframework/domain/CategoryTest.java @@ -1,9 +1,9 @@ package 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.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Created by jt on 6/17/17. @@ -12,7 +12,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 a877539e..27a9fedd 100644 --- a/src/test/java/guru/springframework/repositories/UnitOfMeasureRepositoryIT.java +++ b/src/test/java/guru/springframework/repositories/UnitOfMeasureRepositoryIT.java @@ -2,22 +2,20 @@ import guru.springframework.bootstrap.RecipeBootstrap; 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.data.mongo.DataMongoTest; 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) @DataMongoTest public class UnitOfMeasureRepositoryIT { @@ -30,7 +28,7 @@ public class UnitOfMeasureRepositoryIT { @Autowired RecipeRepository recipeRepository; - @Before + @BeforeEach public void setUp() throws Exception { recipeRepository.deleteAll(); diff --git a/src/test/java/guru/springframework/services/ImageServiceImplTest.java b/src/test/java/guru/springframework/services/ImageServiceImplTest.java index 2c47b098..92810fb4 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,7 +23,7 @@ public class ImageServiceImplTest { ImageService imageService; - @Before + @BeforeEach public void setUp() throws Exception { MockitoAnnotations.initMocks(this); diff --git a/src/test/java/guru/springframework/services/IngredientServiceImplTest.java b/src/test/java/guru/springframework/services/IngredientServiceImplTest.java index f8721ceb..efb73ac9 100644 --- a/src/test/java/guru/springframework/services/IngredientServiceImplTest.java +++ b/src/test/java/guru/springframework/services/IngredientServiceImplTest.java @@ -9,14 +9,15 @@ 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.anyString; import static org.mockito.Mockito.*; @@ -39,7 +40,7 @@ public IngredientServiceImplTest() { this.ingredientCommandToIngredient = new IngredientCommandToIngredient(new UnitOfMeasureCommandToUnitOfMeasure()); } - @Before + @BeforeEach public void setUp() throws Exception { MockitoAnnotations.initMocks(this); diff --git a/src/test/java/guru/springframework/services/RecipeServiceIT.java b/src/test/java/guru/springframework/services/RecipeServiceIT.java index 6e84ada4..808598ea 100644 --- a/src/test/java/guru/springframework/services/RecipeServiceIT.java +++ b/src/test/java/guru/springframework/services/RecipeServiceIT.java @@ -5,22 +5,20 @@ import guru.springframework.converters.RecipeToRecipeCommand; import guru.springframework.domain.Recipe; import guru.springframework.repositories.RecipeRepository; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Disabled; +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. */ -@Ignore -@RunWith(SpringRunner.class) +@Disabled @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 4940676c..9b0cf3e4 100644 --- a/src/test/java/guru/springframework/services/RecipeServiceImplTest.java +++ b/src/test/java/guru/springframework/services/RecipeServiceImplTest.java @@ -7,8 +7,8 @@ import guru.springframework.domain.Recipe; import guru.springframework.exceptions.NotFoundException; 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; @@ -16,9 +16,11 @@ import java.util.Optional; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.instanceOf; +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. @@ -36,9 +38,9 @@ public class RecipeServiceImplTest { @Mock RecipeCommandToRecipe recipeCommandToRecipe; - @Before + @BeforeEach public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); recipeService = new RecipeServiceImpl(recipeRepository, recipeCommandToRecipe, recipeToRecipeCommand); } @@ -58,16 +60,16 @@ public void getRecipeByIdTest() throws Exception { verify(recipeRepository, never()).findAll(); } - @Test(expected = NotFoundException.class) + @Test public void getRecipeByIdTestNotFound() throws Exception { - Optional recipeOptional = Optional.empty(); - - when(recipeRepository.findById(anyString())).thenReturn(recipeOptional); - - Recipe recipeReturned = recipeService.findById("1"); - - //should go boom + try{ + Optional recipeOptional = Optional.empty(); + when(recipeRepository.findById(any())).thenReturn(recipeOptional); + Recipe recipeReturned = recipeService.findById("1"); + }catch(Exception e){ + assertThat(e, instanceOf(NotFoundException.class)); + } } @Test diff --git a/src/test/java/guru/springframework/services/UnitOfMeasureServiceImplTest.java b/src/test/java/guru/springframework/services/UnitOfMeasureServiceImplTest.java index e42b5dcb..812a7fc3 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,7 +23,7 @@ public class UnitOfMeasureServiceImplTest { @Mock UnitOfMeasureRepository unitOfMeasureRepository; - @Before + @BeforeEach public void setUp() throws Exception { MockitoAnnotations.initMocks(this);