}
public void testConstruction() throws Exception {
// null File parameter
try {
new EmailResource( null );
fail( "Null file should throw an exception" );
} catch ( IllegalArgumentException success ) {
// ignore
}
// Parent directory doesn't exist
try {
final File tempFile = new File( tempDir, "EmailResourceTest1" );
new EmailService( new File( tempFile, "email_config.xml" ) );
fail( "Exception should be thrown when parent directory of file provided doesn't exist" );
} catch ( IllegalArgumentException success ) {
// ignore
}
// File exists but is a directory
try {
new EmailService( tempDir );
fail( "Exception should be thrown when providing a filename that is a directory" );
} catch ( IllegalArgumentException success ) {
// ignore
}
// Parent exists, but is not a directory
try {
final File tempFile = new File( tempDir, "EmailResourceTest2" );
assertTrue( "Testing scenario could not be setup correctly", tempFile.createNewFile() );
new EmailService( new File( tempFile, "email_config.xml" ) );
fail( "Exception should be thrown when parent directory exists but is a file" );
} catch ( IllegalArgumentException success ) {
// ignore
}
// File doesn't exist (but is ok)
final File tempFile = new File( tempDir, "temp.xml" );
assertFalse( "Testing scenario not setup correctly", tempFile.exists() );
new EmailService( tempFile );
// File exists (but it is ok)
assertTrue( "Testing scenario could not be setup correctly", tempFile.createNewFile() );
new EmailService( tempFile );
// Default parameters
// This should work
new EmailResource();
}