{
private final String startOfName;
public FileNameBeginsWith(String startOfName)
{
this.startOfName = startOfName;
}
@Override
public boolean matches(Object arg)
{
if (arg != null)
{
File fileArg = (File) arg;
return fileArg.getName().startsWith(startOfName);
}
return false;
}
}
/**
* Check that actualFile has the expected directory and file name prefix, e.g. if the actual file
* is /temp/my_file_123.xml and we call:
*
* assertPathCorrect("my_file_", new File("/tmp"), actualFile)
*
* Then the assertion should hold true.
*
* @param expectedFileNamePrefix
* @param expectedDirectory
* @param actualFile
*/
private void assertPathCorrect(String expectedFileNamePrefix, File expectedDirectory, File actualFile)
{
File expectedPath = new File(expectedDirectory, expectedFileNamePrefix);
if (!actualFile.getAbsolutePath().startsWith(expectedPath.getAbsolutePath()))
{
String failureMsg = "File path " + actualFile.getAbsolutePath() +
" does not start as expected: " + expectedPath.getAbsolutePath();
Assert.fail(failureMsg);
}
}
}