-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
393 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 7 additions & 4 deletions
11
up-core/src/test/java/com/github/restup/query/criteria/OperatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
package com.github.restup.query.criteria; | ||
|
||
import org.junit.Assert; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
import org.junit.Test; | ||
import com.github.restup.query.criteria.ResourcePathFilter.Operator; | ||
|
||
public class OperatorTest { | ||
|
||
@Test | ||
public void testOf() { | ||
Assert.assertEquals(ResourcePathFilter.Operator.eq, ResourcePathFilter.Operator.of(null)); | ||
assertEquals(ResourcePathFilter.Operator.eq, ResourcePathFilter.Operator.of(null)); | ||
for (ResourcePathFilter.Operator op : ResourcePathFilter.Operator.values()) { | ||
Assert.assertEquals(op, ResourcePathFilter.Operator.of(op.name())); | ||
assertEquals(op, ResourcePathFilter.Operator.of(op.name())); | ||
for (String s : op.getOperators()) { | ||
Assert.assertEquals(op, ResourcePathFilter.Operator.of(s)); | ||
assertEquals(op, ResourcePathFilter.Operator.of(s)); | ||
} | ||
} | ||
assertNull(Operator.of("bad")); | ||
} | ||
|
||
} |
81 changes: 81 additions & 0 deletions
81
up-core/src/test/java/com/github/restup/query/criteria/ResourceQueryCriteriaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.github.restup.query.criteria; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
import static org.mockito.Mockito.when; | ||
import org.junit.Test; | ||
|
||
public class ResourceQueryCriteriaTest { | ||
|
||
private ResourceQueryCriteria criteria(Object target, boolean result) { | ||
ResourceQueryCriteria criteria = mock(ResourceQueryCriteria.class); | ||
when(criteria.filter(target)).thenReturn(result); | ||
return criteria; | ||
} | ||
|
||
@Test | ||
public void testAndFalse() { | ||
Object foo = ""; | ||
ResourceQueryCriteria positive = criteria(foo, true); | ||
ResourceQueryCriteria negative = criteria(foo, false); | ||
|
||
assertFalse(ResourceQueryCriteria.and(positive, negative).filter(foo)); | ||
|
||
// negative filter applied positive will not be | ||
ResourceQueryCriteria negative2 = criteria(foo, false); | ||
assertFalse(ResourceQueryCriteria.and(negative2, positive).filter(foo)); | ||
|
||
verifyFilter(foo, positive, negative, negative2); | ||
verifyNoMoreInteractions(positive, negative, negative2); | ||
} | ||
|
||
@Test | ||
public void testAndTrue() { | ||
Object foo = ""; | ||
ResourceQueryCriteria a = criteria(foo, true); | ||
ResourceQueryCriteria b = criteria(foo, true); | ||
|
||
assertTrue(ResourceQueryCriteria.and(a, b).filter(foo)); | ||
|
||
verifyFilter(foo, a, b); | ||
verifyNoMoreInteractions(a, b); | ||
} | ||
|
||
@Test | ||
public void testOrFalse() { | ||
Object foo = ""; | ||
ResourceQueryCriteria a = criteria(foo, false); | ||
ResourceQueryCriteria b = criteria(foo, false); | ||
|
||
assertFalse(ResourceQueryCriteria.or(a, b).filter(foo)); | ||
|
||
verifyFilter(foo, a, b); | ||
verifyNoMoreInteractions(a, b); | ||
} | ||
|
||
@Test | ||
public void testOrTrue() { | ||
Object foo = ""; | ||
ResourceQueryCriteria a = criteria(foo, true); | ||
ResourceQueryCriteria b = criteria(foo, true); | ||
|
||
// b verify not executed | ||
assertTrue(ResourceQueryCriteria.or(a, b).filter(foo)); | ||
|
||
ResourceQueryCriteria c = criteria(foo, false); | ||
assertTrue(ResourceQueryCriteria.or(c, b).filter(foo)); | ||
|
||
verifyFilter(foo, a, b, c); | ||
verifyNoMoreInteractions(a, b); | ||
} | ||
|
||
private void verifyFilter(Object target, ResourceQueryCriteria... array) { | ||
for ( ResourceQueryCriteria criteria : array) { | ||
verify(criteria).filter(target); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.