diff --git a/pom.xml b/pom.xml index 12a69f2ac8e6f2d0c7cb55d67e01b00416b36a15..8aa89d9cc7b11bffb3a748bf951bbb68803ae219 100644 --- a/pom.xml +++ b/pom.xml @@ -103,18 +103,6 @@ <scope>test</scope> </dependency> - <dependency> - <groupId>org.junit.vintage</groupId> - <artifactId>junit-vintage-engine</artifactId> - <scope>test</scope> - <exclusions> - <exclusion> - <groupId>org.hamcrest</groupId> - <artifactId>hamcrest-core</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> diff --git a/src/test/java/org/springframework/samples/petclinic/SpringConfigTests.java b/src/test/java/org/springframework/samples/petclinic/SpringConfigTests.java index a9d9f7816e6252ccd997a23622fe82c25f850cbf..e33631f22db60f489175eedec51d5eb4bab1517b 100644 --- a/src/test/java/org/springframework/samples/petclinic/SpringConfigTests.java +++ b/src/test/java/org/springframework/samples/petclinic/SpringConfigTests.java @@ -1,16 +1,13 @@ package org.springframework.samples.petclinic; -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(classes = PetClinicApplication.class) -public class SpringConfigTests { +class SpringConfigTests { @Test - public void contextLoads() { + void contextLoads() { // Test the Spring configuration } } diff --git a/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java b/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java index 75c3f32eb964f6e9b540aed0e6cc7469b5fac8ae..dfd2105afb1b18ec54e38b6f962cac4057409517 100644 --- a/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java +++ b/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java @@ -8,7 +8,7 @@ import java.util.Set; import javax.validation.ConstraintViolation; import javax.validation.Validator; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; @@ -17,7 +17,7 @@ import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; * Simple test to make sure that Bean Validation is working * (useful when upgrading to a new version of Hibernate Validator/ Bean Validation) */ -public class ValidatorTests { +class ValidatorTests { private Validator createValidator() { LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean(); @@ -26,7 +26,7 @@ public class ValidatorTests { } @Test - public void shouldNotValidateWhenFirstNameEmpty() { + void shouldNotValidateWhenFirstNameEmpty() { LocaleContextHolder.setLocale(Locale.ENGLISH); Person person = new Person(); diff --git a/src/test/java/org/springframework/samples/petclinic/rest/OwnerRestControllerTests.java b/src/test/java/org/springframework/samples/petclinic/rest/OwnerRestControllerTests.java index c0078773f19f0000ee979ceb0b7ee137f30f67fe..b329ebe070b7d2a68fcb3cce7e9baafbe891c34e 100644 --- a/src/test/java/org/springframework/samples/petclinic/rest/OwnerRestControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/rest/OwnerRestControllerTests.java @@ -19,9 +19,8 @@ package org.springframework.samples.petclinic.rest; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -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.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -36,7 +35,6 @@ import org.springframework.samples.petclinic.service.ClinicService; import org.springframework.samples.petclinic.service.clinicService.ApplicationTestConfig; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -46,14 +44,8 @@ import java.util.ArrayList; import java.util.List; import static org.mockito.BDDMockito.given; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; /** @@ -62,10 +54,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * @author Vitaliy Fedoriv */ @SpringBootTest -@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = ApplicationTestConfig.class) @WebAppConfiguration -public class OwnerRestControllerTests { +class OwnerRestControllerTests { @Autowired private OwnerRestController ownerRestController; @@ -80,8 +71,8 @@ public class OwnerRestControllerTests { private List<OwnerDto> owners; - @Before - public void initOwners() { + @BeforeEach + void initOwners() { this.mockMvc = MockMvcBuilders.standaloneSetup(ownerRestController) .setControllerAdvice(new ExceptionControllerAdvice()) .build(); @@ -111,7 +102,7 @@ public class OwnerRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testGetOwnerSuccess() throws Exception { + void testGetOwnerSuccess() throws Exception { given(this.clinicService.findOwnerById(1)).willReturn(ownerMapper.toOwner(owners.get(0))); this.mockMvc.perform(get("/api/owners/1") .accept(MediaType.APPLICATION_JSON_VALUE)) @@ -123,7 +114,7 @@ public class OwnerRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testGetOwnerNotFound() throws Exception { + void testGetOwnerNotFound() throws Exception { given(this.clinicService.findOwnerById(-1)).willReturn(null); this.mockMvc.perform(get("/api/owners/-1") .accept(MediaType.APPLICATION_JSON)) @@ -132,7 +123,7 @@ public class OwnerRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testGetOwnersListSuccess() throws Exception { + void testGetOwnersListSuccess() throws Exception { owners.remove(0); owners.remove(1); given(this.clinicService.findOwnerByLastName("Davis")).willReturn(ownerMapper.toOwners(owners)); @@ -148,7 +139,7 @@ public class OwnerRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testGetOwnersListNotFound() throws Exception { + void testGetOwnersListNotFound() throws Exception { owners.clear(); given(this.clinicService.findOwnerByLastName("0")).willReturn(ownerMapper.toOwners(owners)); this.mockMvc.perform(get("/api/owners/?lastName=0") @@ -158,7 +149,7 @@ public class OwnerRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testGetAllOwnersSuccess() throws Exception { + void testGetAllOwnersSuccess() throws Exception { owners.remove(0); owners.remove(1); given(this.clinicService.findAllOwners()).willReturn(ownerMapper.toOwners(owners)); @@ -174,7 +165,7 @@ public class OwnerRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testGetAllOwnersNotFound() throws Exception { + void testGetAllOwnersNotFound() throws Exception { owners.clear(); given(this.clinicService.findAllOwners()).willReturn(ownerMapper.toOwners(owners)); this.mockMvc.perform(get("/api/owners/") @@ -184,7 +175,7 @@ public class OwnerRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testCreateOwnerSuccess() throws Exception { + void testCreateOwnerSuccess() throws Exception { OwnerDto newOwnerDto = owners.get(0); newOwnerDto.setId(null); ObjectMapper mapper = new ObjectMapper(); @@ -198,7 +189,7 @@ public class OwnerRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testCreateOwnerErrorIdSpecified() throws Exception { + void testCreateOwnerErrorIdSpecified() throws Exception { OwnerDto newOwnerDto = owners.get(0); newOwnerDto.setId(999); ObjectMapper mapper = new ObjectMapper(); @@ -214,7 +205,7 @@ public class OwnerRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testCreateOwnerError() throws Exception { + void testCreateOwnerError() throws Exception { OwnerDto newOwnerDto = owners.get(0); newOwnerDto.setId(null); newOwnerDto.setFirstName(null); @@ -229,7 +220,7 @@ public class OwnerRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testUpdateOwnerSuccess() throws Exception { + void testUpdateOwnerSuccess() throws Exception { given(this.clinicService.findOwnerById(1)).willReturn(ownerMapper.toOwner(owners.get(0))); int ownerId = owners.get(0).getId(); OwnerDto updatedOwnerDto = new OwnerDto(); @@ -260,7 +251,7 @@ public class OwnerRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testUpdateOwnerSuccessNoBodyId() throws Exception { + void testUpdateOwnerSuccessNoBodyId() throws Exception { given(this.clinicService.findOwnerById(1)).willReturn(ownerMapper.toOwner(owners.get(0))); int ownerId = owners.get(0).getId(); OwnerDto updatedOwnerDto = new OwnerDto(); @@ -288,7 +279,7 @@ public class OwnerRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testUpdateOwnerErrorBodyIdMismatchWithPathId() throws Exception { + void testUpdateOwnerErrorBodyIdMismatchWithPathId() throws Exception { int ownerId = owners.get(0).getId(); OwnerDto updatedOwnerDto = new OwnerDto(); // body.id != ownerId @@ -309,7 +300,7 @@ public class OwnerRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testUpdateOwnerError() throws Exception { + void testUpdateOwnerError() throws Exception { OwnerDto newOwnerDto = owners.get(0); newOwnerDto.setFirstName(""); ObjectMapper mapper = new ObjectMapper(); @@ -321,7 +312,7 @@ public class OwnerRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testDeleteOwnerSuccess() throws Exception { + void testDeleteOwnerSuccess() throws Exception { OwnerDto newOwnerDto = owners.get(0); ObjectMapper mapper = new ObjectMapper(); String newOwnerAsJSON = mapper.writeValueAsString(newOwnerDto); @@ -334,7 +325,7 @@ public class OwnerRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testDeleteOwnerError() throws Exception { + void testDeleteOwnerError() throws Exception { OwnerDto newOwnerDto = owners.get(0); ObjectMapper mapper = new ObjectMapper(); String newOwnerAsJSON = mapper.writeValueAsString(newOwnerDto); diff --git a/src/test/java/org/springframework/samples/petclinic/rest/PetRestControllerTests.java b/src/test/java/org/springframework/samples/petclinic/rest/PetRestControllerTests.java index dc34a5232da9f5b4bff2afea81dc6b5f67ec4381..2297d11282e9e3ba2d48bc7a9a3f3afe15b8b76d 100644 --- a/src/test/java/org/springframework/samples/petclinic/rest/PetRestControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/rest/PetRestControllerTests.java @@ -19,9 +19,8 @@ package org.springframework.samples.petclinic.rest; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -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.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -35,7 +34,6 @@ import org.springframework.samples.petclinic.service.ClinicService; import org.springframework.samples.petclinic.service.clinicService.ApplicationTestConfig; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; @@ -60,10 +58,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. */ @SpringBootTest -@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = ApplicationTestConfig.class) @WebAppConfiguration -public class PetRestControllerTests { +class PetRestControllerTests { @MockBean protected ClinicService clinicService; @@ -75,8 +72,8 @@ public class PetRestControllerTests { private List<PetDto> pets; - @Before - public void initPets() { + @BeforeEach + void initPets() { this.mockMvc = MockMvcBuilders.standaloneSetup(petRestController) .setControllerAdvice(new ExceptionControllerAdvice()) .build(); @@ -108,7 +105,7 @@ public class PetRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testGetPetSuccess() throws Exception { + void testGetPetSuccess() throws Exception { given(this.clinicService.findPetById(3)).willReturn(petMapper.toPet(pets.get(0))); this.mockMvc.perform(get("/api/pets/3") .accept(MediaType.APPLICATION_JSON_VALUE)) @@ -120,7 +117,7 @@ public class PetRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testGetPetNotFound() throws Exception { + void testGetPetNotFound() throws Exception { given(petMapper.toPetDto(this.clinicService.findPetById(-1))).willReturn(null); this.mockMvc.perform(get("/api/pets/-1") .accept(MediaType.APPLICATION_JSON)) @@ -129,7 +126,7 @@ public class PetRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testGetAllPetsSuccess() throws Exception { + void testGetAllPetsSuccess() throws Exception { final Collection<Pet> pets = petMapper.toPets(this.pets); System.err.println(pets); when(this.clinicService.findAllPets()).thenReturn(pets); @@ -146,7 +143,7 @@ public class PetRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testGetAllPetsNotFound() throws Exception { + void testGetAllPetsNotFound() throws Exception { pets.clear(); given(this.clinicService.findAllPets()).willReturn(petMapper.toPets(pets)); this.mockMvc.perform(get("/api/pets/") @@ -156,7 +153,7 @@ public class PetRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testCreatePetSuccess() throws Exception { + void testCreatePetSuccess() throws Exception { PetDto newPet = pets.get(0); newPet.setId(999); ObjectMapper mapper = new ObjectMapper(); @@ -172,7 +169,7 @@ public class PetRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testCreatePetError() throws Exception { + void testCreatePetError() throws Exception { PetDto newPet = pets.get(0); newPet.setId(null); newPet.setName(null); @@ -187,7 +184,7 @@ public class PetRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testUpdatePetSuccess() throws Exception { + void testUpdatePetSuccess() throws Exception { given(this.clinicService.findPetById(3)).willReturn(petMapper.toPet(pets.get(0))); PetDto newPet = pets.get(0); newPet.setName("Rosy I"); @@ -213,7 +210,7 @@ public class PetRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testUpdatePetError() throws Exception { + void testUpdatePetError() throws Exception { PetDto newPet = pets.get(0); newPet.setName(null); ObjectMapper mapper = new ObjectMapper(); @@ -228,7 +225,7 @@ public class PetRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testDeletePetSuccess() throws Exception { + void testDeletePetSuccess() throws Exception { PetDto newPet = pets.get(0); ObjectMapper mapper = new ObjectMapper(); String newPetAsJSON = mapper.writeValueAsString(newPet); @@ -240,7 +237,7 @@ public class PetRestControllerTests { @Test @WithMockUser(roles = "OWNER_ADMIN") - public void testDeletePetError() throws Exception { + void testDeletePetError() throws Exception { PetDto newPet = pets.get(0); ObjectMapper mapper = new ObjectMapper(); String newPetAsJSON = mapper.writeValueAsString(newPet); diff --git a/src/test/java/org/springframework/samples/petclinic/rest/PetTypeRestControllerTests.java b/src/test/java/org/springframework/samples/petclinic/rest/PetTypeRestControllerTests.java index baeb6983cd07d377996df862a4ad1f3f7c95af81..4955d5a1cb3c385a44f2346c2b534bd21db511d6 100644 --- a/src/test/java/org/springframework/samples/petclinic/rest/PetTypeRestControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/rest/PetTypeRestControllerTests.java @@ -17,9 +17,8 @@ package org.springframework.samples.petclinic.rest; import com.fasterxml.jackson.databind.ObjectMapper; -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.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -30,7 +29,6 @@ import org.springframework.samples.petclinic.service.ClinicService; import org.springframework.samples.petclinic.service.clinicService.ApplicationTestConfig; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -49,10 +47,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * @author Vitaliy Fedoriv */ @SpringBootTest -@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes=ApplicationTestConfig.class) @WebAppConfiguration -public class PetTypeRestControllerTests { +class PetTypeRestControllerTests { @Autowired private PetTypeRestController petTypeRestController; @@ -67,8 +64,8 @@ public class PetTypeRestControllerTests { private List<PetType> petTypes; - @Before - public void initPetTypes(){ + @BeforeEach + void initPetTypes(){ this.mockMvc = MockMvcBuilders.standaloneSetup(petTypeRestController) .setControllerAdvice(new ExceptionControllerAdvice()) .build(); @@ -97,7 +94,7 @@ public class PetTypeRestControllerTests { @Test @WithMockUser(roles="OWNER_ADMIN") - public void testGetPetTypeSuccessAsOwnerAdmin() throws Exception { + void testGetPetTypeSuccessAsOwnerAdmin() throws Exception { given(this.clinicService.findPetTypeById(1)).willReturn(petTypes.get(0)); this.mockMvc.perform(get("/api/pettypes/1") .accept(MediaType.APPLICATION_JSON_VALUE)) @@ -109,7 +106,7 @@ public class PetTypeRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testGetPetTypeSuccessAsVetAdmin() throws Exception { + void testGetPetTypeSuccessAsVetAdmin() throws Exception { given(this.clinicService.findPetTypeById(1)).willReturn(petTypes.get(0)); this.mockMvc.perform(get("/api/pettypes/1") .accept(MediaType.APPLICATION_JSON_VALUE)) @@ -121,7 +118,7 @@ public class PetTypeRestControllerTests { @Test @WithMockUser(roles="OWNER_ADMIN") - public void testGetPetTypeNotFound() throws Exception { + void testGetPetTypeNotFound() throws Exception { given(this.clinicService.findPetTypeById(-1)).willReturn(null); this.mockMvc.perform(get("/api/pettypes/-1") .accept(MediaType.APPLICATION_JSON)) @@ -130,7 +127,7 @@ public class PetTypeRestControllerTests { @Test @WithMockUser(roles="OWNER_ADMIN") - public void testGetAllPetTypesSuccessAsOwnerAdmin() throws Exception { + void testGetAllPetTypesSuccessAsOwnerAdmin() throws Exception { petTypes.remove(0); petTypes.remove(1); given(this.clinicService.findAllPetTypes()).willReturn(petTypes); @@ -146,7 +143,7 @@ public class PetTypeRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testGetAllPetTypesSuccessAsVetAdmin() throws Exception { + void testGetAllPetTypesSuccessAsVetAdmin() throws Exception { petTypes.remove(0); petTypes.remove(1); given(this.clinicService.findAllPetTypes()).willReturn(petTypes); @@ -162,7 +159,7 @@ public class PetTypeRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testGetAllPetTypesNotFound() throws Exception { + void testGetAllPetTypesNotFound() throws Exception { petTypes.clear(); given(this.clinicService.findAllPetTypes()).willReturn(petTypes); this.mockMvc.perform(get("/api/pettypes/") @@ -172,7 +169,7 @@ public class PetTypeRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testCreatePetTypeSuccess() throws Exception { + void testCreatePetTypeSuccess() throws Exception { PetType newPetType = petTypes.get(0); newPetType.setId(999); ObjectMapper mapper = new ObjectMapper(); @@ -184,7 +181,7 @@ public class PetTypeRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testCreatePetTypeError() throws Exception { + void testCreatePetTypeError() throws Exception { PetType newPetType = petTypes.get(0); newPetType.setId(null); newPetType.setName(null); @@ -197,7 +194,7 @@ public class PetTypeRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testUpdatePetTypeSuccess() throws Exception { + void testUpdatePetTypeSuccess() throws Exception { given(this.clinicService.findPetTypeById(2)).willReturn(petTypes.get(1)); PetType newPetType = petTypes.get(1); newPetType.setName("dog I"); @@ -218,7 +215,7 @@ public class PetTypeRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testUpdatePetTypeError() throws Exception { + void testUpdatePetTypeError() throws Exception { PetType newPetType = petTypes.get(0); newPetType.setName(""); ObjectMapper mapper = new ObjectMapper(); @@ -230,7 +227,7 @@ public class PetTypeRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testDeletePetTypeSuccess() throws Exception { + void testDeletePetTypeSuccess() throws Exception { PetType newPetType = petTypes.get(0); ObjectMapper mapper = new ObjectMapper(); String newPetTypeAsJSON = mapper.writeValueAsString(newPetType); @@ -242,7 +239,7 @@ public class PetTypeRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testDeletePetTypeError() throws Exception { + void testDeletePetTypeError() throws Exception { PetType newPetType = petTypes.get(0); ObjectMapper mapper = new ObjectMapper(); String newPetTypeAsJSON = mapper.writeValueAsString(petTypeMapper.toPetTypeDto(newPetType)); diff --git a/src/test/java/org/springframework/samples/petclinic/rest/SpecialtyRestControllerTests.java b/src/test/java/org/springframework/samples/petclinic/rest/SpecialtyRestControllerTests.java index 023a8663dc5d27998dd549d1ad292118359497d3..3e6a2ff347148cc2380367303c06c26a43235d2b 100644 --- a/src/test/java/org/springframework/samples/petclinic/rest/SpecialtyRestControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/rest/SpecialtyRestControllerTests.java @@ -17,9 +17,8 @@ package org.springframework.samples.petclinic.rest; import com.fasterxml.jackson.databind.ObjectMapper; -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.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -30,7 +29,6 @@ import org.springframework.samples.petclinic.service.ClinicService; import org.springframework.samples.petclinic.service.clinicService.ApplicationTestConfig; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -48,10 +46,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * @author Vitaliy Fedoriv */ @SpringBootTest -@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes=ApplicationTestConfig.class) @WebAppConfiguration -public class SpecialtyRestControllerTests { +class SpecialtyRestControllerTests { @Autowired private SpecialtyRestController specialtyRestController; @@ -66,8 +63,8 @@ public class SpecialtyRestControllerTests { private List<Specialty> specialties; - @Before - public void initSpecialtys(){ + @BeforeEach + void initSpecialtys(){ this.mockMvc = MockMvcBuilders.standaloneSetup(specialtyRestController) .setControllerAdvice(new ExceptionControllerAdvice()) .build(); @@ -92,7 +89,7 @@ public class SpecialtyRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testGetSpecialtySuccess() throws Exception { + void testGetSpecialtySuccess() throws Exception { given(this.clinicService.findSpecialtyById(1)).willReturn(specialties.get(0)); this.mockMvc.perform(get("/api/specialties/1") .accept(MediaType.APPLICATION_JSON_VALUE)) @@ -104,7 +101,7 @@ public class SpecialtyRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testGetSpecialtyNotFound() throws Exception { + void testGetSpecialtyNotFound() throws Exception { given(this.clinicService.findSpecialtyById(-1)).willReturn(null); this.mockMvc.perform(get("/api/specialties/-1") .accept(MediaType.APPLICATION_JSON)) @@ -113,7 +110,7 @@ public class SpecialtyRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testGetAllSpecialtysSuccess() throws Exception { + void testGetAllSpecialtysSuccess() throws Exception { specialties.remove(0); given(this.clinicService.findAllSpecialties()).willReturn(specialties); this.mockMvc.perform(get("/api/specialties/") @@ -128,7 +125,7 @@ public class SpecialtyRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testGetAllSpecialtysNotFound() throws Exception { + void testGetAllSpecialtysNotFound() throws Exception { specialties.clear(); given(this.clinicService.findAllSpecialties()).willReturn(specialties); this.mockMvc.perform(get("/api/specialties/") @@ -138,7 +135,7 @@ public class SpecialtyRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testCreateSpecialtySuccess() throws Exception { + void testCreateSpecialtySuccess() throws Exception { Specialty newSpecialty = specialties.get(0); newSpecialty.setId(999); ObjectMapper mapper = new ObjectMapper(); @@ -150,7 +147,7 @@ public class SpecialtyRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testCreateSpecialtyError() throws Exception { + void testCreateSpecialtyError() throws Exception { Specialty newSpecialty = specialties.get(0); newSpecialty.setId(null); newSpecialty.setName(null); @@ -163,7 +160,7 @@ public class SpecialtyRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testUpdateSpecialtySuccess() throws Exception { + void testUpdateSpecialtySuccess() throws Exception { given(this.clinicService.findSpecialtyById(2)).willReturn(specialties.get(1)); Specialty newSpecialty = specialties.get(1); newSpecialty.setName("surgery I"); @@ -184,7 +181,7 @@ public class SpecialtyRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testUpdateSpecialtyError() throws Exception { + void testUpdateSpecialtyError() throws Exception { Specialty newSpecialty = specialties.get(0); newSpecialty.setName(""); ObjectMapper mapper = new ObjectMapper(); @@ -196,7 +193,7 @@ public class SpecialtyRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testDeleteSpecialtySuccess() throws Exception { + void testDeleteSpecialtySuccess() throws Exception { Specialty newSpecialty = specialties.get(0); ObjectMapper mapper = new ObjectMapper(); String newSpecialtyAsJSON = mapper.writeValueAsString(specialtyMapper.toSpecialtyDto(newSpecialty)); @@ -208,7 +205,7 @@ public class SpecialtyRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testDeleteSpecialtyError() throws Exception { + void testDeleteSpecialtyError() throws Exception { Specialty newSpecialty = specialties.get(0); ObjectMapper mapper = new ObjectMapper(); String newSpecialtyAsJSON = mapper.writeValueAsString(specialtyMapper.toSpecialtyDto(newSpecialty)); diff --git a/src/test/java/org/springframework/samples/petclinic/rest/UserRestControllerTests.java b/src/test/java/org/springframework/samples/petclinic/rest/UserRestControllerTests.java index 72d70c36149a98e711c9f941c04aece4e48c59bc..58fe91b38901a0160c35a1b9992ecf5b7c574f4d 100644 --- a/src/test/java/org/springframework/samples/petclinic/rest/UserRestControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/rest/UserRestControllerTests.java @@ -1,9 +1,8 @@ package org.springframework.samples.petclinic.rest; import com.fasterxml.jackson.databind.ObjectMapper; -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.mockito.Mock; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -14,7 +13,6 @@ import org.springframework.samples.petclinic.service.UserService; import org.springframework.samples.petclinic.service.clinicService.ApplicationTestConfig; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -23,10 +21,9 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @SpringBootTest -@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = ApplicationTestConfig.class) @WebAppConfiguration -public class UserRestControllerTests { +class UserRestControllerTests { @Mock private UserService userService; @@ -39,15 +36,15 @@ public class UserRestControllerTests { private MockMvc mockMvc; - @Before - public void initVets() { + @BeforeEach + void initVets() { this.mockMvc = MockMvcBuilders.standaloneSetup(userRestController) .setControllerAdvice(new ExceptionControllerAdvice()).build(); } @Test @WithMockUser(roles = "ADMIN") - public void testCreateUserSuccess() throws Exception { + void testCreateUserSuccess() throws Exception { User user = new User(); user.setUsername("username"); user.setPassword("password"); @@ -62,7 +59,7 @@ public class UserRestControllerTests { @Test @WithMockUser(roles = "ADMIN") - public void testCreateUserError() throws Exception { + void testCreateUserError() throws Exception { User user = new User(); user.setUsername("username"); user.setPassword("password"); diff --git a/src/test/java/org/springframework/samples/petclinic/rest/VetRestControllerTests.java b/src/test/java/org/springframework/samples/petclinic/rest/VetRestControllerTests.java index 7b90a41f60a04e21eedd2f0e0dcd019ff264f850..11429c1c5f9dc01d8983a30255ca3ae34cb64334 100644 --- a/src/test/java/org/springframework/samples/petclinic/rest/VetRestControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/rest/VetRestControllerTests.java @@ -17,9 +17,8 @@ package org.springframework.samples.petclinic.rest; import com.fasterxml.jackson.databind.ObjectMapper; -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.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -30,7 +29,6 @@ import org.springframework.samples.petclinic.service.ClinicService; import org.springframework.samples.petclinic.service.clinicService.ApplicationTestConfig; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -48,10 +46,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * @author Vitaliy Fedoriv */ @SpringBootTest -@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes=ApplicationTestConfig.class) @WebAppConfiguration -public class VetRestControllerTests { +class VetRestControllerTests { @Autowired private VetRestController vetRestController; @@ -66,8 +63,8 @@ public class VetRestControllerTests { private List<Vet> vets; - @Before - public void initVets(){ + @BeforeEach + void initVets(){ this.mockMvc = MockMvcBuilders.standaloneSetup(vetRestController) .setControllerAdvice(new ExceptionControllerAdvice()) .build(); @@ -95,7 +92,7 @@ public class VetRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testGetVetSuccess() throws Exception { + void testGetVetSuccess() throws Exception { given(this.clinicService.findVetById(1)).willReturn(vets.get(0)); this.mockMvc.perform(get("/api/vets/1") .accept(MediaType.APPLICATION_JSON_VALUE)) @@ -107,7 +104,7 @@ public class VetRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testGetVetNotFound() throws Exception { + void testGetVetNotFound() throws Exception { given(this.clinicService.findVetById(-1)).willReturn(null); this.mockMvc.perform(get("/api/vets/-1") .accept(MediaType.APPLICATION_JSON)) @@ -116,7 +113,7 @@ public class VetRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testGetAllVetsSuccess() throws Exception { + void testGetAllVetsSuccess() throws Exception { given(this.clinicService.findAllVets()).willReturn(vets); this.mockMvc.perform(get("/api/vets/") .accept(MediaType.APPLICATION_JSON)) @@ -130,7 +127,7 @@ public class VetRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testGetAllVetsNotFound() throws Exception { + void testGetAllVetsNotFound() throws Exception { vets.clear(); given(this.clinicService.findAllVets()).willReturn(vets); this.mockMvc.perform(get("/api/vets/") @@ -140,7 +137,7 @@ public class VetRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testCreateVetSuccess() throws Exception { + void testCreateVetSuccess() throws Exception { Vet newVet = vets.get(0); newVet.setId(999); ObjectMapper mapper = new ObjectMapper(); @@ -152,7 +149,7 @@ public class VetRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testCreateVetError() throws Exception { + void testCreateVetError() throws Exception { Vet newVet = vets.get(0); newVet.setId(null); newVet.setFirstName(null); @@ -165,7 +162,7 @@ public class VetRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testUpdateVetSuccess() throws Exception { + void testUpdateVetSuccess() throws Exception { given(this.clinicService.findVetById(1)).willReturn(vets.get(0)); Vet newVet = vets.get(0); newVet.setFirstName("James"); @@ -187,7 +184,7 @@ public class VetRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testUpdateVetError() throws Exception { + void testUpdateVetError() throws Exception { Vet newVet = vets.get(0); newVet.setFirstName(null); ObjectMapper mapper = new ObjectMapper(); @@ -199,7 +196,7 @@ public class VetRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testDeleteVetSuccess() throws Exception { + void testDeleteVetSuccess() throws Exception { Vet newVet = vets.get(0); ObjectMapper mapper = new ObjectMapper(); String newVetAsJSON = mapper.writeValueAsString(vetMapper.toVetDto(newVet)); @@ -211,7 +208,7 @@ public class VetRestControllerTests { @Test @WithMockUser(roles="VET_ADMIN") - public void testDeleteVetError() throws Exception { + void testDeleteVetError() throws Exception { Vet newVet = vets.get(0); ObjectMapper mapper = new ObjectMapper(); String newVetAsJSON = mapper.writeValueAsString(vetMapper.toVetDto(newVet)); diff --git a/src/test/java/org/springframework/samples/petclinic/rest/VisitRestControllerTests.java b/src/test/java/org/springframework/samples/petclinic/rest/VisitRestControllerTests.java index a664a0c1db65f3dbb5630d34ac7bf189e33c0903..33cad05641ff946b9a2321d7437dc5b3adcd1cf8 100644 --- a/src/test/java/org/springframework/samples/petclinic/rest/VisitRestControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/rest/VisitRestControllerTests.java @@ -19,9 +19,8 @@ package org.springframework.samples.petclinic.rest; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -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.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -35,7 +34,6 @@ import org.springframework.samples.petclinic.service.ClinicService; import org.springframework.samples.petclinic.service.clinicService.ApplicationTestConfig; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -54,10 +52,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * @author Vitaliy Fedoriv */ @SpringBootTest -@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes=ApplicationTestConfig.class) @WebAppConfiguration -public class VisitRestControllerTests { +class VisitRestControllerTests { @Autowired private VisitRestController visitRestController; @@ -72,8 +69,8 @@ public class VisitRestControllerTests { private List<Visit> visits; - @Before - public void initVisits(){ + @BeforeEach + void initVisits(){ this.mockMvc = MockMvcBuilders.standaloneSetup(visitRestController) .setControllerAdvice(new ExceptionControllerAdvice()) .build(); @@ -119,7 +116,7 @@ public class VisitRestControllerTests { @Test @WithMockUser(roles="OWNER_ADMIN") - public void testGetVisitSuccess() throws Exception { + void testGetVisitSuccess() throws Exception { given(this.clinicService.findVisitById(2)).willReturn(visits.get(0)); this.mockMvc.perform(get("/api/visits/2") .accept(MediaType.APPLICATION_JSON_VALUE)) @@ -131,7 +128,7 @@ public class VisitRestControllerTests { @Test @WithMockUser(roles="OWNER_ADMIN") - public void testGetVisitNotFound() throws Exception { + void testGetVisitNotFound() throws Exception { given(this.clinicService.findVisitById(-1)).willReturn(null); this.mockMvc.perform(get("/api/visits/-1") .accept(MediaType.APPLICATION_JSON)) @@ -140,7 +137,7 @@ public class VisitRestControllerTests { @Test @WithMockUser(roles="OWNER_ADMIN") - public void testGetAllVisitsSuccess() throws Exception { + void testGetAllVisitsSuccess() throws Exception { given(this.clinicService.findAllVisits()).willReturn(visits); this.mockMvc.perform(get("/api/visits/") .accept(MediaType.APPLICATION_JSON)) @@ -154,7 +151,7 @@ public class VisitRestControllerTests { @Test @WithMockUser(roles="OWNER_ADMIN") - public void testGetAllVisitsNotFound() throws Exception { + void testGetAllVisitsNotFound() throws Exception { visits.clear(); given(this.clinicService.findAllVisits()).willReturn(visits); this.mockMvc.perform(get("/api/visits/") @@ -164,7 +161,7 @@ public class VisitRestControllerTests { @Test @WithMockUser(roles="OWNER_ADMIN") - public void testCreateVisitSuccess() throws Exception { + void testCreateVisitSuccess() throws Exception { Visit newVisit = visits.get(0); newVisit.setId(999); ObjectMapper mapper = new ObjectMapper(); @@ -178,7 +175,7 @@ public class VisitRestControllerTests { } @WithMockUser(roles="OWNER_ADMIN") - public void testCreateVisitError() throws Exception { + void testCreateVisitError() throws Exception { Visit newVisit = visits.get(0); newVisit.setId(null); newVisit.setDescription(null); @@ -191,7 +188,7 @@ public class VisitRestControllerTests { @Test @WithMockUser(roles="OWNER_ADMIN") - public void testUpdateVisitSuccess() throws Exception { + void testUpdateVisitSuccess() throws Exception { given(this.clinicService.findVisitById(2)).willReturn(visits.get(0)); Visit newVisit = visits.get(0); newVisit.setDescription("rabies shot test"); @@ -213,7 +210,7 @@ public class VisitRestControllerTests { } @WithMockUser(roles="OWNER_ADMIN") - public void testUpdateVisitError() throws Exception { + void testUpdateVisitError() throws Exception { Visit newVisit = visits.get(0); newVisit.setDescription(null); ObjectMapper mapper = new ObjectMapper(); @@ -225,7 +222,7 @@ public class VisitRestControllerTests { @Test @WithMockUser(roles="OWNER_ADMIN") - public void testDeleteVisitSuccess() throws Exception { + void testDeleteVisitSuccess() throws Exception { Visit newVisit = visits.get(0); ObjectMapper mapper = new ObjectMapper(); String newVisitAsJSON = mapper.writeValueAsString(visitMapper.toVisitDto(newVisit)); @@ -237,7 +234,7 @@ public class VisitRestControllerTests { @Test @WithMockUser(roles="OWNER_ADMIN") - public void testDeleteVisitError() throws Exception { + void testDeleteVisitError() throws Exception { Visit newVisit = visits.get(0); ObjectMapper mapper = new ObjectMapper(); String newVisitAsJSON = mapper.writeValueAsString(visitMapper.toVisitDto(newVisit)); diff --git a/src/test/java/org/springframework/samples/petclinic/service/clinicService/AbstractClinicServiceTests.java b/src/test/java/org/springframework/samples/petclinic/service/clinicService/AbstractClinicServiceTests.java index 333634259de52ac3d5690f5be58ec6c08390bcd8..eb3d8ea7c4a3625518ece2b1d7e26509bc0ac9cb 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/clinicService/AbstractClinicServiceTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/clinicService/AbstractClinicServiceTests.java @@ -15,8 +15,7 @@ */ package org.springframework.samples.petclinic.service.clinicService; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.samples.petclinic.model.*; import org.springframework.samples.petclinic.service.ClinicService; @@ -49,13 +48,13 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Michael Isvy * @author Vitaliy Fedoriv */ -public abstract class AbstractClinicServiceTests { +abstract class AbstractClinicServiceTests { @Autowired protected ClinicService clinicService; @Test - public void shouldFindOwnersByLastName() { + void shouldFindOwnersByLastName() { Collection<Owner> owners = this.clinicService.findOwnerByLastName("Davis"); assertThat(owners.size()).isEqualTo(2); @@ -64,7 +63,7 @@ public abstract class AbstractClinicServiceTests { } @Test - public void shouldFindSingleOwnerWithPet() { + void shouldFindSingleOwnerWithPet() { Owner owner = this.clinicService.findOwnerById(1); assertThat(owner.getLastName()).startsWith("Franklin"); assertThat(owner.getPets().size()).isEqualTo(1); @@ -74,7 +73,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void shouldInsertOwner() { + void shouldInsertOwner() { Collection<Owner> owners = this.clinicService.findOwnerByLastName("Schultz"); int found = owners.size(); @@ -93,7 +92,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void shouldUpdateOwner() { + void shouldUpdateOwner() { Owner owner = this.clinicService.findOwnerById(1); String oldLastName = owner.getLastName(); String newLastName = oldLastName + "X"; @@ -107,7 +106,7 @@ public abstract class AbstractClinicServiceTests { } @Test - public void shouldFindPetWithCorrectId() { + void shouldFindPetWithCorrectId() { Pet pet7 = this.clinicService.findPetById(7); assertThat(pet7.getName()).startsWith("Samantha"); assertThat(pet7.getOwner().getFirstName()).isEqualTo("Jean"); @@ -115,7 +114,7 @@ public abstract class AbstractClinicServiceTests { } // @Test -// public void shouldFindAllPetTypes() { +// void shouldFindAllPetTypes() { // Collection<PetType> petTypes = this.clinicService.findPetTypes(); // // PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1); @@ -126,7 +125,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void shouldInsertPetIntoDatabaseAndGenerateId() { + void shouldInsertPetIntoDatabaseAndGenerateId() { Owner owner6 = this.clinicService.findOwnerById(6); int found = owner6.getPets().size(); @@ -149,7 +148,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void shouldUpdatePetName() throws Exception { + void shouldUpdatePetName() throws Exception { Pet pet7 = this.clinicService.findPetById(7); String oldName = pet7.getName(); @@ -162,7 +161,7 @@ public abstract class AbstractClinicServiceTests { } @Test - public void shouldFindVets() { + void shouldFindVets() { Collection<Vet> vets = this.clinicService.findVets(); Vet vet = EntityUtils.getById(vets, Vet.class, 3); @@ -174,7 +173,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void shouldAddNewVisitForPet() { + void shouldAddNewVisitForPet() { Pet pet7 = this.clinicService.findPetById(7); int found = pet7.getVisits().size(); Visit visit = new Visit(); @@ -189,7 +188,7 @@ public abstract class AbstractClinicServiceTests { } @Test - public void shouldFindVisitsByPetId() throws Exception { + void shouldFindVisitsByPetId() throws Exception { Collection<Visit> visits = this.clinicService.findVisitsByPetId(7); assertThat(visits.size()).isEqualTo(2); Visit[] visitArr = visits.toArray(new Visit[visits.size()]); @@ -199,7 +198,7 @@ public abstract class AbstractClinicServiceTests { } @Test - public void shouldFindAllPets(){ + void shouldFindAllPets(){ Collection<Pet> pets = this.clinicService.findAllPets(); Pet pet1 = EntityUtils.getById(pets, Pet.class, 1); assertThat(pet1.getName()).isEqualTo("Leo"); @@ -209,7 +208,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void shouldDeletePet(){ + void shouldDeletePet(){ Pet pet = this.clinicService.findPetById(1); this.clinicService.deletePet(pet); try { @@ -221,14 +220,14 @@ public abstract class AbstractClinicServiceTests { } @Test - public void shouldFindVisitDyId(){ + void shouldFindVisitDyId(){ Visit visit = this.clinicService.findVisitById(1); assertThat(visit.getId()).isEqualTo(1); assertThat(visit.getPet().getName()).isEqualTo("Samantha"); } @Test - public void shouldFindAllVisits(){ + void shouldFindAllVisits(){ Collection<Visit> visits = this.clinicService.findAllVisits(); Visit visit1 = EntityUtils.getById(visits, Visit.class, 1); assertThat(visit1.getPet().getName()).isEqualTo("Samantha"); @@ -238,7 +237,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void shouldInsertVisit() { + void shouldInsertVisit() { Collection<Visit> visits = this.clinicService.findAllVisits(); int found = visits.size(); @@ -259,7 +258,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void shouldUpdateVisit(){ + void shouldUpdateVisit(){ Visit visit = this.clinicService.findVisitById(1); String oldDesc = visit.getDescription(); String newDesc = oldDesc + "X"; @@ -271,7 +270,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void shouldDeleteVisit(){ + void shouldDeleteVisit(){ Visit visit = this.clinicService.findVisitById(1); this.clinicService.deleteVisit(visit); try { @@ -283,7 +282,7 @@ public abstract class AbstractClinicServiceTests { } @Test - public void shouldFindVetDyId(){ + void shouldFindVetDyId(){ Vet vet = this.clinicService.findVetById(1); assertThat(vet.getFirstName()).isEqualTo("James"); assertThat(vet.getLastName()).isEqualTo("Carter"); @@ -291,7 +290,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void shouldInsertVet() { + void shouldInsertVet() { Collection<Vet> vets = this.clinicService.findAllVets(); int found = vets.size(); @@ -308,7 +307,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void shouldUpdateVet(){ + void shouldUpdateVet(){ Vet vet = this.clinicService.findVetById(1); String oldLastName = vet.getLastName(); String newLastName = oldLastName + "X"; @@ -320,7 +319,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void shouldDeleteVet(){ + void shouldDeleteVet(){ Vet vet = this.clinicService.findVetById(1); this.clinicService.deleteVet(vet); try { @@ -332,7 +331,7 @@ public abstract class AbstractClinicServiceTests { } @Test - public void shouldFindAllOwners(){ + void shouldFindAllOwners(){ Collection<Owner> owners = this.clinicService.findAllOwners(); Owner owner1 = EntityUtils.getById(owners, Owner.class, 1); assertThat(owner1.getFirstName()).isEqualTo("George"); @@ -342,7 +341,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void shouldDeleteOwner(){ + void shouldDeleteOwner(){ Owner owner = this.clinicService.findOwnerById(1); this.clinicService.deleteOwner(owner); try { @@ -354,13 +353,13 @@ public abstract class AbstractClinicServiceTests { } @Test - public void shouldFindPetTypeById(){ + void shouldFindPetTypeById(){ PetType petType = this.clinicService.findPetTypeById(1); assertThat(petType.getName()).isEqualTo("cat"); } @Test - public void shouldFindAllPetTypes(){ + void shouldFindAllPetTypes(){ Collection<PetType> petTypes = this.clinicService.findAllPetTypes(); PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1); assertThat(petType1.getName()).isEqualTo("cat"); @@ -370,7 +369,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void shouldInsertPetType() { + void shouldInsertPetType() { Collection<PetType> petTypes = this.clinicService.findAllPetTypes(); int found = petTypes.size(); @@ -386,7 +385,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void shouldUpdatePetType(){ + void shouldUpdatePetType(){ PetType petType = this.clinicService.findPetTypeById(1); String oldLastName = petType.getName(); String newLastName = oldLastName + "X"; @@ -398,7 +397,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void shouldDeletePetType(){ + void shouldDeletePetType(){ PetType petType = this.clinicService.findPetTypeById(1); this.clinicService.deletePetType(petType); try { @@ -410,13 +409,13 @@ public abstract class AbstractClinicServiceTests { } @Test - public void shouldFindSpecialtyById(){ + void shouldFindSpecialtyById(){ Specialty specialty = this.clinicService.findSpecialtyById(1); assertThat(specialty.getName()).isEqualTo("radiology"); } @Test - public void shouldFindAllSpecialtys(){ + void shouldFindAllSpecialtys(){ Collection<Specialty> specialties = this.clinicService.findAllSpecialties(); Specialty specialty1 = EntityUtils.getById(specialties, Specialty.class, 1); assertThat(specialty1.getName()).isEqualTo("radiology"); @@ -426,7 +425,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void shouldInsertSpecialty() { + void shouldInsertSpecialty() { Collection<Specialty> specialties = this.clinicService.findAllSpecialties(); int found = specialties.size(); @@ -442,7 +441,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void shouldUpdateSpecialty(){ + void shouldUpdateSpecialty(){ Specialty specialty = this.clinicService.findSpecialtyById(1); String oldLastName = specialty.getName(); String newLastName = oldLastName + "X"; @@ -454,7 +453,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void shouldDeleteSpecialty(){ + void shouldDeleteSpecialty(){ Specialty specialty = new Specialty(); specialty.setName("test"); this.clinicService.saveSpecialty(specialty); diff --git a/src/test/java/org/springframework/samples/petclinic/service/clinicService/ClinicServiceJdbcTests.java b/src/test/java/org/springframework/samples/petclinic/service/clinicService/ClinicServiceJdbcTests.java index 06623fec7dbab245c0f2db0f1a14c11a20e8ef0c..43724aa30d382a91c8312568cbb95341601d9e81 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/clinicService/ClinicServiceJdbcTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/clinicService/ClinicServiceJdbcTests.java @@ -15,10 +15,8 @@ */ package org.springframework.samples.petclinic.service.clinicService; -import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * <p> Integration test using the jdbc profile. @@ -28,9 +26,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @see AbstractClinicServiceTests AbstractClinicServiceTests for more details. </p> */ @SpringBootTest -@RunWith(SpringJUnit4ClassRunner.class) @ActiveProfiles({"jdbc", "hsqldb"}) -public class ClinicServiceJdbcTests extends AbstractClinicServiceTests { - +class ClinicServiceJdbcTests extends AbstractClinicServiceTests { } diff --git a/src/test/java/org/springframework/samples/petclinic/service/clinicService/ClinicServiceJpaTests.java b/src/test/java/org/springframework/samples/petclinic/service/clinicService/ClinicServiceJpaTests.java index 162bcb94553c96825b1677e5b24ad05668791345..1a7305079d975e7676d8d5c3f0f0ab91e5e139e1 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/clinicService/ClinicServiceJpaTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/clinicService/ClinicServiceJpaTests.java @@ -1,9 +1,7 @@ package org.springframework.samples.petclinic.service.clinicService; -import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * <p> Integration test using the jpa profile. @@ -15,8 +13,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; */ @SpringBootTest -@RunWith(SpringJUnit4ClassRunner.class) @ActiveProfiles({"jpa", "hsqldb"}) -public class ClinicServiceJpaTests extends AbstractClinicServiceTests { +class ClinicServiceJpaTests extends AbstractClinicServiceTests { } diff --git a/src/test/java/org/springframework/samples/petclinic/service/clinicService/ClinicServiceSpringDataJpaTests.java b/src/test/java/org/springframework/samples/petclinic/service/clinicService/ClinicServiceSpringDataJpaTests.java index 2b6dbc3a8d5ad25403fab1da2da026a66dfe8e9d..b5c57c0ce70e5a66ba02e11abed22aede3cd4a68 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/clinicService/ClinicServiceSpringDataJpaTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/clinicService/ClinicServiceSpringDataJpaTests.java @@ -1,9 +1,7 @@ package org.springframework.samples.petclinic.service.clinicService; -import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * <p> Integration test using the 'Spring Data' profile. @@ -13,8 +11,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; */ @SpringBootTest -@RunWith(SpringJUnit4ClassRunner.class) @ActiveProfiles({"spring-data-jpa", "hsqldb"}) -public class ClinicServiceSpringDataJpaTests extends AbstractClinicServiceTests { +class ClinicServiceSpringDataJpaTests extends AbstractClinicServiceTests { } diff --git a/src/test/java/org/springframework/samples/petclinic/service/userService/AbstractUserServiceTests.java b/src/test/java/org/springframework/samples/petclinic/service/userService/AbstractUserServiceTests.java index ef82d68d70a1f468245347171e74d53339347b87..488ce61ae13fca61afc296c40b9eea478fdc22d6 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/userService/AbstractUserServiceTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/userService/AbstractUserServiceTests.java @@ -1,22 +1,21 @@ package org.springframework.samples.petclinic.service.userService; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.startsWith; -import static org.hamcrest.MatcherAssert.assertThat; - -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.samples.petclinic.model.User; import org.springframework.samples.petclinic.service.UserService; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + public abstract class AbstractUserServiceTests { @Autowired private UserService userService; - @Before + @BeforeEach public void init() { MockitoAnnotations.initMocks(this); } diff --git a/src/test/java/org/springframework/samples/petclinic/service/userService/UserServiceJdbcTests.java b/src/test/java/org/springframework/samples/petclinic/service/userService/UserServiceJdbcTests.java index e79eb66150bba43e62b1467211f0cf57a0905979..8cfbdaf70469b7f317ba53d12b74d297e5b8d3bd 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/userService/UserServiceJdbcTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/userService/UserServiceJdbcTests.java @@ -1,13 +1,10 @@ package org.springframework.samples.petclinic.service.userService; -import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @SpringBootTest -@RunWith(SpringJUnit4ClassRunner.class) @ActiveProfiles({"jdbc", "hsqldb"}) -public class UserServiceJdbcTests extends AbstractUserServiceTests { +class UserServiceJdbcTests extends AbstractUserServiceTests { } diff --git a/src/test/java/org/springframework/samples/petclinic/service/userService/UserServiceJpaTests.java b/src/test/java/org/springframework/samples/petclinic/service/userService/UserServiceJpaTests.java index 75210fec435efa43b5fbde67c7ccb7e5e6d7b3eb..0db9a1276f269e39e814a6487a97ce81711acdd2 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/userService/UserServiceJpaTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/userService/UserServiceJpaTests.java @@ -1,13 +1,10 @@ package org.springframework.samples.petclinic.service.userService; -import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @SpringBootTest -@RunWith(SpringJUnit4ClassRunner.class) @ActiveProfiles({"jpa", "hsqldb"}) -public class UserServiceJpaTests extends AbstractUserServiceTests { +class UserServiceJpaTests extends AbstractUserServiceTests { } diff --git a/src/test/java/org/springframework/samples/petclinic/service/userService/UserServiceSpringDataJpaTests.java b/src/test/java/org/springframework/samples/petclinic/service/userService/UserServiceSpringDataJpaTests.java index 3d077ba32bfd12fd257d15b01cd15243a8770f5d..d7240c81de2b191a7ee5a8879d7f207171d20016 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/userService/UserServiceSpringDataJpaTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/userService/UserServiceSpringDataJpaTests.java @@ -1,13 +1,10 @@ package org.springframework.samples.petclinic.service.userService; -import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @SpringBootTest -@RunWith(SpringJUnit4ClassRunner.class) @ActiveProfiles({"spring-data-jpa", "hsqldb"}) -public class UserServiceSpringDataJpaTests extends AbstractUserServiceTests { +class UserServiceSpringDataJpaTests extends AbstractUserServiceTests { }