Skip to content

Commit

Permalink
Removed use of flaky Mockito spy
Browse files Browse the repository at this point in the history
for checking whether or not close() had been called on an anonymous
class, worked locally, but not on build server. Now instead asserts
closed by issuing a call which contractually fails with a specific
exception if closed.
  • Loading branch information
tinwelint committed Aug 13, 2016
1 parent f7b5a31 commit a7f7a94
Showing 1 changed file with 18 additions and 12 deletions.
Expand Up @@ -19,6 +19,7 @@
*/
package org.neo4j.unsafe.impl.batchimport.input.csv;

import java.io.IOException;
import java.io.StringReader;
import java.util.Iterator;
import java.util.Set;
Expand All @@ -28,8 +29,6 @@
import org.junit.Test;

import org.neo4j.csv.reader.CharReadable;
import org.neo4j.csv.reader.CharSeeker;
import org.neo4j.csv.reader.CharSeekers;
import org.neo4j.csv.reader.Extractor;
import org.neo4j.csv.reader.Extractors;
import org.neo4j.graphdb.ResourceIterator;
Expand Down Expand Up @@ -57,7 +56,6 @@
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

Expand Down Expand Up @@ -125,8 +123,8 @@ public void shouldProvideRelationshipsFromCsvInput() throws Exception
public void shouldCloseDataIteratorsInTheEnd() throws Exception
{
// GIVEN
CharReadable nodeData = spy( charReader( "1" ) );
CharReadable relationshipData = spy( charReader( "1,1" ) );
CharReadable nodeData = charReader( "1" );
CharReadable relationshipData = charReader( "1,1" );
IdType idType = IdType.STRING;
Iterable<DataFactory<InputNode>> nodeDataIterable = dataIterable( given( nodeData ) );
Iterable<DataFactory<InputRelationship>> relationshipDataIterable =
Expand All @@ -150,8 +148,21 @@ relationshipDataIterable, header(
}

// THEN
verify( nodeData, times( 1 ) ).close();
verify( relationshipData, times( 1 ) ).close();
assertClosed( nodeData );
assertClosed( relationshipData );
}

private void assertClosed( CharReadable reader )
{
try
{
reader.read( new char[1], 0, 1 );
fail( reader + " not closed" );
}
catch ( IOException e )
{
assertTrue( e.getMessage().contains( "closed" ) );
}
}

@Test
Expand Down Expand Up @@ -948,11 +959,6 @@ public int bufferSize()
}
};

private static CharSeeker charSeeker( String data )
{
return CharSeekers.charSeeker( charReader( data ), SEEKER_CONFIG, false );
}

private static CharReadable charReader( String data )
{
return wrap( new StringReader( data ) );
Expand Down

0 comments on commit a7f7a94

Please sign in to comment.