From 64c1eeaf0569ce71d7fd144af6af17627192889d Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Fri, 29 Jan 2021 10:10:58 +0100 Subject: [PATCH] Polishing. Add `@author` tags to changed files. Remove Hamcrest usage. Original pull request #602 Related tickest #583 --- .../CustomerRepositoryIntegrationTests.java | 1 + .../jpa/auditing/AuditableUserSample.java | 14 ++-- .../jpa/basics/BasicFactorySetup.java | 1 + .../springdata/jpa/basics/BasicSample.java | 1 + .../jpa/caching/CachingRepositoryTests.java | 1 + .../compositions/ComposedRepositoryTests.java | 1 + .../UserRepositoryCustomizationTests.java | 1 + .../UserRepositoryCustomizationTests.java | 1 + .../CustomerRepositoryIntegrationTest.java | 1 + .../jpa/simple/SimpleUserRepositoryTests.java | 18 ++-- .../InterceptorIntegrationTest.java | 4 + .../jpa/java8/Java8IntegrationTests.java | 1 + .../FetchGraphIntegrationTests.java | 1 + ...ubscriptionRepositoryIntegrationTests.java | 1 + .../UserRepositoryIntegrationTests.java | 15 ++-- jpa/multiple-datasources/pom.xml | 2 +- .../customer/CustomerRepositoryTests.java | 12 +-- .../order/OrderRepositoryTests.java | 11 +-- ...RepositoryInheritanceIntegrationTests.java | 11 +-- .../UserRepositoryIntegrationTests.java | 1 + .../security/SecurityIntegrationTests.java | 30 +++---- .../AbstractShowcaseContextTests.java | 18 +++- .../jpa/showcase/AbstractShowcaseTest.java | 1 + ...ractTransactionalShowcaseContextTests.java | 82 ++++++++++++------- .../AccountRepositoryIntegrationTest.java | 1 + .../CustomerRepositoryIntegrationTest.java | 1 + .../before/AccountServiceIntegrationTest.java | 16 ++-- .../CustomerServiceIntegrationTest.java | 1 + .../PersonRepositoryIntegrationTests.java | 1 + 29 files changed, 150 insertions(+), 100 deletions(-) diff --git a/jpa/eclipselink/src/test/java/example/springdata/jpa/eclipselink/CustomerRepositoryIntegrationTests.java b/jpa/eclipselink/src/test/java/example/springdata/jpa/eclipselink/CustomerRepositoryIntegrationTests.java index ece3dd86..37df322b 100644 --- a/jpa/eclipselink/src/test/java/example/springdata/jpa/eclipselink/CustomerRepositoryIntegrationTests.java +++ b/jpa/eclipselink/src/test/java/example/springdata/jpa/eclipselink/CustomerRepositoryIntegrationTests.java @@ -29,6 +29,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; * Integration test for {@link CustomerRepository}. * * @author Oliver Gierke + * @author Divya Srivastava */ @ExtendWith(SpringExtension.class) @SpringBootTest diff --git a/jpa/example/src/test/java/example/springdata/jpa/auditing/AuditableUserSample.java b/jpa/example/src/test/java/example/springdata/jpa/auditing/AuditableUserSample.java index 269be31d..c3ba59c6 100644 --- a/jpa/example/src/test/java/example/springdata/jpa/auditing/AuditableUserSample.java +++ b/jpa/example/src/test/java/example/springdata/jpa/auditing/AuditableUserSample.java @@ -15,10 +15,6 @@ */ package example.springdata.jpa.auditing; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; - import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -28,9 +24,13 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.transaction.annotation.Transactional; +import static org.assertj.core.api.Assertions.*; + /** * @author Oliver Gierke * @author Thomas Darimont + * @author Divya Srivastava + * @author Jens Schauder */ @ExtendWith(SpringExtension.class) @Transactional @@ -44,7 +44,7 @@ public class AuditableUserSample { @Test public void auditEntityCreation() throws Exception { - assertThat(ReflectionTestUtils.getField(listener, "handler"),is(notNullValue())); + assertThat(ReflectionTestUtils.getField(listener, "handler")).isNotNull(); AuditableUser user = new AuditableUser(); user.setUsername("username"); @@ -54,7 +54,7 @@ public class AuditableUserSample { user = repository.save(user); user = repository.save(user); - assertThat(user.getCreatedBy(), is(user)); - assertThat(user.getLastModifiedBy(), is(user)); + assertThat(user.getCreatedBy()).isEqualTo(user); + assertThat(user.getLastModifiedBy()).isEqualTo(user); } } diff --git a/jpa/example/src/test/java/example/springdata/jpa/basics/BasicFactorySetup.java b/jpa/example/src/test/java/example/springdata/jpa/basics/BasicFactorySetup.java index a5b58715..924944a3 100644 --- a/jpa/example/src/test/java/example/springdata/jpa/basics/BasicFactorySetup.java +++ b/jpa/example/src/test/java/example/springdata/jpa/basics/BasicFactorySetup.java @@ -33,6 +33,7 @@ import org.springframework.data.jpa.repository.support.JpaRepositoryFactory; * Test case showing how to use the basic {@link GenericDaoFactory} * * @author Oliver Gierke + * @author Divya Srivastava */ public class BasicFactorySetup { diff --git a/jpa/example/src/test/java/example/springdata/jpa/basics/BasicSample.java b/jpa/example/src/test/java/example/springdata/jpa/basics/BasicSample.java index cdca11c0..6861e84a 100644 --- a/jpa/example/src/test/java/example/springdata/jpa/basics/BasicSample.java +++ b/jpa/example/src/test/java/example/springdata/jpa/basics/BasicSample.java @@ -38,6 +38,7 @@ import org.springframework.data.repository.CrudRepository; * * @author Oliver Gierke * @author Thomas Darimont + * @author Divya Srivastava */ public class BasicSample { diff --git a/jpa/example/src/test/java/example/springdata/jpa/caching/CachingRepositoryTests.java b/jpa/example/src/test/java/example/springdata/jpa/caching/CachingRepositoryTests.java index 3f8825c5..a7fe3ffc 100644 --- a/jpa/example/src/test/java/example/springdata/jpa/caching/CachingRepositoryTests.java +++ b/jpa/example/src/test/java/example/springdata/jpa/caching/CachingRepositoryTests.java @@ -33,6 +33,7 @@ import org.springframework.transaction.annotation.Transactional; * @author Oliver Gierke * @author Thomas Darimont * @author Andrea Rizzini + * @author Divya Srivastava */ @ExtendWith(SpringExtension.class) @Transactional diff --git a/jpa/example/src/test/java/example/springdata/jpa/compositions/ComposedRepositoryTests.java b/jpa/example/src/test/java/example/springdata/jpa/compositions/ComposedRepositoryTests.java index b3bd86c2..8a4866b1 100644 --- a/jpa/example/src/test/java/example/springdata/jpa/compositions/ComposedRepositoryTests.java +++ b/jpa/example/src/test/java/example/springdata/jpa/compositions/ComposedRepositoryTests.java @@ -30,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional; * Integration test showing the usage of a composite repository via {@link UserRepository}. * * @author Mark Paluch + * @author Divya Srivastava */ @ExtendWith(SpringExtension.class) @Transactional diff --git a/jpa/example/src/test/java/example/springdata/jpa/custom/UserRepositoryCustomizationTests.java b/jpa/example/src/test/java/example/springdata/jpa/custom/UserRepositoryCustomizationTests.java index f474b39c..971bb8db 100644 --- a/jpa/example/src/test/java/example/springdata/jpa/custom/UserRepositoryCustomizationTests.java +++ b/jpa/example/src/test/java/example/springdata/jpa/custom/UserRepositoryCustomizationTests.java @@ -31,6 +31,7 @@ import org.springframework.transaction.annotation.Transactional; * * @author Oliver Gierke * @author Thomas Darimont + * @author Divya Srivastava */ @ExtendWith(SpringExtension.class) @Transactional diff --git a/jpa/example/src/test/java/example/springdata/jpa/customall/UserRepositoryCustomizationTests.java b/jpa/example/src/test/java/example/springdata/jpa/customall/UserRepositoryCustomizationTests.java index 03825807..37406adc 100644 --- a/jpa/example/src/test/java/example/springdata/jpa/customall/UserRepositoryCustomizationTests.java +++ b/jpa/example/src/test/java/example/springdata/jpa/customall/UserRepositoryCustomizationTests.java @@ -28,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional; * Intergration test showing the usage of a custom method implemented for all repositories * * @author Oliver Gierke + * @author Divya Srivastava * @soundtrack Elen - It's you (Elen) */ @ExtendWith(SpringExtension.class) diff --git a/jpa/example/src/test/java/example/springdata/jpa/projections/CustomerRepositoryIntegrationTest.java b/jpa/example/src/test/java/example/springdata/jpa/projections/CustomerRepositoryIntegrationTest.java index 670a31c2..22cd5058 100644 --- a/jpa/example/src/test/java/example/springdata/jpa/projections/CustomerRepositoryIntegrationTest.java +++ b/jpa/example/src/test/java/example/springdata/jpa/projections/CustomerRepositoryIntegrationTest.java @@ -39,6 +39,7 @@ import org.springframework.transaction.annotation.Transactional; * Integration tests for {@link CustomerRepository} to show projection capabilities. * * @author Oliver Gierke + * @author Divya Srivastava */ @ExtendWith(SpringExtension.class) @SpringBootTest diff --git a/jpa/example/src/test/java/example/springdata/jpa/simple/SimpleUserRepositoryTests.java b/jpa/example/src/test/java/example/springdata/jpa/simple/SimpleUserRepositoryTests.java index d22917c2..a35b6fed 100644 --- a/jpa/example/src/test/java/example/springdata/jpa/simple/SimpleUserRepositoryTests.java +++ b/jpa/example/src/test/java/example/springdata/jpa/simple/SimpleUserRepositoryTests.java @@ -16,10 +16,6 @@ package example.springdata.jpa.simple; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.hasItems; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.iterableWithSize; -import static org.hamcrest.MatcherAssert.assertThat; import static org.springframework.data.domain.Sort.Direction.ASC; import static org.springframework.data.domain.Sort.Direction.DESC; @@ -45,6 +41,8 @@ import org.springframework.transaction.annotation.Transactional; * @author Oliver Gierke * @author Thomas Darimont * @author Christoph Strobl + * @author Divya Srivastava + * @author Jens Schauder */ @ExtendWith(SpringExtension.class) @Transactional @@ -155,8 +153,7 @@ public class SimpleUserRepositoryTests { List result = repository.findFirst2ByOrderByLastnameAsc(); - assertThat(result.size(), is(2)); - assertThat(result, hasItems(user0, user1)); + assertThat(result).containsExactly(user0, user1); } @Test @@ -176,13 +173,11 @@ public class SimpleUserRepositoryTests { List resultAsc = repository.findTop2By(Sort.by(ASC, "lastname")); - assertThat(resultAsc.size(), is(2)); - assertThat(resultAsc, hasItems(user0, user1)); + assertThat(resultAsc).containsExactly(user0, user1); List resultDesc = repository.findTop2By(Sort.by(DESC, "lastname")); - assertThat(resultDesc.size(), is(2)); - assertThat(resultDesc, hasItems(user1, user2)); + assertThat(resultDesc).containsExactly(user2, user1); } @Test @@ -204,7 +199,6 @@ public class SimpleUserRepositoryTests { Iterable users = repository.findByFirstnameOrLastname(reference); - assertThat(users, is(iterableWithSize(2))); - assertThat(users, hasItems(first, second)); + assertThat(users).containsExactly(first, second); } } diff --git a/jpa/interceptors/src/test/java/example/springdata/jpa/interceptors/InterceptorIntegrationTest.java b/jpa/interceptors/src/test/java/example/springdata/jpa/interceptors/InterceptorIntegrationTest.java index ff5fe1b5..7d8dd8ed 100644 --- a/jpa/interceptors/src/test/java/example/springdata/jpa/interceptors/InterceptorIntegrationTest.java +++ b/jpa/interceptors/src/test/java/example/springdata/jpa/interceptors/InterceptorIntegrationTest.java @@ -21,6 +21,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit.jupiter.SpringExtension; +/** + * @author Oliver Drotbohm + * @author Divya Srivastava + */ @ExtendWith(SpringExtension.class) @SpringBootTest public class InterceptorIntegrationTest { diff --git a/jpa/java8/src/test/java/example/springdata/jpa/java8/Java8IntegrationTests.java b/jpa/java8/src/test/java/example/springdata/jpa/java8/Java8IntegrationTests.java index 7a5ed564..0b5a3008 100644 --- a/jpa/java8/src/test/java/example/springdata/jpa/java8/Java8IntegrationTests.java +++ b/jpa/java8/src/test/java/example/springdata/jpa/java8/Java8IntegrationTests.java @@ -40,6 +40,7 @@ import org.springframework.transaction.annotation.Transactional; * * @author Oliver Gierke * @author Thomas Darimont + * @author Divya Srivastava */ @ExtendWith(SpringExtension.class) @SpringBootTest diff --git a/jpa/jpa21/src/test/java/example/springdata/jpa/fetchgraph/FetchGraphIntegrationTests.java b/jpa/jpa21/src/test/java/example/springdata/jpa/fetchgraph/FetchGraphIntegrationTests.java index 5bfca1c6..e7c1d410 100644 --- a/jpa/jpa21/src/test/java/example/springdata/jpa/fetchgraph/FetchGraphIntegrationTests.java +++ b/jpa/jpa21/src/test/java/example/springdata/jpa/fetchgraph/FetchGraphIntegrationTests.java @@ -35,6 +35,7 @@ import org.springframework.transaction.annotation.Transactional; * * @author Thomas Darimont * @author Jens Schauder + * @author Divya Srivastava */ @ExtendWith(SpringExtension.class) diff --git a/jpa/jpa21/src/test/java/example/springdata/jpa/resultsetmappings/SubscriptionRepositoryIntegrationTests.java b/jpa/jpa21/src/test/java/example/springdata/jpa/resultsetmappings/SubscriptionRepositoryIntegrationTests.java index 35ccd996..e6a3865c 100644 --- a/jpa/jpa21/src/test/java/example/springdata/jpa/resultsetmappings/SubscriptionRepositoryIntegrationTests.java +++ b/jpa/jpa21/src/test/java/example/springdata/jpa/resultsetmappings/SubscriptionRepositoryIntegrationTests.java @@ -28,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional; /** * @author Thomas Darimont + * @author Divya Srivastava */ @ExtendWith(SpringExtension.class) @DataJpaTest diff --git a/jpa/jpa21/src/test/java/example/springdata/jpa/storedprocedures/UserRepositoryIntegrationTests.java b/jpa/jpa21/src/test/java/example/springdata/jpa/storedprocedures/UserRepositoryIntegrationTests.java index c6262e8f..aea93ff0 100644 --- a/jpa/jpa21/src/test/java/example/springdata/jpa/storedprocedures/UserRepositoryIntegrationTests.java +++ b/jpa/jpa21/src/test/java/example/springdata/jpa/storedprocedures/UserRepositoryIntegrationTests.java @@ -15,9 +15,6 @@ */ package example.springdata.jpa.storedprocedures; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - import javax.persistence.EntityManager; import javax.persistence.ParameterMode; import javax.persistence.StoredProcedureQuery; @@ -29,11 +26,15 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.annotation.Transactional; +import static org.assertj.core.api.Assertions.*; + /** * Integration test showing the usage of JPA 2.1 stored procedures support through Spring Data repositories. * * @author Thomas Darimont * @author Oliver Gierke + * @author Divya Srivastava + * @author Jens Schauder */ @ExtendWith(SpringExtension.class) @SpringBootTest @@ -47,7 +48,7 @@ public class UserRepositoryIntegrationTests { */ @Test public void entityAnnotatedCustomNamedProcedurePlus1IO() { - assertThat(repository.plus1BackedByOtherNamedStoredProcedure(1), is(2)); + assertThat(repository.plus1BackedByOtherNamedStoredProcedure(1)).isEqualTo(2); } /** @@ -55,7 +56,7 @@ public class UserRepositoryIntegrationTests { */ @Test public void invokeDerivedStoredProcedure() { - assertThat(repository.plus1inout(1), is(2)); + assertThat(repository.plus1inout(1)).isEqualTo(2); } // This is what it would look like implemented manually. @@ -72,7 +73,7 @@ public class UserRepositoryIntegrationTests { proc.setParameter(1, 1); proc.execute(); - assertThat(proc.getOutputParameterValue(2), is((Object) 2)); + assertThat(proc.getOutputParameterValue(2)).isEqualTo(2); } @Test @@ -83,6 +84,6 @@ public class UserRepositoryIntegrationTests { proc.setParameter("arg", 1); proc.execute(); - assertThat(proc.getOutputParameterValue("res"), is((Object) 2)); + assertThat(proc.getOutputParameterValue("res")).isEqualTo(2); } } diff --git a/jpa/multiple-datasources/pom.xml b/jpa/multiple-datasources/pom.xml index 2d2a2397..e4a4b157 100644 --- a/jpa/multiple-datasources/pom.xml +++ b/jpa/multiple-datasources/pom.xml @@ -9,6 +9,6 @@ spring-data-jpa-multiple-datasources - Spring Data JPA - Multple datasources + Spring Data JPA - Multiple datasources \ No newline at end of file diff --git a/jpa/multiple-datasources/src/test/java/example/springdata/jpa/multipleds/customer/CustomerRepositoryTests.java b/jpa/multiple-datasources/src/test/java/example/springdata/jpa/multipleds/customer/CustomerRepositoryTests.java index 1eff41b8..de05f641 100644 --- a/jpa/multiple-datasources/src/test/java/example/springdata/jpa/multipleds/customer/CustomerRepositoryTests.java +++ b/jpa/multiple-datasources/src/test/java/example/springdata/jpa/multipleds/customer/CustomerRepositoryTests.java @@ -15,10 +15,6 @@ */ package example.springdata.jpa.multipleds.customer; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; - import java.util.Optional; import javax.persistence.EntityManager; @@ -31,10 +27,14 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.annotation.Transactional; +import static org.assertj.core.api.Assertions.*; + /** * Integration test for {@link CustomerRepository}. * * @author Oliver Gierke + * @author Divya Srivastava + * @author Jens Schauder */ @ExtendWith(SpringExtension.class) @SpringBootTest @@ -49,7 +49,7 @@ public class CustomerRepositoryTests { Optional result = repository.findByLastname("Matthews"); - assertThat(result, is(not(Optional.empty()))); - assertThat(result.get().getFirstname(), is("Dave")); + assertThat(result).isNotEmpty(); + assertThat(result.get().getFirstname()).isEqualTo("Dave"); } } diff --git a/jpa/multiple-datasources/src/test/java/example/springdata/jpa/multipleds/order/OrderRepositoryTests.java b/jpa/multiple-datasources/src/test/java/example/springdata/jpa/multipleds/order/OrderRepositoryTests.java index 3879ca00..aac5ad9f 100644 --- a/jpa/multiple-datasources/src/test/java/example/springdata/jpa/multipleds/order/OrderRepositoryTests.java +++ b/jpa/multiple-datasources/src/test/java/example/springdata/jpa/multipleds/order/OrderRepositoryTests.java @@ -15,8 +15,9 @@ */ package example.springdata.jpa.multipleds.order; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.MatcherAssert.assertThat; +import static org.assertj.core.api.Assertions.*; + +import example.springdata.jpa.multipleds.customer.CustomerRepository; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -25,12 +26,12 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.annotation.Transactional; -import example.springdata.jpa.multipleds.customer.CustomerRepository; - /** * Integration test for {@link CustomerRepository}. * * @author Oliver Gierke + * @author Divya Srivastava + * @author Jens Schauder */ @ExtendWith(SpringExtension.class) @SpringBootTest @@ -44,7 +45,7 @@ public class OrderRepositoryTests { public void persistsAndFindsCustomer() { customers.findAll().forEach(customer -> { - assertThat(orders.findByCustomer(customer.getId()), hasSize(1)); + assertThat(orders.findByCustomer(customer.getId())).hasSize(1); }); } } diff --git a/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryInheritanceIntegrationTests.java b/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryInheritanceIntegrationTests.java index 7a030cd3..9c7651b5 100644 --- a/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryInheritanceIntegrationTests.java +++ b/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryInheritanceIntegrationTests.java @@ -15,9 +15,6 @@ */ package example.springdata.jpa.querybyexample; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -27,12 +24,16 @@ import org.springframework.data.domain.Example; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.annotation.Transactional; +import static org.assertj.core.api.Assertions.*; + /** * Integration test showing the usage of JPA Query-by-Example support through Spring Data repositories and entities * using inheritance. * * @author Mark Paluch * @author Oliver Gierke + * @author Divya Srivastava + * @author Jens Schauder */ @ExtendWith(SpringExtension.class) @Transactional @@ -58,7 +59,7 @@ public class UserRepositoryInheritanceIntegrationTests { */ @Test public void countByExample() { - assertThat(repository.count(Example.of(new User(null, "White", null))), is(3L)); + assertThat(repository.count(Example.of(new User(null, "White", null)))).isEqualTo(3L); } /** @@ -66,6 +67,6 @@ public class UserRepositoryInheritanceIntegrationTests { */ @Test public void countSubtypesByExample() { - assertThat(repository.count(Example.of(new SpecialUser(null, "White", null))), is(2L)); + assertThat(repository.count(Example.of(new SpecialUser(null, "White", null)))).isEqualTo(2L); } } diff --git a/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryIntegrationTests.java b/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryIntegrationTests.java index abeff748..3a131cd5 100644 --- a/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryIntegrationTests.java +++ b/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryIntegrationTests.java @@ -38,6 +38,7 @@ import org.springframework.transaction.annotation.Transactional; * @author Mark Paluch * @author Oliver Gierke * @author Jens Schauder + * @author Divya Srivastava */ @ExtendWith(SpringExtension.class) @Transactional diff --git a/jpa/security/src/test/java/example/springdata/jpa/security/SecurityIntegrationTests.java b/jpa/security/src/test/java/example/springdata/jpa/security/SecurityIntegrationTests.java index 7a3b29ae..0f90a9ac 100644 --- a/jpa/security/src/test/java/example/springdata/jpa/security/SecurityIntegrationTests.java +++ b/jpa/security/src/test/java/example/springdata/jpa/security/SecurityIntegrationTests.java @@ -16,11 +16,7 @@ package example.springdata.jpa.security; import static java.util.Collections.singleton; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; +import static org.assertj.core.api.Assertions.*; import java.util.List; @@ -40,6 +36,8 @@ import org.springframework.transaction.annotation.Transactional; * * @author Oliver Gierke * @author Thomas Darimont + * @author Divya Srivastava + * @author Jens Schauder */ @ExtendWith(SpringExtension.class) @SpringBootTest @@ -78,15 +76,13 @@ public class SecurityIntegrationTests { List businessObjects = secureBusinessObjectRepository.findBusinessObjectsForCurrentUser(); - assertThat(businessObjects, hasSize(1)); - assertThat(businessObjects, contains(object3)); + assertThat(businessObjects).containsExactly(object3); SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(ollie, "x")); businessObjects = secureBusinessObjectRepository.findBusinessObjectsForCurrentUser(); - assertThat(businessObjects, hasSize(2)); - assertThat(businessObjects, contains(object1, object2)); + assertThat(businessObjects).containsExactly(object1, object2); } @Test @@ -96,8 +92,7 @@ public class SecurityIntegrationTests { List businessObjects = secureBusinessObjectRepository.findBusinessObjectsForCurrentUser(); - assertThat(businessObjects, hasSize(3)); - assertThat(businessObjects, contains(object1, object2, object3)); + assertThat(businessObjects).containsExactly(object1, object2, object3); } @Test @@ -107,15 +102,13 @@ public class SecurityIntegrationTests { List businessObjects = secureBusinessObjectRepository.findBusinessObjectsForCurrentUserById(); - assertThat(businessObjects, hasSize(1)); - assertThat(businessObjects, contains(object3)); + assertThat(businessObjects).containsExactly(object3); SecurityContextHolder.getContext().setAuthentication(olliAuth); businessObjects = secureBusinessObjectRepository.findBusinessObjectsForCurrentUserById(); - assertThat(businessObjects, hasSize(2)); - assertThat(businessObjects, contains(object1, object2)); + assertThat(businessObjects).containsExactly(object1, object2); } @Test @@ -125,8 +118,7 @@ public class SecurityIntegrationTests { List businessObjects = secureBusinessObjectRepository.findBusinessObjectsForCurrentUserById(); - assertThat(businessObjects, hasSize(3)); - assertThat(businessObjects, contains(object1, object2, object3)); + assertThat(businessObjects).containsExactly(object1, object2, object3); } @Test @@ -138,8 +130,8 @@ public class SecurityIntegrationTests { for (BusinessObject bo : businessObjectRepository.findAll()) { - assertThat(bo.getLastModifiedDate(), is(notNullValue())); - assertThat(bo.getLastModifiedBy().getFirstname(), is("admin")); + assertThat(bo.getLastModifiedDate()).isNotNull(); + assertThat(bo.getLastModifiedBy().getFirstname()).isEqualTo("admin"); } } } diff --git a/jpa/showcase/src/test/java/example/springdata/jpa/showcase/AbstractShowcaseContextTests.java b/jpa/showcase/src/test/java/example/springdata/jpa/showcase/AbstractShowcaseContextTests.java index fbf81898..72664ab4 100644 --- a/jpa/showcase/src/test/java/example/springdata/jpa/showcase/AbstractShowcaseContextTests.java +++ b/jpa/showcase/src/test/java/example/springdata/jpa/showcase/AbstractShowcaseContextTests.java @@ -1,5 +1,17 @@ -/** - * +/* + * Copyright 2020-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package example.springdata.jpa.showcase; @@ -18,7 +30,7 @@ import org.springframework.test.context.support.DirtiesContextTestExecutionListe import org.springframework.test.context.web.ServletTestExecutionListener; /** - * + * @author Divya Srivastava */ @ExtendWith(SpringExtension.class) @TestExecutionListeners({ ServletTestExecutionListener.class, DirtiesContextBeforeModesTestExecutionListener.class, diff --git a/jpa/showcase/src/test/java/example/springdata/jpa/showcase/AbstractShowcaseTest.java b/jpa/showcase/src/test/java/example/springdata/jpa/showcase/AbstractShowcaseTest.java index 3d9b9055..b8107906 100644 --- a/jpa/showcase/src/test/java/example/springdata/jpa/showcase/AbstractShowcaseTest.java +++ b/jpa/showcase/src/test/java/example/springdata/jpa/showcase/AbstractShowcaseTest.java @@ -24,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional; /** * @author Oliver Gierke + * @author Divya Srivastava */ @SpringBootTest @Transactional diff --git a/jpa/showcase/src/test/java/example/springdata/jpa/showcase/AbstractTransactionalShowcaseContextTests.java b/jpa/showcase/src/test/java/example/springdata/jpa/showcase/AbstractTransactionalShowcaseContextTests.java index 813cfbee..82451d40 100644 --- a/jpa/showcase/src/test/java/example/springdata/jpa/showcase/AbstractTransactionalShowcaseContextTests.java +++ b/jpa/showcase/src/test/java/example/springdata/jpa/showcase/AbstractTransactionalShowcaseContextTests.java @@ -1,5 +1,17 @@ -/** - * +/* + * Copyright 2020-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package example.springdata.jpa.showcase; @@ -24,28 +36,28 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; /** - * + * @author Divya Srivastava */ @TestExecutionListeners(listeners = { ServletTestExecutionListener.class, DirtiesContextBeforeModesTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class, SqlScriptsTestExecutionListener.class, EventPublishingTestExecutionListener.class }, inheritListeners = false) - @Transactional -public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseContextTests{ - +@Transactional +public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseContextTests { + /** * The {@code JdbcTemplate} that this base class manages, available to subclasses. + * * @since 3.2 */ protected final JdbcTemplate jdbcTemplate = new JdbcTemplate(); - @Nullable - private String sqlScriptEncoding; - + @Nullable private String sqlScriptEncoding; /** * Set the {@code DataSource}, typically provided via Dependency Injection. - *

This method also instantiates the {@link #jdbcTemplate} instance variable. + *

+ * This method also instantiates the {@link #jdbcTemplate} instance variable. */ @Autowired public void setDataSource(DataSource dataSource) { @@ -54,6 +66,7 @@ public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseC /** * Specify the encoding for SQL scripts, if different from the platform encoding. + * * @see #executeSqlScript */ public void setSqlScriptEncoding(String sqlScriptEncoding) { @@ -62,6 +75,7 @@ public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseC /** * Convenience method for counting the rows in the given table. + * * @param tableName table name to count rows in * @return the number of rows in the table * @see JdbcTestUtils#countRowsInTable @@ -71,13 +85,13 @@ public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseC } /** - * Convenience method for counting the rows in the given table, using the - * provided {@code WHERE} clause. - *

See the Javadoc for {@link JdbcTestUtils#countRowsInTableWhere} for details. + * Convenience method for counting the rows in the given table, using the provided {@code WHERE} clause. + *

+ * See the Javadoc for {@link JdbcTestUtils#countRowsInTableWhere} for details. + * * @param tableName the name of the table to count rows in * @param whereClause the {@code WHERE} clause to append to the query - * @return the number of rows in the table that match the provided - * {@code WHERE} clause + * @return the number of rows in the table that match the provided {@code WHERE} clause * @since 3.2 * @see JdbcTestUtils#countRowsInTableWhere */ @@ -87,7 +101,9 @@ public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseC /** * Convenience method for deleting all rows from the specified tables. - *

Use with caution outside of a transaction! + *

+ * Use with caution outside of a transaction! + * * @param names the names of the tables from which to delete * @return the total number of rows deleted from all specified tables * @see JdbcTestUtils#deleteFromTables @@ -97,17 +113,18 @@ public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseC } /** - * Convenience method for deleting all rows from the given table, using the - * provided {@code WHERE} clause. - *

Use with caution outside of a transaction! - *

See the Javadoc for {@link JdbcTestUtils#deleteFromTableWhere} for details. + * Convenience method for deleting all rows from the given table, using the provided {@code WHERE} clause. + *

+ * Use with caution outside of a transaction! + *

+ * See the Javadoc for {@link JdbcTestUtils#deleteFromTableWhere} for details. + * * @param tableName the name of the table to delete rows from * @param whereClause the {@code WHERE} clause to append to the query * @param args arguments to bind to the query (leaving it to the {@code * PreparedStatement} to guess the corresponding SQL type); may also contain - * {@link org.springframework.jdbc.core.SqlParameterValue SqlParameterValue} - * objects which indicate not only the argument value but also the SQL type - * and optionally the scale. + * {@link org.springframework.jdbc.core.SqlParameterValue SqlParameterValue} objects which indicate not only + * the argument value but also the SQL type and optionally the scale. * @return the number of rows deleted from the table * @since 4.0 * @see JdbcTestUtils#deleteFromTableWhere @@ -118,7 +135,9 @@ public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseC /** * Convenience method for dropping all of the specified tables. - *

Use with caution outside of a transaction! + *

+ * Use with caution outside of a transaction! + * * @param names the names of the tables to drop * @since 3.2 * @see JdbcTestUtils#dropTables @@ -129,12 +148,15 @@ public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseC /** * Execute the given SQL script. - *

Use with caution outside of a transaction! - *

The script will normally be loaded by classpath. - *

Do not use this method to execute DDL if you expect rollback. + *

+ * Use with caution outside of a transaction! + *

+ * The script will normally be loaded by classpath. + *

+ * Do not use this method to execute DDL if you expect rollback. + * * @param sqlResourcePath the Spring resource path for the SQL script - * @param continueOnError whether or not to continue without throwing an - * exception in the event of an error + * @param continueOnError whether or not to continue without throwing an exception in the event of an error * @throws DataAccessException if there is an error executing a statement * @see ResourceDatabasePopulator * @see #setSqlScriptEncoding @@ -146,5 +168,5 @@ public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseC Resource resource = this.applicationContext.getResource(sqlResourcePath); new ResourceDatabasePopulator(continueOnError, false, this.sqlScriptEncoding, resource).execute(ds); } - + } diff --git a/jpa/showcase/src/test/java/example/springdata/jpa/showcase/after/AccountRepositoryIntegrationTest.java b/jpa/showcase/src/test/java/example/springdata/jpa/showcase/after/AccountRepositoryIntegrationTest.java index f6d1f0b6..a9ef6ca1 100644 --- a/jpa/showcase/src/test/java/example/springdata/jpa/showcase/after/AccountRepositoryIntegrationTest.java +++ b/jpa/showcase/src/test/java/example/springdata/jpa/showcase/after/AccountRepositoryIntegrationTest.java @@ -32,6 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired; * Integration tests for Spring Data JPA {@link AccountRepository}. * * @author Oliver Gierke + * @author Divya Srivastava */ public class AccountRepositoryIntegrationTest extends AbstractShowcaseTest { diff --git a/jpa/showcase/src/test/java/example/springdata/jpa/showcase/after/CustomerRepositoryIntegrationTest.java b/jpa/showcase/src/test/java/example/springdata/jpa/showcase/after/CustomerRepositoryIntegrationTest.java index f97bbc7d..41cfa5dd 100644 --- a/jpa/showcase/src/test/java/example/springdata/jpa/showcase/after/CustomerRepositoryIntegrationTest.java +++ b/jpa/showcase/src/test/java/example/springdata/jpa/showcase/after/CustomerRepositoryIntegrationTest.java @@ -34,6 +34,7 @@ import org.springframework.data.domain.PageRequest; * Integration tests for Spring Data JPA {@link CustomerRepository}. * * @author Oliver Gierke + * @author Divya Srivastava */ public class CustomerRepositoryIntegrationTest extends AbstractShowcaseTest { diff --git a/jpa/showcase/src/test/java/example/springdata/jpa/showcase/before/AccountServiceIntegrationTest.java b/jpa/showcase/src/test/java/example/springdata/jpa/showcase/before/AccountServiceIntegrationTest.java index b3dba7e2..2f9581db 100644 --- a/jpa/showcase/src/test/java/example/springdata/jpa/showcase/before/AccountServiceIntegrationTest.java +++ b/jpa/showcase/src/test/java/example/springdata/jpa/showcase/before/AccountServiceIntegrationTest.java @@ -15,21 +15,27 @@ */ package example.springdata.jpa.showcase.before; -import static org.hamcrest.Matchers.*; - -import example.springdata.jpa.showcase.AbstractShowcaseTest; -import example.springdata.jpa.showcase.core.Account; -import example.springdata.jpa.showcase.core.Customer; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import example.springdata.jpa.showcase.AbstractShowcaseTest; +import example.springdata.jpa.showcase.core.Account; +import example.springdata.jpa.showcase.core.Customer; + /** * Integration test for {@link AccountService}. * * @author Oliver Gierke + * @author Divya Srivastava + * @author Jens Schauder */ public class AccountServiceIntegrationTest extends AbstractShowcaseTest { diff --git a/jpa/showcase/src/test/java/example/springdata/jpa/showcase/before/CustomerServiceIntegrationTest.java b/jpa/showcase/src/test/java/example/springdata/jpa/showcase/before/CustomerServiceIntegrationTest.java index 432bfab2..c1540349 100644 --- a/jpa/showcase/src/test/java/example/springdata/jpa/showcase/before/CustomerServiceIntegrationTest.java +++ b/jpa/showcase/src/test/java/example/springdata/jpa/showcase/before/CustomerServiceIntegrationTest.java @@ -31,6 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired; * Integration test for {@link CustomerService}. * * @author Oliver Gierke + * @author Divya Srivastava */ public class CustomerServiceIntegrationTest extends AbstractShowcaseTest { diff --git a/jpa/vavr/src/test/java/example/PersonRepositoryIntegrationTests.java b/jpa/vavr/src/test/java/example/PersonRepositoryIntegrationTests.java index ca850277..771722f0 100644 --- a/jpa/vavr/src/test/java/example/PersonRepositoryIntegrationTests.java +++ b/jpa/vavr/src/test/java/example/PersonRepositoryIntegrationTests.java @@ -35,6 +35,7 @@ import org.springframework.transaction.annotation.Transactional; * Integration tests for {@link PersonRepository} showing Vavr support at repository query methods. * * @author Oliver Gierke + * @author Divya Srivastava */ @ExtendWith(SpringExtension.class) @Transactional