adammurdoch 2002/10/22 04:41:49
Modified: vfs/src/test/org/apache/commons AbstractVfsTestCase.java
vfs/src/java/org/apache/commons/vfs FileSystemException.java
vfs/src/java/org/apache/commons/vfs/impl
DefaultFileReplicator.java
Added: vfs/src/java/org/apache/commons/vfs/util Messages.java
Log:
Moved message formatting out of FileSystemException to new vfs.util.Messages
class, where it can be used by other classes. Updated test cases to use this
class.
Revision Changes Path
1.7 +26 -11
jakarta-commons-sandbox/vfs/src/test/org/apache/commons/AbstractVfsTestCase.java
Index: AbstractVfsTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/AbstractVfsTestCase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AbstractVfsTestCase.java 21 Oct 2002 02:52:40 -0000 1.6
+++ AbstractVfsTestCase.java 22 Oct 2002 11:41:49 -0000 1.7
@@ -11,6 +11,8 @@
import java.io.IOException;
import java.lang.reflect.Method;
import junit.framework.TestCase;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.util.Messages;
/**
* A base class for VFS tests. Provides utility methods for locating
@@ -166,33 +168,46 @@
/**
* Asserts that an exception contains the expected message.
*/
- protected void assertSameMessage( final String message,
+ protected void assertSameMessage( final String code,
final Throwable throwable )
{
- // TODO - implement this
- fail( "Not implemented." );
+ assertSameMessage( code, new Object[ 0 ], throwable );
}
/**
* Asserts that an exception contains the expected message.
*/
- protected void assertSameMessage( final String message,
- final Object[] info,
+ protected void assertSameMessage( final String code,
+ final Object[] params,
final Throwable throwable )
{
- // TODO - implement this
- fail( "Not implemented." );
+ if ( throwable instanceof FileSystemException )
+ {
+ final FileSystemException fse = (FileSystemException)throwable;
+
+ // Compare message code and params
+ assertEquals( code, fse.getCode() );
+ assertEquals( params.length, fse.getInfo().length );
+ for ( int i = 0; i < params.length; i++ )
+ {
+ final Object param = params[ i ];
+ assertEquals( String.valueOf( param ), fse.getInfo()[ i ] );
+ }
+ }
+
+ // Compare formatted message
+ final String message = Messages.getString( code, params );
+ assertEquals( message, throwable.getMessage() );
}
/**
* Asserts that an exception contains the expected message.
*/
- protected void assertSameMessage( final String message,
- final Object info,
+ protected void assertSameMessage( final String code,
+ final Object param,
final Throwable throwable )
{
- // TODO - implement this
- fail( "Not implemented." );
+ assertSameMessage( code, new Object[] { param }, throwable );
}
/**
1.6 +11 -20
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileSystemException.java
Index: FileSystemException.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileSystemException.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FileSystemException.java 21 Oct 2002 02:52:40 -0000 1.5
+++ FileSystemException.java 22 Oct 2002 11:41:49 -0000 1.6
@@ -7,6 +7,8 @@
*/
package org.apache.commons.vfs;
+import org.apache.commons.vfs.util.Messages;
+
/**
* Thrown for file system errors.
*
@@ -22,6 +24,11 @@
private final Throwable throwable;
/**
+ * The message code.
+ */
+ private final String code;
+
+ /**
* array of complementary info (context).
*/
private final String[] info;
@@ -83,7 +90,8 @@
final Object[] info,
final Throwable throwable )
{
- super( code );
+ super( Messages.getString( code, info ) );
+
if ( info == null )
{
this.info = new String[ 0 ];
@@ -96,6 +104,7 @@
this.info[ i ] = String.valueOf( info[ i ] );
}
}
+ this.code = code;
this.throwable = throwable;
}
@@ -127,7 +136,7 @@
*/
public String getCode()
{
- return super.getMessage();
+ return code;
}
/**
@@ -140,22 +149,4 @@
{
return info;
}
-
- /**
- * Returns the message for this exception.
- * @todo Look up message in resources.
- */
- public String getMessage()
- {
- StringBuffer sb = new StringBuffer( getCode() );
- sb.append( '{' );
- for ( int i = 0; i < info.length; i++ )
- {
- sb.append( info[ i ] ).append( ',' );
- }
- sb.append( throwable );
- sb.append( '}' );
- return sb.toString();
- }
-
}
1.1
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/util/Messages.java
Index: Messages.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.commons.vfs.util;
/**
* Formats messages.
*
* @author <a href="mailto:adammurdoch@;apache.org">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/10/22 11:41:49 $
*/
public class Messages
{
private Messages()
{
}
/**
* Formats a message.
*
* @param code The message code.
* @return The formatted message.
*/
public static String getString( final String code )
{
return getString( code, new Object[ 0 ] );
}
/**
* Formats a message.
*
* @param code The message code.
* @param param The message parameter.
* @return The formatted message.
*/
public static String getString( final String code, final Object param )
{
return getString( code, new Object[] { param } );
}
/**
* Formats a message.
*
* @param code The message code.
* @param params The message parameters.
* @return The formatted message.
*/
public static String getString( final String code, final Object[] params )
{
StringBuffer sb = new StringBuffer( code );
sb.append( '{' );
if ( params != null )
{
for ( int i = 0; i < params.length; i++ )
{
sb.append( params[ i ] );
sb.append( ',' );
}
}
sb.append( '}' );
return sb.toString();
}
}
1.8 +3 -3
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/DefaultFileReplicator.java
Index: DefaultFileReplicator.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/DefaultFileReplicator.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DefaultFileReplicator.java 21 Oct 2002 01:40:38 -0000 1.7
+++ DefaultFileReplicator.java 22 Oct 2002 11:41:49 -0000 1.8
@@ -14,6 +14,7 @@
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSelector;
import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.util.Messages;
import org.apache.commons.vfs.provider.AbstractVfsComponent;
import org.apache.commons.vfs.provider.FileReplicator;
@@ -56,9 +57,8 @@
}
catch ( final FileSystemException e )
{
- //TODO - fix this
- //final String message = REZ.getString( "delete-temp.warn",
file.getName() );
- getLogger().warn( "vfs.impl/delete-temp.warn", e );
+ final String message = Messages.getString(
"vfs.impl/delete-temp.warn", file.getName() );
+ getLogger().warn( message, e );
}
}
--
To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>