Skip to content

Commit 9195a0e

Browse files
committed
DATACMNS-1007 - Polishing.
Moved the enum declaration to a more appropriate position. Moved the author addition to the part of the codebase that was actually changed. Expanded copyright year. Moved unit tests to more appropriate position. Added another one to make sure a reference to a boolean property "empty" can still be supported by adding an explicit Is to make sure we detect a simple property reference. Original pull request: #203.
1 parent e864c69 commit 9195a0e

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

Diff for: src/main/java/org/springframework/data/repository/query/parser/Part.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2014 the original author or authors.
2+
* Copyright 2008-2017 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.
@@ -34,7 +34,6 @@
3434
*
3535
* @author Oliver Gierke
3636
* @author Martin Baumgartner
37-
* @author Michael Cramer
3837
*/
3938
public class Part {
4039

@@ -178,19 +177,20 @@ public String toString() {
178177
*
179178
* @author Oliver Gierke
180179
* @author Thomas Darimont
180+
* @author Michael Cramer
181181
*/
182182
public static enum Type {
183183

184184
BETWEEN(2, "IsBetween", "Between"), IS_NOT_NULL(0, "IsNotNull", "NotNull"), IS_NULL(0, "IsNull", "Null"), LESS_THAN(
185185
"IsLessThan", "LessThan"), LESS_THAN_EQUAL("IsLessThanEqual", "LessThanEqual"), GREATER_THAN("IsGreaterThan",
186186
"GreaterThan"), GREATER_THAN_EQUAL("IsGreaterThanEqual", "GreaterThanEqual"), BEFORE("IsBefore", "Before"), AFTER(
187187
"IsAfter", "After"), NOT_LIKE("IsNotLike", "NotLike"), LIKE("IsLike", "Like"), STARTING_WITH("IsStartingWith",
188-
"StartingWith", "StartsWith"), ENDING_WITH("IsEndingWith", "EndingWith", "EndsWith"), NOT_CONTAINING(
189-
"IsNotContaining", "NotContaining", "NotContains"), CONTAINING("IsContaining", "Containing", "Contains"), NOT_IN(
190-
"IsNotIn", "NotIn"), IN("IsIn", "In"), NEAR("IsNear", "Near"), WITHIN("IsWithin", "Within"), REGEX(
191-
"MatchesRegex", "Matches", "Regex"), EXISTS(0, "Exists"), TRUE(0, "IsTrue", "True"), FALSE(0, "IsFalse",
192-
"False"), NEGATING_SIMPLE_PROPERTY("IsNot", "Not"), SIMPLE_PROPERTY("Is", "Equals"), IS_NOT_EMPTY(0, "IsNotEmpty",
193-
"NotEmpty"), IS_EMPTY(0, "IsEmpty", "Empty");
188+
"StartingWith", "StartsWith"), ENDING_WITH("IsEndingWith", "EndingWith", "EndsWith"), IS_NOT_EMPTY(0, "IsNotEmpty",
189+
"NotEmpty"), IS_EMPTY(0, "IsEmpty", "Empty"), NOT_CONTAINING("IsNotContaining", "NotContaining", "NotContains"),
190+
CONTAINING("IsContaining", "Containing", "Contains"), NOT_IN("IsNotIn", "NotIn"), IN("IsIn", "In"), NEAR("IsNear",
191+
"Near"), WITHIN("IsWithin", "Within"), REGEX("MatchesRegex", "Matches", "Regex"), EXISTS(0, "Exists"), TRUE(0,
192+
"IsTrue", "True"), FALSE(0, "IsFalse", "False"), NEGATING_SIMPLE_PROPERTY("IsNot", "Not"), SIMPLE_PROPERTY("Is",
193+
"Equals");
194194

195195
// Need to list them again explicitly as the order is important
196196
// (esp. for IS_NULL, IS_NOT_NULL)

Diff for: src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java

+18-10
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,6 @@ public void returnsAllPartsOfType() {
222222
assertThat(parts, is(hasSize(1)));
223223
}
224224

225-
@Test // DATACMNS-1007
226-
public void parsesEmptyKeywordCorrectly() {
227-
assertType(asList("friendsIsEmpty", "friendsEmpty"), IS_EMPTY, "friends", 0, false);
228-
}
229-
230-
@Test // DATACMNS-1007
231-
public void parsesNotEmptyKeywordCorrectly() {
232-
assertType(asList("friendsIsNotEmpty", "friendsNotEmpty"), IS_NOT_EMPTY, "friends", 0, false);
233-
}
234-
235225
@Test // DATACMNS-94
236226
public void parsesExistsKeywordCorrectly() {
237227
assertType(asList("lastnameExists"), EXISTS, "lastname", 0, false);
@@ -577,6 +567,23 @@ public void doesNotFailOnPropertiesContainingAKeyword() {
577567
assertThat(part.getProperty(), is(PropertyPath.from("someInfo", Category.class)));
578568
}
579569

570+
@Test // DATACMNS-1007
571+
public void parsesEmptyKeywordCorrectly() {
572+
assertType(asList("friendsIsEmpty", "friendsEmpty"), IS_EMPTY, "friends", 0, false);
573+
}
574+
575+
@Test // DATACMNS-1007
576+
public void parsesNotEmptyKeywordCorrectly() {
577+
assertType(asList("friendsIsNotEmpty", "friendsNotEmpty"), IS_NOT_EMPTY, "friends", 0, false);
578+
}
579+
580+
@Test // DATACMNS-1007
581+
public void parsesEmptyAsPropertyIfDifferentKeywordIsUsed() {
582+
583+
assertType(asList("emptyIsTrue"), TRUE, "empty", 0, false);
584+
assertType(asList("emptyIs"), SIMPLE_PROPERTY, "empty", 1, true);
585+
}
586+
580587
private static void assertLimiting(String methodName, Class<?> entityType, boolean limiting, Integer maxResults) {
581588
assertLimiting(methodName, entityType, limiting, maxResults, false);
582589
}
@@ -663,6 +670,7 @@ class User {
663670
boolean active;
664671
Date birthday;
665672
List<User> friends;
673+
boolean empty;
666674
}
667675

668676
class Organization {

0 commit comments

Comments
 (0)