Skip to content

Commit

Permalink
Fixed tests to check line by line inclusion...
Browse files Browse the repository at this point in the history
... instead of entire output contains usage
  • Loading branch information
phughk committed Jan 30, 2018
1 parent 07a092e commit bd60e3e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Expand Up @@ -21,12 +21,13 @@

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class BackupHelpOutput
{
public static final String BACKUP_OUTPUT = backupOutput();
public static final List<String> BACKUP_OUTPUT_LINES = backupOutput();

private static String backupOutput()
private static List<String> backupOutput()
{
List<String> lines = new ArrayList<>();

Expand All @@ -45,7 +46,7 @@ private static String backupOutput()
lines.add( " NEO4J_CONF Path to directory which contains neo4j.conf." );
lines.add( " NEO4J_DEBUG Set to anything to enable debug output." );
lines.add( " NEO4J_HOME Neo4j home directory." );
lines.add( " HEAP_SIZE Set size of JVM heap during command execution." );
lines.add( " HEAP_SIZE Set JVM maximum heap size during command execution." );
lines.add( " Takes a number and a unit, for example 512m." );
lines.add( "" );
lines.add( "Perform an online backup from a running Neo4j enterprise server. Neo4j's backup" );
Expand Down Expand Up @@ -93,7 +94,8 @@ private static String backupOutput()
lines.add( " *very* expensive in time and memory." );
lines.add( " [default:false]" );
String platformNewLine = System.lineSeparator();
return String.join( platformNewLine, lines );
lines = lines.stream().map( line -> line += platformNewLine ).collect( Collectors.toList() );
return lines;
}
}

Expand Up @@ -58,7 +58,10 @@ public void outputMatchesExpectedForMissingBackupDir() throws UnsupportedEncodin
assertThat( output, containsString( reason ) );

// and
assertThat( output, containsString( BackupHelpOutput.BACKUP_OUTPUT ) );
for ( String line : BackupHelpOutput.BACKUP_OUTPUT_LINES )
{
assertThat( output, containsString( line ) );
}
}

@Test
Expand All @@ -72,7 +75,10 @@ public void missingBackupName() throws UnsupportedEncodingException
assertThat( output, containsString( reason ) );

// and
assertThat( output, containsString( BackupHelpOutput.BACKUP_OUTPUT ) );
for ( String line : BackupHelpOutput.BACKUP_OUTPUT_LINES )
{
assertThat( "Failed for line: " + line, output, containsString( line ) );
}
}

@Test
Expand All @@ -85,7 +91,6 @@ public void incorrectBackupDirectory() throws IOException
// then
String reason = String.format( "command failed: Directory '%s' does not exist.\n", backupDirectoryResolved );
assertThat( output, containsString( reason ) );
assertThat( output, not( containsString( BackupHelpOutput.BACKUP_OUTPUT ) ) );
}

private String runBackup( String... args ) throws UnsupportedEncodingException
Expand All @@ -97,14 +102,15 @@ private String runBackup( boolean debug, String... args ) throws UnsupportedEnco
{
ParameterisedOutsideWorld outsideWorld = // ParameterisedOutsideWorld used for suppressing #close() doing System.exit()
new ParameterisedOutsideWorld( System.console(), System.out, System.err, System.in, new DefaultFileSystemAbstraction() );
AdminTool subject = new AdminTool( commandLocator, cmd -> new ArrayList<>( ), outsideWorld, debug );
AdminTool subject = new AdminTool( commandLocator, cmd -> new ArrayList<>(), outsideWorld, debug );
Path homeDir = HERE;
Path configDir = HERE;
List<String> params = new ArrayList();
params.add( "backup" );
params.addAll( Arrays.asList( args ) );
String[] argArray = params.toArray( new String[params.size()] );
subject.execute( homeDir, configDir, argArray );
return suppressOutput.getErrorVoice().toString() + suppressOutput.getOutputVoice().toString();

return suppressOutput.getErrorVoice().toString() + System.lineSeparator() + suppressOutput.getOutputVoice().toString();
}
}

0 comments on commit bd60e3e

Please sign in to comment.