From 5cfd8bc3dfc3bd71c1151b85b4d3b9c268ca8ac9 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Sun, 21 Aug 2011 14:46:44 +0200 Subject: [PATCH] DATACMNS-61 - Fixed Parameters lookup in QueryMethod. --- .../data/repository/query/QueryMethod.java | 8 +++++--- .../data/repository/query/QueryMethodUnitTest.java | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryMethod.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryMethod.java index 233d59db4..af8e1fbc9 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryMethod.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryMethod.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2010 the original author or authors. + * Copyright 2008-2011 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. @@ -73,15 +73,17 @@ public class QueryMethod { } this.method = method; - this.parameters = getParameters(); + this.parameters = createParameters(method); this.metadata = metadata; + + Assert.notNull(this.parameters); } /** * Creates a {@link Parameters} instance. * * @param method - * @return + * @return must not return {@literal null}. */ protected Parameters createParameters(Method method) { return new Parameters(method); diff --git a/spring-data-commons-core/src/test/java/org/springframework/data/repository/query/QueryMethodUnitTest.java b/spring-data-commons-core/src/test/java/org/springframework/data/repository/query/QueryMethodUnitTest.java index 5035d62d8..400ef218c 100644 --- a/spring-data-commons-core/src/test/java/org/springframework/data/repository/query/QueryMethodUnitTest.java +++ b/spring-data-commons-core/src/test/java/org/springframework/data/repository/query/QueryMethodUnitTest.java @@ -41,8 +41,16 @@ public class QueryMethodUnitTest { Method method = SampleRepository.class.getMethod("pagingMethodWithInvalidReturnType", Pageable.class); new QueryMethod(method, metadata); } + + @Test + public void setsUpSimpleQueryMethodCorrectly() throws NoSuchMethodException, SecurityException { + Method method = SampleRepository.class.getMethod("findByUsername", String.class); + new QueryMethod(method, metadata); + } interface SampleRepository { String pagingMethodWithInvalidReturnType(Pageable pageable); + + String findByUsername(String username); } }