Skip to content

Commit

Permalink
Make RoleProcedure return a single row of results.
Browse files Browse the repository at this point in the history
  • Loading branch information
apcj committed Aug 2, 2016
1 parent 36e3daa commit 90f72c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
Expand Up @@ -42,27 +42,12 @@ public RoleProcedure( CoreOrEdge role )
@Override
public RawIterator<Object[], ProcedureException> apply( Context ctx, Object[] input ) throws ProcedureException
{
return new RawIterator<Object[], ProcedureException>()
{
@Override
public boolean hasNext() throws ProcedureException
{
return true;
}
return RawIterator.<Object[], ProcedureException>of( new Object[]{name()} );
}

@Override
public Object[] next() throws ProcedureException
{
try
{
return new Object[]{role.name()};
}
catch ( NullPointerException npe )
{
return new Object[]{"UNKNOWN"};
}
}
};
private String name()
{
return role == null ? "UNKNOWN" : role.name();
}

public enum CoreOrEdge
Expand Down
Expand Up @@ -22,10 +22,13 @@
import org.junit.Test;

import org.neo4j.collection.RawIterator;
import org.neo4j.helpers.collection.Iterators;
import org.neo4j.kernel.api.exceptions.ProcedureException;

import static org.junit.Assert.assertEquals;

import static org.neo4j.helpers.collection.Iterators.asList;

public class RoleProcedureTest
{
@Test
Expand All @@ -38,7 +41,7 @@ public void shouldReturnCore() throws Exception
RawIterator<Object[], ProcedureException> result = proc.apply( null, null );

// then
assertEquals( RoleProcedure.CoreOrEdge.CORE.name(), result.next()[0]);
assertEquals( RoleProcedure.CoreOrEdge.CORE.name(), single( result )[0]);
}

@Test
Expand All @@ -51,7 +54,7 @@ public void shouldReturnEdge() throws Exception
RawIterator<Object[], ProcedureException> result = proc.apply( null, null );

// then
assertEquals( RoleProcedure.CoreOrEdge.EDGE.name(), result.next()[0]);
assertEquals( RoleProcedure.CoreOrEdge.EDGE.name(), single( result )[0]);
}

@Test
Expand All @@ -64,6 +67,11 @@ public void shouldReturnUnknown() throws Exception
RawIterator<Object[], ProcedureException> result = proc.apply( null, null );

// then
assertEquals( "UNKNOWN", result.next()[0]);
assertEquals( "UNKNOWN", single( result )[0]);
}

private Object[] single( RawIterator<Object[], ProcedureException> result ) throws ProcedureException
{
return Iterators.single( asList( result ).iterator() );
}
}

0 comments on commit 90f72c8

Please sign in to comment.