Permalink
Browse files

Refactored code after feedback

  • Loading branch information...
1 parent 868afd8 commit 8f578acaddaabaeed537f784038f2a5cb08fa029 @systay committed Aug 28, 2012
@@ -124,8 +124,8 @@ private long logStoreFiles( StringLogger.LineLogger logger, String prefix, File
String fileModificationDate = getFileModificationDate( file );
String bytes = Format.bytes( size );
- String format = String.format( "%s%s: %s - %s", prefix, filename, fileModificationDate, bytes );
- logger.logLine( format );
+ String fileInformation = String.format( "%s%s: %s - %s", prefix, filename, fileModificationDate, bytes );
+ logger.logLine( fileInformation );
total += size;
}
@@ -291,36 +291,28 @@ public boolean accept( File path )
@Override
void dump( LineLogger logger )
{
- logger.logLine( getIPAddresses() );
- }
-
- private String getIPAddresses()
- {
- StringBuilder mess = new StringBuilder();
try
{
Enumeration<NetworkInterface> networkInterfaces = getNetworkInterfaces();
while ( networkInterfaces.hasMoreElements() )
{
NetworkInterface iface = networkInterfaces.nextElement();
- mess.append( String.format( "Interface %s:\n", iface.getDisplayName() ) );
+ logger.logLine( String.format( "Interface %s:", iface.getDisplayName() ) );
Enumeration<InetAddress> addresses = iface.getInetAddresses();
while ( addresses.hasMoreElements() )
{
InetAddress address = addresses.nextElement();
String hostAddress = address.getHostAddress();
- mess.append( String.format( " address: %s\n", hostAddress ) );
+ logger.logLine( String.format( " address: %s", hostAddress ) );
}
}
- return mess.toString();
} catch ( SocketException e )
{
- return "ERROR: failed to inspect network interfaces and addresses: " + e.getMessage();
+ logger.logLine( "ERROR: failed to inspect network interfaces and addresses: " + e.getMessage() );
}
}
-
},
;
@@ -18,40 +18,51 @@ public void shouldSeeHelloWorld()
{
FakeDatabase db = new FakeDatabase();
FakeLogger logger = db.getLogger();
- assertThat( logger.messages, containsString( "Network information" ) );
- assertThat( logger.messages, containsString( "Disk space on partition" ) );
- assertThat( logger.messages, containsString( "Local timezone" ) );
+ String messages = logger.getMessages();
+ assertThat( messages, containsString( "Network information" ) );
+ assertThat( messages, containsString( "Disk space on partition" ) );
+ assertThat( messages, containsString( "Local timezone" ) );
db.shutdown();
}
private class FakeLogger extends StringLogger implements Logging
{
- public String messages = "";
+ private StringBuilder messages = new StringBuilder();
+
+ public String getMessages()
+ {
+ return messages.toString();
+ }
+
+ private void appendLine( String mess )
+ {
+ messages.append( mess ).append( "\n" );
+ }
@Override
public void logLongMessage( String msg, Visitor<LineLogger> source, boolean flush )
{
- messages = messages + msg + "\n";
+ appendLine( msg );
source.visit( new LineLogger()
{
@Override
public void logLine( String line )
{
- messages = messages + line + "\n";
+ appendLine( line );
}
} );
}
@Override
public void logMessage( String msg, boolean flush )
{
- messages = messages + msg + "\n";
+ appendLine( msg );
}
@Override
public void logMessage( String msg, Throwable cause, boolean flush )
{
- messages = messages + msg + "\n";
+ appendLine( msg );
}
@Override
@@ -72,7 +83,7 @@ public void close()
@Override
protected void logLine( String line )
{
- messages = messages + line;
+ appendLine( line );
}
@Override

0 comments on commit 8f578ac

Please sign in to comment.