Skip to content

Commit

Permalink
Adds NodeValueClientFilter testing for when IndexQuery denies values
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint committed Sep 11, 2018
1 parent ae33149 commit 653dca3
Showing 1 changed file with 31 additions and 7 deletions.
Expand Up @@ -138,18 +138,30 @@ public void shouldNotAcceptNodeWithoutMatchingProperty()
} }


@Test @Test
public void shouldConsultProvidedFiltersForMixOfValuesAndNoValues() public void shouldConsultProvidedAcceptingFiltersForMixOfValuesAndNoValues()
{ {
shouldConsultProvidedFilters( Function.identity() ); shouldConsultProvidedFilters( Function.identity(), true );
} }


@Test @Test
public void shouldConsultProvidedFiltersForNullValues() public void shouldConsultProvidedAcceptingFiltersForNullValues()
{ {
shouldConsultProvidedFilters( v -> null ); shouldConsultProvidedFilters( v -> null, true );
} }


private void shouldConsultProvidedFilters( Function<Value[],Value[]> filterValues ) @Test
public void shouldConsultProvidedDenyingFiltersForMixOfValuesAndNoValues()
{
shouldConsultProvidedFilters( Function.identity(), false );
}

@Test
public void shouldConsultProvidedDenyingFiltersForNullValues()
{
shouldConsultProvidedFilters( v -> null, false );
}

private void shouldConsultProvidedFilters( Function<Value[],Value[]> filterValues, boolean filterAcceptsValue )
{ {
// given // given
long nodeReference = 123; long nodeReference = 123;
Expand All @@ -167,7 +179,8 @@ private void shouldConsultProvidedFilters( Function<Value[],Value[]> filterValue
propertyKeyIds[i] = propertyKeyId; propertyKeyIds[i] = propertyKeyId;
if ( random.nextBoolean() ) if ( random.nextBoolean() )
{ {
filters[i] = IndexQuery.exact( propertyKeyId, actualValues[i].asObjectCopy() ); Object filterValue = (filterAcceptsValue ? actualValues[i] : anyOtherValueThan( actualValues[i] )).asObjectCopy();
filters[i] = IndexQuery.exact( propertyKeyId, filterValue );
} }
values[i] = random.nextBoolean() ? NO_VALUE : actualValues[i]; values[i] = random.nextBoolean() ? NO_VALUE : actualValues[i];
properties.put( propertyKeyId, actualValues[i] ); properties.put( propertyKeyId, actualValues[i] );
Expand All @@ -180,7 +193,18 @@ private void shouldConsultProvidedFilters( Function<Value[],Value[]> filterValue
boolean accepted = filter.acceptNode( nodeReference, filterValues.apply( values ) ); boolean accepted = filter.acceptNode( nodeReference, filterValues.apply( values ) );


// then // then
assertTrue( accepted ); assertEquals( filterAcceptsValue, accepted );
}

private Value anyOtherValueThan( Value valueToNotReturn )
{
Value candidate;
do
{
candidate = random.nextValue();
}
while ( candidate.eq( valueToNotReturn ) );
return candidate;
} }


private NodeValueClientFilter initializeFilter( IndexQuery... filters ) private NodeValueClientFilter initializeFilter( IndexQuery... filters )
Expand Down

0 comments on commit 653dca3

Please sign in to comment.