diff --git a/account-jsp/src/test/java/com/bobocode/AccountControllerTest.java b/account-jsp/src/test/java/com/bobocode/AccountControllerTest.java index 0623f5f..f5801f4 100644 --- a/account-jsp/src/test/java/com/bobocode/AccountControllerTest.java +++ b/account-jsp/src/test/java/com/bobocode/AccountControllerTest.java @@ -14,32 +14,36 @@ import org.springframework.web.context.WebApplicationContext; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.arrayContaining; +import static org.hamcrest.Matchers.arrayWithSize; +import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.core.IsNull.notNullValue; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; @SpringJUnitWebConfig(classes = {RootConfig.class, WebConfig.class}) -public class AccountControllerTest { +class AccountControllerTest { @Autowired private WebApplicationContext applicationContext; private MockMvc mockMvc; @BeforeEach - public void setup() { + void setup() { mockMvc = MockMvcBuilders.webAppContextSetup(applicationContext).build(); } @Test - public void testAccountControllerAnnotation() { + void testAccountControllerAnnotation() { Controller controller = AccountController.class.getAnnotation(Controller.class); assertThat(controller, notNullValue()); } @Test - public void testAccountControllerRequestMapping() { + void testAccountControllerRequestMapping() { RequestMapping requestMapping = AccountController.class.getAnnotation(RequestMapping.class); assertThat(requestMapping, notNullValue()); @@ -48,30 +52,30 @@ public void testAccountControllerRequestMapping() { } @Test - public void testGetAccountsResponseStatusCode() throws Exception { + void testGetAccountsResponseStatusCode() throws Exception { mockMvc.perform(get("/accounts")).andExpect(status().isOk()); } @Test - public void testGetAccountsViewName() throws Exception { + void testGetAccountsViewName() throws Exception { mockMvc.perform(get("/accounts")) .andExpect(view().name("accounts")); } @Test - public void testGetAccountsModelContainsAccountList() throws Exception { + void testGetAccountsModelContainsAccountList() throws Exception { mockMvc.perform(get("/accounts")) .andExpect(model().attributeExists("accountList")); } @Test - public void testAccountsResponseDefaultListSize() throws Exception { + void testAccountsResponseDefaultListSize() throws Exception { mockMvc.perform(get("/accounts")) .andExpect(model().attribute("accountList", hasSize(10))); } @Test - public void testAccountsResponseListSize() throws Exception { + void testAccountsResponseListSize() throws Exception { mockMvc.perform(get("/accounts").param("size", "20")) .andExpect(model().attribute("accountList", hasSize(20))); } diff --git a/account-jsp/src/test/java/com/bobocode/WebAppConfigTest.java b/account-jsp/src/test/java/com/bobocode/WebAppConfigTest.java index 2154ce8..9a02778 100644 --- a/account-jsp/src/test/java/com/bobocode/WebAppConfigTest.java +++ b/account-jsp/src/test/java/com/bobocode/WebAppConfigTest.java @@ -21,58 +21,62 @@ import java.util.stream.Stream; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.arrayContaining; +import static org.hamcrest.Matchers.arrayWithSize; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.notNullValue; @SpringJUnitConfig(classes = RootConfig.class) -public class WebAppConfigTest { +class WebAppConfigTest { @Autowired private ApplicationContext applicationContext; @Test - public void testDispatcherServletMapping() { + void testDispatcherServletMapping() { WebAppInitializerWrapper webAppInitializerWrapper = new WebAppInitializerWrapper(); assertThat(webAppInitializerWrapper.getServletMappings(), arrayContaining("/")); } @Test - public void testInitializerRootConfigClasses() { + void testInitializerRootConfigClasses() { WebAppInitializerWrapper webAppInitializerWrapper = new WebAppInitializerWrapper(); assertThat(webAppInitializerWrapper.getRootConfigClasses(), arrayContaining(RootConfig.class)); } @Test - public void testInitializerWebConfigClasses() { + void testInitializerWebConfigClasses() { WebAppInitializerWrapper webAppInitializerWrapper = new WebAppInitializerWrapper(); assertThat(webAppInitializerWrapper.getServletConfigClasses(), arrayContaining(WebConfig.class)); } @Test - public void testRootConfigClassIsMarkedAsConfiguration() { + void testRootConfigClassIsMarkedAsConfiguration() { Configuration configuration = RootConfig.class.getAnnotation(Configuration.class); assertThat(configuration, notNullValue()); } @Test - public void testRootConfigClassEnablesComponentScan() { + void testRootConfigClassEnablesComponentScan() { ComponentScan componentScan = RootConfig.class.getAnnotation(ComponentScan.class); assertThat(componentScan, notNullValue()); } @Test - public void testRootConfigComponentScanPackages() { + void testRootConfigComponentScanPackages() { ComponentScan componentScan = RootConfig.class.getAnnotation(ComponentScan.class); assertThat(componentScan.basePackages(), arrayContaining("com.bobocode")); } @Test - public void testRootConfigComponentScanFilters() { + void testRootConfigComponentScanFilters() { ComponentScan componentScan = RootConfig.class.getAnnotation(ComponentScan.class); Filter[] filters = componentScan.excludeFilters(); List filteredClasses = getFilteredClasses(filters); @@ -88,42 +92,42 @@ private List getFilteredClasses(Filter[] filters) { } @Test - public void testWebConfigIsMarkedAsConfiguration() { + void testWebConfigIsMarkedAsConfiguration() { Configuration configuration = WebConfig.class.getAnnotation(Configuration.class); assertThat(configuration, notNullValue()); } @Test - public void testWebConfigEnablesComponentScan() { + void testWebConfigEnablesComponentScan() { ComponentScan componentScan = WebConfig.class.getAnnotation(ComponentScan.class); assertThat(componentScan, notNullValue()); } @Test - public void testWebConfigComponentScanPackages() { + void testWebConfigComponentScanPackages() { ComponentScan componentScan = WebConfig.class.getAnnotation(ComponentScan.class); assertThat(componentScan.value(), arrayContaining("com.bobocode.web")); } @Test - public void testWebConfigEnablesWebMvc() { + void testWebConfigEnablesWebMvc() { EnableWebMvc enableWebMvc = WebConfig.class.getAnnotation(EnableWebMvc.class); assertThat(enableWebMvc, notNullValue()); } @Test - public void testDataGeneratorBeanName() { + void testDataGeneratorBeanName() { TestDataGenerator dataGenerator = applicationContext.getBean("dataGenerator", TestDataGenerator.class); assertThat(dataGenerator, notNullValue()); } @Test - public void testDataGeneratorBeanNameIsNotSpecifiedExplicitly() { + void testDataGeneratorBeanNameIsNotSpecifiedExplicitly() { Method[] methods = RootConfig.class.getMethods(); Method testDataGeneratorBeanMethod = findTestDataGeneratorBeanMethod(methods); Bean bean = testDataGeneratorBeanMethod.getDeclaredAnnotation(Bean.class); diff --git a/account-jsp/src/test/java/com/bobocode/WelcomeControllerTest.java b/account-jsp/src/test/java/com/bobocode/WelcomeControllerTest.java index 50e8e53..3fc23f3 100644 --- a/account-jsp/src/test/java/com/bobocode/WelcomeControllerTest.java +++ b/account-jsp/src/test/java/com/bobocode/WelcomeControllerTest.java @@ -15,31 +15,31 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; @SpringJUnitWebConfig(classes = {RootConfig.class, WebConfig.class}) -public class WelcomeControllerTest { +class WelcomeControllerTest { @Autowired private WebApplicationContext applicationContext; private MockMvc mockMvc; @BeforeEach - public void setup() { + void setup() { mockMvc = MockMvcBuilders.webAppContextSetup(applicationContext).build(); } @Test - public void testWelcomeUrl() throws Exception { + void testWelcomeUrl() throws Exception { mockMvc.perform(get("/welcome")) .andExpect(status().isOk()); } @Test - public void testRootUrl() throws Exception { + void testRootUrl() throws Exception { mockMvc.perform(get("/")) .andExpect(status().isOk()); } @Test - public void testWelcomeViewName() throws Exception { + void testWelcomeViewName() throws Exception { mockMvc.perform(get("/")) .andExpect(view().name("welcome")); } diff --git a/account-rest-api/src/test/java/com/bobocode/AccountRestControllerTest.java b/account-rest-api/src/test/java/com/bobocode/AccountRestControllerTest.java index 7b0a3c6..c2d7a87 100644 --- a/account-rest-api/src/test/java/com/bobocode/AccountRestControllerTest.java +++ b/account-rest-api/src/test/java/com/bobocode/AccountRestControllerTest.java @@ -17,14 +17,19 @@ import org.springframework.web.context.WebApplicationContext; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.arrayContaining; +import static org.hamcrest.Matchers.arrayWithSize; +import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.core.IsNull.notNullValue; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +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.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @SpringJUnitWebConfig(classes = {RootConfig.class, WebConfig.class}) -public class AccountRestControllerTest { +class AccountRestControllerTest { @Autowired private WebApplicationContext applicationContext; @@ -34,20 +39,20 @@ public class AccountRestControllerTest { private MockMvc mockMvc; @BeforeEach - public void setup() { + void setup() { mockMvc = MockMvcBuilders.webAppContextSetup(applicationContext).build(); accountDao.clear(); } @Test - public void testAccountRestControllerAnnotation() { + void testAccountRestControllerAnnotation() { RestController restController = AccountRestController.class.getAnnotation(RestController.class); assertThat(restController, notNullValue()); } @Test - public void testAccountRestControllerRequestMapping() { + void testAccountRestControllerRequestMapping() { RequestMapping requestMapping = AccountRestController.class.getAnnotation(RequestMapping.class); assertThat(requestMapping, notNullValue()); @@ -56,7 +61,7 @@ public void testAccountRestControllerRequestMapping() { } @Test - public void testHttpStatusCodeOnCreate() throws Exception { + void testHttpStatusCodeOnCreate() throws Exception { mockMvc.perform( post("/accounts") .contentType(MediaType.APPLICATION_JSON) @@ -65,7 +70,7 @@ public void testHttpStatusCodeOnCreate() throws Exception { } @Test - public void testCreateAccountReturnsAssignedId() throws Exception { + void testCreateAccountReturnsAssignedId() throws Exception { mockMvc.perform( post("/accounts") .contentType(MediaType.APPLICATION_JSON) @@ -74,13 +79,13 @@ public void testCreateAccountReturnsAssignedId() throws Exception { } @Test - public void testGetAccountsResponseStatusCode() throws Exception { + void testGetAccountsResponseStatusCode() throws Exception { mockMvc.perform(get("/accounts").accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()); } @Test - public void testGetAllAccounts() throws Exception { + void testGetAllAccounts() throws Exception { Account account1 = create("Johnny", "Boy", "jboy@gmail.com"); Account account2 = create("Okko", "Bay", "obay@gmail.com"); accountDao.save(account1); @@ -91,7 +96,7 @@ public void testGetAllAccounts() throws Exception { .andExpect(jsonPath("$.[*].email").value(hasItems("jboy@gmail.com", "obay@gmail.com"))); } - private Account create(String firstName, String lastName, String email){ + private Account create(String firstName, String lastName, String email) { Account account = new Account(); account.setFirstName(firstName); account.setLastName(lastName); @@ -100,7 +105,7 @@ private Account create(String firstName, String lastName, String email){ } @Test - public void testGetById() throws Exception { + void testGetById() throws Exception { Account account = create("Johnny", "Boy", "jboy@gmail.com"); accountDao.save(account); @@ -113,7 +118,7 @@ public void testGetById() throws Exception { } @Test - public void testRemoveAccount() throws Exception { + void testRemoveAccount() throws Exception { Account account = create("Johnny", "Boy", "jboy@gmail.com"); accountDao.save(account); @@ -122,7 +127,7 @@ public void testRemoveAccount() throws Exception { } @Test - public void testUpdateAccount() throws Exception { + void testUpdateAccount() throws Exception { Account account = create("Johnny", "Boy", "jboy@gmail.com"); accountDao.save(account); diff --git a/hello-application-context/src/test/java/com/bobocode/AppConfigTest.java b/hello-application-context/src/test/java/com/bobocode/AppConfigTest.java index 392430c..dd54541 100644 --- a/hello-application-context/src/test/java/com/bobocode/AppConfigTest.java +++ b/hello-application-context/src/test/java/com/bobocode/AppConfigTest.java @@ -21,11 +21,16 @@ import java.util.Map; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.arrayContainingInAnyOrder; +import static org.hamcrest.Matchers.arrayWithSize; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; @SpringJUnitConfig -public class AppConfigTest { +class AppConfigTest { @Configuration @ComponentScan(basePackages = "com.bobocode") static class TestConfig { @@ -41,21 +46,21 @@ static class TestConfig { private AccountDao accountDao; @Test - public void testConfigClassIsMarkedAsConfiguration() { + void testConfigClassIsMarkedAsConfiguration() { Configuration configuration = AppConfig.class.getAnnotation(Configuration.class); assertThat(configuration, notNullValue()); } @Test - public void testComponentScanIsEnabled() { + void testComponentScanIsEnabled() { ComponentScan componentScan = AppConfig.class.getAnnotation(ComponentScan.class); assertThat(componentScan, notNullValue()); } @Test - public void testComponentScanPackagesAreSpecified() { + void testComponentScanPackagesAreSpecified() { ComponentScan componentScan = AppConfig.class.getAnnotation(ComponentScan.class); String[] packages = componentScan.basePackages(); if (packages.length == 0) { @@ -65,14 +70,14 @@ public void testComponentScanPackagesAreSpecified() { } @Test - public void testDataGeneratorHasOnlyOneBean() { + void testDataGeneratorHasOnlyOneBean() { Map testDataGeneratorMap = applicationContext.getBeansOfType(TestDataGenerator.class); assertThat(testDataGeneratorMap.size(), is(1)); } @Test - public void testDataGeneratorBeanIsConfiguredExplicitly() { + void testDataGeneratorBeanIsConfiguredExplicitly() { Method[] methods = AppConfig.class.getMethods(); Method testDataGeneratorBeanMethod = findTestDataGeneratorBeanMethod(methods); @@ -81,14 +86,14 @@ public void testDataGeneratorBeanIsConfiguredExplicitly() { } @Test - public void testDataGeneratorBeanName() { + void testDataGeneratorBeanName() { Map dataGeneratorBeanMap = applicationContext.getBeansOfType(TestDataGenerator.class); assertThat(dataGeneratorBeanMap.keySet(), hasItem("dataGenerator")); } @Test - public void testDataGeneratorBeanNameIsNotSpecifiedExplicitly() { + void testDataGeneratorBeanNameIsNotSpecifiedExplicitly() { Method[] methods = AppConfig.class.getMethods(); Method testDataGeneratorBeanMethod = findTestDataGeneratorBeanMethod(methods); Bean bean = testDataGeneratorBeanMethod.getDeclaredAnnotation(Bean.class); @@ -108,70 +113,70 @@ private Method findTestDataGeneratorBeanMethod(Method[] methods) { } @Test - public void testFakeAccountDaoIsConfiguredAsComponent() { + void testFakeAccountDaoIsConfiguredAsComponent() { Component component = FakeAccountDao.class.getAnnotation(Component.class); assertThat(component, notNullValue()); } @Test - public void testAccountDaoHasOnlyOneBean() { + void testAccountDaoHasOnlyOneBean() { Map accountDaoBeanMap = applicationContext.getBeansOfType(AccountDao.class); assertThat(accountDaoBeanMap.size(), is(1)); } @Test - public void testAccountDaoBeanName() { + void testAccountDaoBeanName() { Map accountDaoBeanMap = applicationContext.getBeansOfType(AccountDao.class); assertThat(accountDaoBeanMap.keySet(), hasItem("accountDao")); } @Test - public void testAccountDaoConstructorIsMarkedWithAutowired() throws NoSuchMethodException { + void testAccountDaoConstructorIsMarkedWithAutowired() throws NoSuchMethodException { Autowired autowired = FakeAccountDao.class.getConstructor(TestDataGenerator.class).getAnnotation(Autowired.class); assertThat(autowired, notNullValue()); } @Test - public void testAccountServiceHasOnlyOneBean() { + void testAccountServiceHasOnlyOneBean() { Map accountServiceMap = applicationContext.getBeansOfType(AccountService.class); assertThat(accountServiceMap.size(), is(1)); } @Test - public void testAccountServiceIsConfiguredAsService() { + void testAccountServiceIsConfiguredAsService() { Service service = AccountService.class.getAnnotation(Service.class); assertThat(service, notNullValue()); } @Test - public void testAccountServiceBeanName() { + void testAccountServiceBeanName() { Map accountServiceMap = applicationContext.getBeansOfType(AccountService.class); assertThat(accountServiceMap.keySet(), hasItem("accountService")); } @Test - public void testAccountServiceBeanNameIsNotSpecifiedExplicitly() { + void testAccountServiceBeanNameIsNotSpecifiedExplicitly() { Service service = AccountService.class.getAnnotation(Service.class); assertThat(service.value(), equalTo("")); } @Test - public void testAccountServiceDoesNotUseAutowired() throws NoSuchMethodException { + void testAccountServiceDoesNotUseAutowired() throws NoSuchMethodException { Annotation[] annotations = AccountService.class.getConstructor(AccountDao.class).getDeclaredAnnotations(); assertThat(annotations, arrayWithSize(0)); } @Test - public void testFindRichestAccount() { + void testFindRichestAccount() { Account richestAccount = accountService.findRichestAccount(); Account actualRichestAccount = accountDao.findAll().stream().max(Comparator.comparing(Account::getBalance)).get(); diff --git a/hello-spring-mvc/src/test/java/com/bobocode/WelcomeWebAppTest.java b/hello-spring-mvc/src/test/java/com/bobocode/WelcomeWebAppTest.java index c9365d0..7bb3176 100644 --- a/hello-spring-mvc/src/test/java/com/bobocode/WelcomeWebAppTest.java +++ b/hello-spring-mvc/src/test/java/com/bobocode/WelcomeWebAppTest.java @@ -17,47 +17,51 @@ import java.util.stream.Stream; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.arrayContaining; +import static org.hamcrest.Matchers.arrayWithSize; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.notNullValue; -public class WelcomeWebAppTest { +class WelcomeWebAppTest { @Test - public void testDispatcherServletMapping() { + void testDispatcherServletMapping() { WebAppInitializerWrapper webAppInitializerWrapper = new WebAppInitializerWrapper(); assertThat(webAppInitializerWrapper.getServletMappings(), arrayContaining("/")); } @Test - public void testInitializerRootConfigClasses() { + void testInitializerRootConfigClasses() { WebAppInitializerWrapper webAppInitializerWrapper = new WebAppInitializerWrapper(); assertThat(webAppInitializerWrapper.getRootConfigClasses(), arrayContaining(RootConfig.class)); } @Test - public void testInitializerWebConfigClasses() { + void testInitializerWebConfigClasses() { WebAppInitializerWrapper webAppInitializerWrapper = new WebAppInitializerWrapper(); assertThat(webAppInitializerWrapper.getServletConfigClasses(), arrayContaining(WebConfig.class)); } @Test - public void testRootConfigClassIsMarkedAsConfiguration() { + void testRootConfigClassIsMarkedAsConfiguration() { Configuration configuration = RootConfig.class.getAnnotation(Configuration.class); assertThat(configuration, notNullValue()); } @Test - public void testRootConfigClassEnablesComponentScan() { + void testRootConfigClassEnablesComponentScan() { ComponentScan componentScan = RootConfig.class.getAnnotation(ComponentScan.class); assertThat(componentScan, notNullValue()); } @Test - public void testRootConfigComponentScanPackages() { + void testRootConfigComponentScanPackages() { ComponentScan componentScan = RootConfig.class.getAnnotation(ComponentScan.class); String[] packages = componentScan.basePackages(); if (packages.length == 0) { @@ -68,7 +72,7 @@ public void testRootConfigComponentScanPackages() { } @Test - public void testRootConfigComponentScanFilters() { + void testRootConfigComponentScanFilters() { ComponentScan componentScan = RootConfig.class.getAnnotation(ComponentScan.class); Filter[] filters = componentScan.excludeFilters(); List filteredClasses = getFilteredClasses(filters); @@ -84,49 +88,49 @@ private List getFilteredClasses(Filter[] filters) { } @Test - public void testWebConfigIsMarkedAsConfiguration() { + void testWebConfigIsMarkedAsConfiguration() { Configuration configuration = WebConfig.class.getAnnotation(Configuration.class); assertThat(configuration, notNullValue()); } @Test - public void testWebConfigEnablesComponentScan() { + void testWebConfigEnablesComponentScan() { ComponentScan componentScan = WebConfig.class.getAnnotation(ComponentScan.class); assertThat(componentScan, notNullValue()); } @Test - public void testWebConfigComponentScanPackages() { + void testWebConfigComponentScanPackages() { ComponentScan componentScan = WebConfig.class.getAnnotation(ComponentScan.class); assertThat(componentScan.basePackages(), arrayContaining("com.bobocode.web")); } @Test - public void testWebConfigEnablesWebMvc() { + void testWebConfigEnablesWebMvc() { EnableWebMvc enableWebMvc = WebConfig.class.getAnnotation(EnableWebMvc.class); assertThat(enableWebMvc, notNullValue()); } @Test - public void testWelcomeControllerIsMarkedAsController() { + void testWelcomeControllerIsMarkedAsController() { Controller controller = WelcomeController.class.getAnnotation(Controller.class); assertThat(controller, notNullValue()); } @Test - public void testWelcomeControllerMethodIsMarkedAsGetMethod() throws NoSuchMethodException { + void testWelcomeControllerMethodIsMarkedAsGetMethod() throws NoSuchMethodException { GetMapping getMapping = WelcomeController.class.getDeclaredMethod("welcome").getAnnotation(GetMapping.class); assertThat(getMapping, notNullValue()); } @Test - public void testWelcomeControllerMethodMapping() throws NoSuchMethodException { + void testWelcomeControllerMethodMapping() throws NoSuchMethodException { GetMapping getMapping = WelcomeController.class.getDeclaredMethod("welcome").getAnnotation(GetMapping.class); assertThat(getMapping.value(), arrayContaining("/welcome")); diff --git a/transactional-user-service/src/test/java/com/bobocode/TransactionalUserServiceTest.java b/transactional-user-service/src/test/java/com/bobocode/TransactionalUserServiceTest.java index 05aca2d..fe5a86d 100644 --- a/transactional-user-service/src/test/java/com/bobocode/TransactionalUserServiceTest.java +++ b/transactional-user-service/src/test/java/com/bobocode/TransactionalUserServiceTest.java @@ -24,17 +24,20 @@ import static java.util.stream.Collectors.toList; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.hasProperty; +import static org.hamcrest.Matchers.is; import static org.hamcrest.core.IsCollectionContaining.hasItem; import static org.hamcrest.core.IsNull.notNullValue; @SpringJUnitConfig(RootConfig.class) @Transactional -public class TransactionalUserServiceTest { +class TransactionalUserServiceTest { @Configuration static class TestConfig { @Bean - public TestDataGenerator dataGenerator() { + TestDataGenerator dataGenerator() { return new TestDataGenerator(); } } @@ -49,70 +52,70 @@ public TestDataGenerator dataGenerator() { private TestDataGenerator dataGenerator; @Test - public void testTxManagerBeanName() { + void testTxManagerBeanName() { PlatformTransactionManager transactionManager = applicationContext.getBean(PlatformTransactionManager.class, "transactionManager"); assertThat(transactionManager, notNullValue()); } @Test - public void testUserDaoBeanName() { + void testUserDaoBeanName() { UserDao userDao = applicationContext.getBean(UserDao.class, "userDao"); assertThat(userDao, notNullValue()); } @Test - public void testEntityManagerFactoryBeanName() { + void testEntityManagerFactoryBeanName() { EntityManagerFactory entityManagerFactory = applicationContext.getBean(EntityManagerFactory.class, "entityManagerFactory"); assertThat(entityManagerFactory, notNullValue()); } @Test - public void testUserServiceIsMarkedAsService() { + void testUserServiceIsMarkedAsService() { Service service = UserService.class.getAnnotation(Service.class); assertThat(service, notNullValue()); } @Test - public void testUserDaoIsMarkedAsRepository() { + void testUserDaoIsMarkedAsRepository() { Repository repository = JpaUserDao.class.getAnnotation(Repository.class); assertThat(repository, notNullValue()); } @Test - public void testUserServiceIsTransactional() { + void testUserServiceIsTransactional() { Transactional transactional = UserService.class.getAnnotation(Transactional.class); assertThat(transactional, notNullValue()); } @Test - public void testUserServiceGetAllIsReadOnly() throws NoSuchMethodException { + void testUserServiceGetAllIsReadOnly() throws NoSuchMethodException { Transactional transactional = UserService.class.getDeclaredMethod("getAll").getAnnotation(Transactional.class); assertThat(transactional.readOnly(), is(true)); } @Test - public void testUserServiceGetAllAdminsIsReadOnly() throws NoSuchMethodException { + void testUserServiceGetAllAdminsIsReadOnly() throws NoSuchMethodException { Transactional transactional = UserService.class.getDeclaredMethod("getAllAdmins").getAnnotation(Transactional.class); assertThat(transactional.readOnly(), is(true)); } @Test - public void testUserDaoIsTransactional() { + void testUserDaoIsTransactional() { Transactional transactional = JpaUserDao.class.getAnnotation(Transactional.class); assertThat(transactional, notNullValue()); } @Test - public void testSaveUser() { + void testSaveUser() { User user = dataGenerator.generateUser(); userService.save(user); @@ -120,7 +123,7 @@ public void testSaveUser() { } @Test - public void testGetAllUsers() { + void testGetAllUsers() { List userList = generateUserList(10); userList.forEach(userService::save); @@ -135,7 +138,7 @@ private List generateUserList(int size) { } @Test - public void testGetAllAdmins() { + void testGetAllAdmins() { List userList = generateUserList(20); userList.forEach(userService::save); @@ -154,7 +157,7 @@ private List findAdmins(List users) { } @Test - public void testAddNewRole() { + void testAddNewRole() { User user = dataGenerator.generateUser(RoleType.USER); userService.save(user);