From 7e50fd827321da2bceef1130a37016ea4cc2333b Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Tue, 10 Mar 2015 12:14:33 +0100 Subject: [PATCH] DATAMONGO-1180 - Polishing. Fixed copyright ranges in license headers. Added unit test to PartTreeMongoQueryUnitTests to verify the root exception being propagated correctly. Original pull request: #280. Related pull request: #259. --- .../repository/query/PartTreeMongoQuery.java | 2 +- .../query/PartTreeMongoQueryUnitTests.java | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQuery.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQuery.java index b97d01922..df5cabbe5 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQuery.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQuery.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQueryUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQueryUnitTests.java index 62c3b113b..493a1e685 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQueryUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQueryUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2015 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. @@ -45,6 +45,7 @@ import org.springframework.data.mongodb.repository.Query; import org.springframework.data.repository.core.RepositoryMetadata; import com.mongodb.BasicDBObjectBuilder; +import com.mongodb.util.JSONParseException; /** * Unit tests for {@link PartTreeMongoQuery}. @@ -135,6 +136,18 @@ public class PartTreeMongoQueryUnitTests { assertThat(query, isTextQuery().searchingFor("search").where(new Criteria("firstname").is("text"))); } + /** + * @see DATAMONGO-1180 + */ + @Test + public void propagatesRootExceptionForInvalidQuery() { + + exception.expect(IllegalStateException.class); + exception.expectCause(is(org.hamcrest.Matchers. instanceOf(JSONParseException.class))); + + deriveQueryFromMethod("findByAge", new Object[] { 1 }); + } + private org.springframework.data.mongodb.core.query.Query deriveQueryFromMethod(String method, Object[] args) { Class[] types = new Class[args.length]; @@ -179,5 +192,8 @@ public class PartTreeMongoQueryUnitTests { Person findPersonByFirstnameAndLastname(String firstname, String lastname); Person findPersonByFirstname(String firstname, TextCriteria fullText); + + @Query(fields = "{ 'firstname }") + Person findByAge(Integer age); } }