diff --git a/spring-data-mongodb/src/main/java/org/baeldung/repository/UserRepository.java b/spring-data-mongodb/src/main/java/org/baeldung/repository/UserRepository.java index 229c907b90..72d9a4dba0 100644 --- a/spring-data-mongodb/src/main/java/org/baeldung/repository/UserRepository.java +++ b/spring-data-mongodb/src/main/java/org/baeldung/repository/UserRepository.java @@ -25,6 +25,6 @@ public interface UserRepository extends MongoRepository, QueryDslP List findByAgeBetween(int ageGT, int ageLT); List findByNameStartingWith(String regexp); - + List findByNameEndingWith(String regexp); } diff --git a/spring-data-mongodb/src/test/java/org/baeldung/mongotemplate/DocumentQueryIntegrationTest.java b/spring-data-mongodb/src/test/java/org/baeldung/mongotemplate/DocumentQueryIntegrationTest.java index 8e264720d9..a4b09e1c70 100644 --- a/spring-data-mongodb/src/test/java/org/baeldung/mongotemplate/DocumentQueryIntegrationTest.java +++ b/spring-data-mongodb/src/test/java/org/baeldung/mongotemplate/DocumentQueryIntegrationTest.java @@ -37,7 +37,7 @@ public class DocumentQueryIntegrationTest { public void tearDown() { mongoTemplate.dropCollection(User.class); } - + @Test public void givenUsersExist_whenFindingUsersByName_thenUsersAreFound() { User user = new User(); @@ -103,7 +103,7 @@ public class DocumentQueryIntegrationTest { List users = mongoTemplate.find(query, User.class); assertThat(users.size(), is(2)); } - + @Test public void givenUsersExist_whenFindingUserWithNameEndWithC_thenUsersAreFound() { User user = new User(); diff --git a/spring-data-mongodb/src/test/java/org/baeldung/repository/BaseQueryIntegrationTest.java b/spring-data-mongodb/src/test/java/org/baeldung/repository/BaseQueryIntegrationTest.java index 9e63121472..459716c7ca 100644 --- a/spring-data-mongodb/src/test/java/org/baeldung/repository/BaseQueryIntegrationTest.java +++ b/spring-data-mongodb/src/test/java/org/baeldung/repository/BaseQueryIntegrationTest.java @@ -7,7 +7,6 @@ import org.junit.Before; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.MongoOperations; - public class BaseQueryIntegrationTest { @Autowired diff --git a/spring-data-mongodb/src/test/java/org/baeldung/repository/DSLQueryIntegrationTest.java b/spring-data-mongodb/src/test/java/org/baeldung/repository/DSLQueryIntegrationTest.java index 48e53dfdf1..ca8d46a97a 100644 --- a/spring-data-mongodb/src/test/java/org/baeldung/repository/DSLQueryIntegrationTest.java +++ b/spring-data-mongodb/src/test/java/org/baeldung/repository/DSLQueryIntegrationTest.java @@ -18,7 +18,7 @@ import com.mysema.query.types.Predicate; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = MongoConfig.class) public class DSLQueryIntegrationTest extends BaseQueryIntegrationTest { - + @Test public void givenUsersExist_whenFindingUsersByName_thenUserAreFound() { User user = new User(); @@ -37,7 +37,7 @@ public class DSLQueryIntegrationTest extends BaseQueryIntegrationTest { assertThat(users.size(), is(1)); } - + @Test public void givenUsersExist_whenFindingUsersWithAgeCreaterThanAndLessThan_thenUsersAreFound() { User user = new User(); @@ -62,7 +62,7 @@ public class DSLQueryIntegrationTest extends BaseQueryIntegrationTest { assertThat(users.size(), is(1)); } - + @Test public void givenUsersExist_whenFindingUserWithNameStartWithA_thenUsersAreFound() { User user = new User(); @@ -86,7 +86,7 @@ public class DSLQueryIntegrationTest extends BaseQueryIntegrationTest { List users = (List) userRepository.findAll(predicate); assertThat(users.size(), is(2)); } - + @Test public void givenUsersExist_whenFindingUserWithNameEndWithC_thenUsersAreFound() { User user = new User(); @@ -107,8 +107,7 @@ public class DSLQueryIntegrationTest extends BaseQueryIntegrationTest { QUser qUser = new QUser("user"); Predicate predicate = qUser.name.endsWith("c"); List users = (List) userRepository.findAll(predicate); - + assertThat(users.size(), is(1)); } } - diff --git a/spring-data-mongodb/src/test/java/org/baeldung/repository/JSONQueryIntegrationTest.java b/spring-data-mongodb/src/test/java/org/baeldung/repository/JSONQueryIntegrationTest.java index a899e76659..ed88429792 100644 --- a/spring-data-mongodb/src/test/java/org/baeldung/repository/JSONQueryIntegrationTest.java +++ b/spring-data-mongodb/src/test/java/org/baeldung/repository/JSONQueryIntegrationTest.java @@ -15,8 +15,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = MongoConfig.class) public class JSONQueryIntegrationTest extends BaseQueryIntegrationTest { - - @Test + + @Test public void givenUsersExist_whenFindingUsersByName_thenUsersAreFound() { User user = new User(); user.setName("Eric"); @@ -30,70 +30,69 @@ public class JSONQueryIntegrationTest extends BaseQueryIntegrationTest { List users = userRepository.findUsersByName("Eric"); assertThat(users.size(), is(1)); } - - @Test - public void givenUsersExist_whenFindingUsersWithAgeCreaterThanAndLessThan_thenUsersAreFound() { - User user = new User(); - user.setAge(20); - user.setName("Jon"); - mongoOps.insert(user); - user = new User(); - user.setAge(50); - user.setName("Jon"); - mongoOps.insert(user); + @Test + public void givenUsersExist_whenFindingUsersWithAgeCreaterThanAndLessThan_thenUsersAreFound() { + User user = new User(); + user.setAge(20); + user.setName("Jon"); + mongoOps.insert(user); - user = new User(); - user.setAge(33); - user.setName("Jim"); - mongoOps.insert(user); + user = new User(); + user.setAge(50); + user.setName("Jon"); + mongoOps.insert(user); - List users = userRepository.findUsersByAgeBetween(26, 40); - assertThat(users.size(), is(1)); - } - - @Test - public void givenUsersExist_whenFindingUserWithNameStartWithA_thenUsersAreFound() { - User user = new User(); - user.setName("Eric"); - user.setAge(45); - mongoOps.insert(user); + user = new User(); + user.setAge(33); + user.setName("Jim"); + mongoOps.insert(user); - user = new User(); - user.setName("Antony"); - user.setAge(33); - mongoOps.insert(user); + List users = userRepository.findUsersByAgeBetween(26, 40); + assertThat(users.size(), is(1)); + } - user = new User(); - user.setName("Alice"); - user.setAge(35); - mongoOps.insert(user); + @Test + public void givenUsersExist_whenFindingUserWithNameStartWithA_thenUsersAreFound() { + User user = new User(); + user.setName("Eric"); + user.setAge(45); + mongoOps.insert(user); - List users = userRepository.findUsersByRegexpName("^A"); - - assertThat(users.size(), is(2)); - } - - @Test - public void givenUsersExist_whenFindingUserWithNameEndWithC_thenUsersAreFound() { - User user = new User(); - user.setName("Eric"); - user.setAge(45); - mongoOps.insert(user); + user = new User(); + user.setName("Antony"); + user.setAge(33); + mongoOps.insert(user); - user = new User(); - user.setName("Antony"); - user.setAge(33); - mongoOps.insert(user); + user = new User(); + user.setName("Alice"); + user.setAge(35); + mongoOps.insert(user); - user = new User(); - user.setName("Alice"); - user.setAge(35); - mongoOps.insert(user); + List users = userRepository.findUsersByRegexpName("^A"); - List users = userRepository.findUsersByRegexpName("c$"); - - assertThat(users.size(), is(1)); - } + assertThat(users.size(), is(2)); + } + + @Test + public void givenUsersExist_whenFindingUserWithNameEndWithC_thenUsersAreFound() { + User user = new User(); + user.setName("Eric"); + user.setAge(45); + mongoOps.insert(user); + + user = new User(); + user.setName("Antony"); + user.setAge(33); + mongoOps.insert(user); + + user = new User(); + user.setName("Alice"); + user.setAge(35); + mongoOps.insert(user); + + List users = userRepository.findUsersByRegexpName("c$"); + + assertThat(users.size(), is(1)); + } } -