Skip to content

Commit

Permalink
DATACMNS-1007 - Polishing.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
odrotbohm committed Mar 13, 2017
1 parent e864c69 commit 9195a0e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2014 the original author or authors.
* Copyright 2008-2017 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.
Expand Down Expand Up @@ -34,7 +34,6 @@
*
* @author Oliver Gierke
* @author Martin Baumgartner
* @author Michael Cramer
*/
public class Part {

Expand Down Expand Up @@ -178,19 +177,20 @@ public String toString() {
*
* @author Oliver Gierke
* @author Thomas Darimont
* @author Michael Cramer
*/
public static enum Type {

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

// Need to list them again explicitly as the order is important
// (esp. for IS_NULL, IS_NOT_NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,6 @@ public void returnsAllPartsOfType() {
assertThat(parts, is(hasSize(1)));
}

@Test // DATACMNS-1007
public void parsesEmptyKeywordCorrectly() {
assertType(asList("friendsIsEmpty", "friendsEmpty"), IS_EMPTY, "friends", 0, false);
}

@Test // DATACMNS-1007
public void parsesNotEmptyKeywordCorrectly() {
assertType(asList("friendsIsNotEmpty", "friendsNotEmpty"), IS_NOT_EMPTY, "friends", 0, false);
}

@Test // DATACMNS-94
public void parsesExistsKeywordCorrectly() {
assertType(asList("lastnameExists"), EXISTS, "lastname", 0, false);
Expand Down Expand Up @@ -577,6 +567,23 @@ public void doesNotFailOnPropertiesContainingAKeyword() {
assertThat(part.getProperty(), is(PropertyPath.from("someInfo", Category.class)));
}

@Test // DATACMNS-1007
public void parsesEmptyKeywordCorrectly() {
assertType(asList("friendsIsEmpty", "friendsEmpty"), IS_EMPTY, "friends", 0, false);
}

@Test // DATACMNS-1007
public void parsesNotEmptyKeywordCorrectly() {
assertType(asList("friendsIsNotEmpty", "friendsNotEmpty"), IS_NOT_EMPTY, "friends", 0, false);
}

@Test // DATACMNS-1007
public void parsesEmptyAsPropertyIfDifferentKeywordIsUsed() {

assertType(asList("emptyIsTrue"), TRUE, "empty", 0, false);
assertType(asList("emptyIs"), SIMPLE_PROPERTY, "empty", 1, true);
}

private static void assertLimiting(String methodName, Class<?> entityType, boolean limiting, Integer maxResults) {
assertLimiting(methodName, entityType, limiting, maxResults, false);
}
Expand Down Expand Up @@ -663,6 +670,7 @@ class User {
boolean active;
Date birthday;
List<User> friends;
boolean empty;
}

class Organization {
Expand Down

0 comments on commit 9195a0e

Please sign in to comment.