Skip to content

Commit

Permalink
Add keyword less and less equal, #144. (#184)
Browse files Browse the repository at this point in the history
Signed-off-by: Pan Li <panli@microsoft.com>
  • Loading branch information
Incarnation-p-lee committed Aug 23, 2018
1 parent ae4bb9b commit 197366e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ private String generateQueryBody(@NonNull Criteria criteria, @NonNull List<Pair<
case IS_EQUAL:
case BEFORE:
case AFTER:
case LESS_THAN:
case LESS_THAN_EQUAL:
case GREATER_THAN:
case GREATER_THAN_EQUAL:
return this.generateUnaryQuery(criteria, parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public enum CriteriaType {
AND("AND"),
BEFORE("<"),
AFTER(">"),
LESS_THAN("<"),
LESS_THAN_EQUAL("<="),
GREATER_THAN(">"),
GREATER_THAN_EQUAL(">=");

Expand All @@ -40,6 +42,8 @@ public enum CriteriaType {
map.put(Part.Type.AFTER, CriteriaType.AFTER);
map.put(Part.Type.GREATER_THAN, CriteriaType.GREATER_THAN);
map.put(Part.Type.GREATER_THAN_EQUAL, CriteriaType.GREATER_THAN_EQUAL);
map.put(Part.Type.LESS_THAN, CriteriaType.LESS_THAN);
map.put(Part.Type.LESS_THAN_EQUAL, CriteriaType.LESS_THAN_EQUAL);

PART_TREE_TYPE_TO_CRITERIA = Collections.unmodifiableMap(map);
}
Expand Down Expand Up @@ -101,6 +105,8 @@ public static boolean isUnary(CriteriaType type) {
case IS_EQUAL:
case BEFORE:
case AFTER:
case LESS_THAN:
case LESS_THAN_EQUAL:
case GREATER_THAN:
case GREATER_THAN_EQUAL:
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class ProjectRepositoryIT {
private static final String CREATOR_3 = "creator-3";
private static final String FAKE_CREATOR = "fake-creator";

private static final Long STAR_COUNT_MIN = -1L;
private static final Long STAR_COUNT_0 = 0L;
private static final Long STAR_COUNT_1 = 1L;
private static final Long STAR_COUNT_2 = 2L;
Expand Down Expand Up @@ -232,6 +233,51 @@ public void testFindByGreaterThanWithAndOr() {
assertProjectListEquals(projects, Arrays.asList(PROJECT_0, PROJECT_3, PROJECT_4));
}

@Test
public void testFindByLessThan() {
List<Project> projects = repository.findByStarCountLessThan(STAR_COUNT_0);

Assert.assertTrue(projects.isEmpty());

projects = repository.findByStarCountLessThan(STAR_COUNT_2);

assertProjectListEquals(projects, Arrays.asList(PROJECT_0, PROJECT_1, PROJECT_4));
}

@Test
public void testFindByLessThanEqual() {
List<Project> projects = repository.findByForkCountLessThanEqual(STAR_COUNT_MIN);

Assert.assertTrue(projects.isEmpty());

projects = repository.findByForkCountLessThanEqual(STAR_COUNT_2);

assertProjectListEquals(projects, Arrays.asList(PROJECT_0, PROJECT_1, PROJECT_2, PROJECT_4));
}

@Test
public void testFindByLessThanAndGreaterThan() {
List<Project> projects = repository.findByStarCountLessThanAndForkCountGreaterThan(STAR_COUNT_0, FORK_COUNT_3);

Assert.assertTrue(projects.isEmpty());

projects = repository.findByStarCountLessThanAndForkCountGreaterThan(STAR_COUNT_3, FORK_COUNT_0);

assertProjectListEquals(projects, Arrays.asList(PROJECT_1, PROJECT_2));
}

@Test
public void testFindByLessThanEqualsAndGreaterThanEquals() {
List<Project> projects = repository.findByForkCountLessThanEqualAndStarCountGreaterThan(
STAR_COUNT_MIN, FORK_COUNT_0);

Assert.assertTrue(projects.isEmpty());

projects = repository.findByForkCountLessThanEqualAndStarCountGreaterThan(STAR_COUNT_3, FORK_COUNT_0);

assertProjectListEquals(projects, Arrays.asList(PROJECT_1, PROJECT_2, PROJECT_3));
}

@Test
public void testFindByGreaterThanEqual() {
List<Project> projects = repository.findByStarCountGreaterThanEqual(STAR_COUNT_MAX);
Expand All @@ -251,8 +297,6 @@ public void testFindByGreaterThanEqualAnd() {

projects = repository.findByForkCountGreaterThanEqualAndCreator(FORK_COUNT_0, CREATOR_0);

final List<Project> reference = Arrays.asList(PROJECT_0, PROJECT_4);

assertProjectListEquals(projects, Arrays.asList(PROJECT_0, PROJECT_4));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ List<Project> findByNameOrCreatorAndForkCountOrStarCount(String name, String cre

List<Project> findByForkCount(Long forkCount, Sort sort);

List<Project> findByStarCountLessThan(Long starCount);

List<Project> findByForkCountLessThanEqual(Long forkCount);

List<Project> findByStarCountLessThanAndForkCountGreaterThan(Long max, Long min);

List<Project> findByForkCountLessThanEqualAndStarCountGreaterThan(Long max, Long min);

List<Project> findByStarCountGreaterThanEqual(Long count);

List<Project> findByForkCountGreaterThanEqualAndCreator(Long count, String creator);
Expand Down

0 comments on commit 197366e

Please sign in to comment.