DATAJPA-513 - Improve error message on missing @Param on query method parameter.

StringQuery now hints to the usage of @Param on query method parameters if named parameters are used and parameter names were not declared.

Original pull request: #77.
This commit is contained in:
Oliver Wehrens
2014-04-13 15:20:00 +02:00
committed by Oliver Gierke
parent ff0170967d
commit 7c6f4528ef
2 changed files with 23 additions and 1 deletions

View File

@@ -20,10 +20,13 @@ import static org.junit.Assert.*;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.data.jpa.repository.query.StringQuery.InParameterBinding;
import org.springframework.data.jpa.repository.query.StringQuery.LikeParameterBinding;
import org.springframework.data.jpa.repository.query.StringQuery.ParameterBinding;
import org.springframework.data.repository.query.Param;
import org.springframework.data.repository.query.parser.Part.Type;
/**
@@ -34,6 +37,8 @@ import org.springframework.data.repository.query.parser.Part.Type;
*/
public class StringQueryUnitTests {
public @Rule ExpectedException exception = ExpectedException.none();
/**
* @see DATAJPA-341
*/
@@ -227,6 +232,20 @@ public class StringQueryUnitTests {
assertNamedBinding(InParameterBinding.class, "statuses", bindings.get(0));
}
/**
* @see DATAJPA-513
*/
@Test
public void rejectsNullParameterNameHintingTowardsAtParamForNullParameterName() {
StringQuery query = new StringQuery("select x from X");
exception.expect(IllegalArgumentException.class);
exception.expectMessage(Param.class.getSimpleName());
query.getBindingFor(null);
}
private void assertPositionalBinding(Class<? extends ParameterBinding> bindingType, Integer position,
ParameterBinding expectedBinding) {