diff --git a/redis/repositories/src/test/java/example/springdata/redis/repositories/PersonRepositoryTests.java b/redis/repositories/src/test/java/example/springdata/redis/repositories/PersonRepositoryTests.java index 2e70d7ff..36b22ec0 100644 --- a/redis/repositories/src/test/java/example/springdata/redis/repositories/PersonRepositoryTests.java +++ b/redis/repositories/src/test/java/example/springdata/redis/repositories/PersonRepositoryTests.java @@ -15,15 +15,13 @@ */ package example.springdata.redis.repositories; -import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.*; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.*; import example.springdata.redis.test.util.EmbeddedRedisServer; import example.springdata.redis.test.util.RequiresRedisServer; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; @@ -67,7 +65,7 @@ public class PersonRepositoryTests { .around(RequiresRedisServer.onLocalhost().atLeast("3.2")); /** {@link Charset} for String conversion **/ - private static final Charset CHARSET = Charset.forName("UTF-8"); + private static final Charset CHARSET = StandardCharsets.UTF_8; @Autowired RedisOperations operations; @Autowired PersonRepository repository; @@ -102,9 +100,9 @@ public class PersonRepositoryTests { repository.save(eddard); - assertThat(operations.execute( - (RedisConnection connection) -> connection.exists(new String("persons:" + eddard.getId()).getBytes(CHARSET))), - is(true)); + assertThat(operations + .execute((RedisConnection connection) -> connection.exists(("persons:" + eddard.getId()).getBytes(CHARSET)))) + .isTrue(); } /** @@ -117,8 +115,7 @@ public class PersonRepositoryTests { List starks = repository.findByLastname(eddard.getLastname()); - assertThat(starks, containsInAnyOrder(eddard, robb, sansa, arya, bran, rickon)); - assertThat(starks, not(hasItem(jon))); + assertThat(starks).contains(eddard, robb, sansa, arya, bran, rickon).doesNotContain(jon); } /** @@ -131,8 +128,7 @@ public class PersonRepositoryTests { List aryaStark = repository.findByFirstnameAndLastname(arya.getFirstname(), arya.getLastname()); - assertThat(aryaStark, hasItem(arya)); - assertThat(aryaStark, not(hasItems(eddard, robb, sansa, bran, rickon, jon))); + assertThat(aryaStark).containsOnly(arya); } /** @@ -145,27 +141,26 @@ public class PersonRepositoryTests { List aryaAndJon = repository.findByFirstnameOrLastname(arya.getFirstname(), jon.getLastname()); - assertThat(aryaAndJon, containsInAnyOrder(arya, jon)); - assertThat(aryaAndJon, not(hasItems(eddard, robb, sansa, bran, rickon))); + assertThat(aryaAndJon).containsOnly(arya, jon); } /** * Find entities in range defined by {@link Pageable}. */ @Test - public void findByReturingPage() { + public void findByReturningPage() { flushTestUsers(); - Page page1 = repository.findPersonByLastname(eddard.getLastname(), new PageRequest(0, 5)); + Page page1 = repository.findPersonByLastname(eddard.getLastname(), PageRequest.of(0, 5)); - assertThat(page1.getNumberOfElements(), is(5)); - assertThat(page1.getTotalElements(), is(6L)); + assertThat(page1.getNumberOfElements()).isEqualTo(5); + assertThat(page1.getTotalElements()).isEqualTo(6); - Page page2 = repository.findPersonByLastname(eddard.getLastname(), new PageRequest(1, 5)); + Page page2 = repository.findPersonByLastname(eddard.getLastname(), PageRequest.of(1, 5)); - assertThat(page2.getNumberOfElements(), is(1)); - assertThat(page2.getTotalElements(), is(6L)); + assertThat(page2.getNumberOfElements()).isEqualTo(1); + assertThat(page2.getTotalElements()).isEqualTo(6); } /** @@ -184,8 +179,7 @@ public class PersonRepositoryTests { List eddardStark = repository.findByAddress_City(winterfell.getCity()); - assertThat(eddardStark, hasItem(eddard)); - assertThat(eddardStark, not(hasItems(robb, sansa, arya, bran, rickon, jon))); + assertThat(eddardStark).containsOnly(eddard); } /** @@ -213,18 +207,16 @@ public class PersonRepositoryTests { Circle innerCircle = new Circle(new Point(51.8911912, -0.4979756), new Distance(50, Metrics.KILOMETERS)); List eddardStark = repository.findByAddress_LocationWithin(innerCircle); - assertThat(eddardStark, hasItem(robb)); - assertThat(eddardStark, hasSize(1)); + assertThat(eddardStark).containsOnly(robb); Circle biggerCircle = new Circle(new Point(51.8911912, -0.4979756), new Distance(200, Metrics.KILOMETERS)); List eddardAndRobbStark = repository.findByAddress_LocationWithin(biggerCircle); - assertThat(eddardAndRobbStark, hasItems(robb, eddard)); - assertThat(eddardAndRobbStark, hasSize(2)); + assertThat(eddardAndRobbStark).hasSize(2).contains(robb, eddard); } /** - * Store references to other entites without embedding all data.
+ * Store references to other entities without embedding all data.
* Print out the hash structure within Redis. */ @Test