Skip to content

Commit 2dc2072

Browse files
committed
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.
1 parent a7b70d6 commit 2dc2072

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQueryUnitTests.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2014-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,6 +45,7 @@
4545
import org.springframework.data.repository.core.RepositoryMetadata;
4646

4747
import com.mongodb.BasicDBObjectBuilder;
48+
import com.mongodb.util.JSONParseException;
4849

4950
/**
5051
* Unit tests for {@link PartTreeMongoQuery}.
@@ -135,6 +136,18 @@ public void shouldAddFullTextParamCorrectlyToDerivedQuery() {
135136
assertThat(query, isTextQuery().searchingFor("search").where(new Criteria("firstname").is("text")));
136137
}
137138

139+
/**
140+
* @see DATAMONGO-1180
141+
*/
142+
@Test
143+
public void propagatesRootExceptionForInvalidQuery() {
144+
145+
exception.expect(IllegalStateException.class);
146+
exception.expectCause(is(org.hamcrest.Matchers.<Throwable> instanceOf(JSONParseException.class)));
147+
148+
deriveQueryFromMethod("findByAge", new Object[] { 1 });
149+
}
150+
138151
private org.springframework.data.mongodb.core.query.Query deriveQueryFromMethod(String method, Object[] args) {
139152

140153
Class<?>[] types = new Class<?>[args.length];
@@ -179,5 +192,8 @@ interface Repo extends MongoRepository<Person, Long> {
179192
Person findPersonByFirstnameAndLastname(String firstname, String lastname);
180193

181194
Person findPersonByFirstname(String firstname, TextCriteria fullText);
195+
196+
@Query(fields = "{ 'firstname }")
197+
Person findByAge(Integer age);
182198
}
183199
}

0 commit comments

Comments
 (0)