Skip to content

Commit

Permalink
feat(logical-operators): add Operator ISNULL for filtering on NULL va…
Browse files Browse the repository at this point in the history
…lues
  • Loading branch information
Yves-MENGELLE-OF committed Mar 21, 2024
1 parent 9665201 commit 67e295b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/main/java/fr/ouestfrance/querydsl/FilterOperation.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.ouestfrance.querydsl;

import fr.ouestfrance.querydsl.service.validators.ValidatedBy;
import fr.ouestfrance.querydsl.service.validators.impl.BooleanValidator;
import fr.ouestfrance.querydsl.service.validators.impl.CollectionValidator;
import fr.ouestfrance.querydsl.service.validators.impl.ComparableValidator;
import fr.ouestfrance.querydsl.service.validators.impl.StringValidator;
Expand Down Expand Up @@ -72,4 +73,11 @@ class IN implements FilterOperation {
@ValidatedBy(CollectionValidator.class)
class NOTIN implements FilterOperation {
}

/**
* Is null Operation
*/
@ValidatedBy(BooleanValidator.class)
class ISNULL implements FilterOperation {

Check warning on line 81 in src/main/java/fr/ouestfrance/querydsl/FilterOperation.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/fr/ouestfrance/querydsl/FilterOperation.java#L81

Added line #L81 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fr.ouestfrance.querydsl.service.validators.impl;

import fr.ouestfrance.querydsl.service.validators.FilterFieldValidator;
import lombok.NoArgsConstructor;

/**
* Validator that handle filter on Boolean
*/
@NoArgsConstructor
public class BooleanValidator implements FilterFieldValidator {
@Override
public boolean validate(Class<?> clazz) {
return Boolean.class.isAssignableFrom(clazz);
}

@Override
public String message() {
return "should be applied to Boolean";

Check warning on line 18 in src/main/java/fr/ouestfrance/querydsl/service/validators/impl/BooleanValidator.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/fr/ouestfrance/querydsl/service/validators/impl/BooleanValidator.java#L18

Added line #L18 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package fr.ouestfrance.querydsl.service.validators.impl;

import fr.ouestfrance.querydsl.service.validators.FilterFieldValidator;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class BooleanValidatorTest {

private final FilterFieldValidator validator = new BooleanValidator();
@Test
void shouldValidate(){
assertTrue(validator.validate(Boolean.class));
}

@Test
void shouldUnValidate(){
assertFalse(validator.validate(String.class));
assertFalse(validator.validate(Double.class));
assertFalse(validator.validate(LocalDate.class));
assertFalse(validator.validate(LocalDateTime.class));
assertFalse(validator.validate(Date.class));
assertFalse(validator.validate(UUID.class));
assertFalse(validator.validate(Integer.class));
assertFalse(validator.validate(BigDecimal.class));
assertFalse(validator.validate(Set.class));
assertFalse(validator.validate(ArrayList.class));
assertFalse(validator.validate(LinkedList.class));
assertFalse(validator.validate(HashSet.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class ComprableValidatorTest {
class ComparableValidatorTest {

private final FilterFieldValidator validator = new ComparableValidator();
@Test
Expand Down

0 comments on commit 67e295b

Please sign in to comment.