|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjunit.framework.Assert
junit.framework.TestCase
com.mucommander.file.AbstractFileTestCase
public abstract class AbstractFileTestCase
A generic JUnit test case for the AbstractFile class. This class is abstract and must be extended by
file implementations test classes. The tests performed by this class are generic and should validate on any proper
file implementation, but they may not test the implementation's specifics. It is recommended the test case
implementation provides additional test methods to complete those tests.
This test case is a WORK-IN-PROGRESS and by no means complete.
| Field Summary | |
|---|---|
protected java.util.Vector |
filesToDelete
AbstractFile instances to be deleted if they exist when tearDown() is called. |
protected java.util.Random |
random
Random instance initialized with a static seed so that the values it generates are reproducible. |
protected AbstractFile |
tempFile
A temporary file instance automatically instanciated by setUp() when a test is started. |
| Constructor Summary | |
|---|---|
AbstractFileTestCase()
|
|
| Method Summary | |
|---|---|
protected void |
assertContentsEquals(AbstractFile file1,
AbstractFile file2)
Asserts that both files contain the same data, by calculating their checksum and comparing them. |
protected void |
assertEquals(java.io.InputStream in1,
java.io.InputStream in2)
Asserts that both InputStream contain the same data, by calculating their checksum and comparing
them. |
protected boolean |
byteArraysEqual(byte[] b1,
byte[] b2)
Returns true if both byte arrays are equal. |
protected java.lang.String |
calculateMd5(AbstractFile file)
Calculates and returns the md5 checksum of the given AbstractFile's contents. |
protected java.lang.String |
calculateMd5(java.io.InputStream in)
Calculates and returns the md5 checksum of the given InputStream's contents. |
protected java.lang.String |
createFile(AbstractFile file,
long length)
Creates a regular file and fills it with length random bytes. |
protected void |
deleteWhenFinished(AbstractFile fileToDelete)
Adds the specified file to the list of files to be deleted by tearDown() when the test is finished. |
ChecksumOutputStream |
getMd5OutputStream(java.io.OutputStream out)
Creates and returns a ChecksumOutputStream that generates an md5 checksum as data
is written to it. |
protected java.lang.String |
getPseudoUniqueFilename(java.lang.String prefix)
Generates and returns a pseudo unique filename, prepended by the given prefix. |
abstract AbstractFile |
getTemporaryFile()
Returns a temporary file that can be used for testing purposes. |
protected void |
setUp()
Initializes test variables before each test execution. |
protected void |
sleep(long timeMs)
Sleeps for the given number of milliseconds. |
protected void |
tearDown()
Cleans up test files after each test execution so as to leave the filesystem in the same state as it was before the test. |
void |
testAbsolutePath()
Tests AbstractFile.getAbsolutePath() by asserting that it returns a non-null value, that the file can
be resolved again using this path, and that the resolved file is the same as the orginal file. |
void |
testCanonicalPath()
Tests AbstractFile.getCanonicalPath() by asserting that it returns a non-null value, that the file can
be resolved again using this path, and that the resolved file is the same as the orginal file. |
void |
testCopyTo()
Tests AbstractFile.getCopyToHint(AbstractFile) and AbstractFile.copyTo(AbstractFile). |
void |
testDate()
Tests AbstractFile.getDate(), AbstractFile.canChangeDate() and AbstractFile.changeDate(long),
no matter if dates can be changed or not. |
void |
testDelete()
Tests the AbstractFile.delete() method in various situations. |
void |
testDigest()
Tests AbstractFile.calculateChecksum(java.security.MessageDigest) and ByteUtils.toHexString(byte[])
by computing file digests using different algorithms (MD5, SHA-1, ...) and comparing them against known values. |
void |
testExists()
Tests AbstractFile.exists() in various situations. |
void |
testFileURL()
Tests AbstractFile.getURL() by asserting that it returns a non-null value, that the file can
be resolved again using its string representation (with credentials), and that the resolved file is the same as
the orginal file. |
void |
testFreeSpace()
Tests AbstractFile.getFreeSpace() by asserting that the returned value is either -1
(not available), or a positive (potentially null) value. |
void |
testIcon()
Tests AbstractFile.getIcon() and AbstractFile.getIcon(java.awt.Dimension). |
void |
testInputStream()
Tests AbstractFile.getInputStream(). |
void |
testIsDirectory()
Tests the AbstractFile.isDirectory() method in various situations. |
void |
testJavaNetURL()
Tests the java.net.URL returned by AbstractFile.getJavaNetURL()
and its associated java.net.URLConnection. |
void |
testLs()
Tests AbstractFile.ls(). |
void |
testMkdir()
Tests the AbstractFile.mkdir() method in various situations. |
void |
testMkdirs()
Tests the AbstractFile.mkdirs() method in various situations. |
void |
testMkfile()
Tests the AbstractFile.mkfile() method in various situations. |
void |
testMoveTo()
Tests AbstractFile.getMoveToHint(AbstractFile) and AbstractFile.moveTo(AbstractFile). |
void |
testOutputStream()
Tests AbstractFile.getOutputStream(boolean). |
void |
testParent()
Tests AbstractFile.getParent() and AbstractFile.isParentOf(AbstractFile) methods. |
protected void |
testPathResolution(AbstractFile file,
java.lang.String path)
Verifies the given path is not null, that it can be resolved by FileFactory.getFile(String) into
a file, and that this file is equal to the given one. |
void |
testPermissions()
Tests AbstractFile permission methods. |
void |
testRandomAccessInputStream()
Tests AbstractFile.hasRandomAccessInputStream() and AbstractFile.getRandomAccessInputStream(). |
void |
testRandomAccessOutputStream()
Tests AbstractFile.hasRandomAccessOutputStream() and AbstractFile.getRandomAccessOutputStream(). |
void |
testRoot()
Tests AbstractFile.getRoot() and AbstractFile.isRoot() methods. |
void |
testSeparator()
Tests AbstractFile.getSeparator() by simply asserting that the return value is not null. |
void |
testTotalSpace()
Tests AbstractFile.getTotalSpace() by asserting that the returned value is either -1
(not available), or a positive (potentially null) value. |
void |
testUnicodeFilenames()
Verifies that the file implementation handles unicode/non-ascii filenames properly. |
protected java.lang.String |
writeRandomData(AbstractFile file,
long length,
int maxChunkSize,
boolean append)
Fills the given file with a total of length bytes of random data. |
protected void |
writeRandomData(java.io.OutputStream out,
long length,
int maxChunkSize)
Fills the given OutputStream with a total of length bytes of random data. |
| Methods inherited from class junit.framework.TestCase |
|---|
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString |
| Methods inherited from class junit.framework.Assert |
|---|
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected java.util.Vector filesToDelete
tearDown() is called.
protected AbstractFile tempFile
setUp() when a test is started. The file
is not physically created.
protected java.util.Random random
| Constructor Detail |
|---|
public AbstractFileTestCase()
| Method Detail |
|---|
protected void setUp()
throws java.io.IOException
In particular, the tempFile file is created and ready for use by test methods.
Note that this AbstractFile instance is created, but the file is not physically created.
setUp in class junit.framework.TestCasejava.io.IOException - if an error occurred while creating test variables
protected void tearDown()
throws java.io.IOException
deleteWhenFinished(AbstractFile) are
deleted if they exist.
tearDown in class junit.framework.TestCasejava.io.IOException - if an error occurred while delete files registered with deleteWhenFinished(AbstractFile)protected void deleteWhenFinished(AbstractFile fileToDelete)
tearDown() when the test is finished.
This file will be deleted only if it exists, and any children file it contains will also be deleted.
fileToDelete - a file to be deleted when the test is finished
protected java.lang.String writeRandomData(AbstractFile file,
long length,
int maxChunkSize,
boolean append)
throws java.io.IOException,
java.security.NoSuchAlgorithmException
length bytes of random data. The data is generated and written
chunk by chunk, where each chunk has a random length comprised between 1 and maxChunkSize bytes.
This method returns the md5 checksum of the data written to the file, allowing to later on test the integrity
of the file. Before returning, this method asserts that the file exists (as reported by
AbstractFile.exists()) and that its size (as returned by AbstractFile.getSize()) matches the
specified length argument.
The OutputStream used for writing data is retrieved from AbstractFile.getOutputStream(boolean),
passing the specified append argument. This method uses
writeRandomData(java.io.OutputStream, long, int) to write the file, see this method's documentation for
more information about how the random data is generated and written.
file - the file to write the data tolength - the number of random bytes to fill the file withmaxChunkSize - maximum size of a data chunk written to the file. Size of chunks is comprised between 1 and
this value (inclusive).append - if true, data written to the OutputStream will be appended to the end of this file. If false,
any existing data this file contains will be discarded and overwritten.
java.io.IOException - if an error occurred while retrieving the file's OutputStream or writing to it
java.security.NoSuchAlgorithmException - should not happen
protected void writeRandomData(java.io.OutputStream out,
long length,
int maxChunkSize)
throws java.io.IOException,
java.security.NoSuchAlgorithmException
OutputStream with a total of length bytes of random data.
The data is generated and written chunk by chunk, where each chunk has a random length comprised between 1 and
maxChunkSize bytes.
The random data is generated with a java.util.Random instance initialized with a static seed, so
the data generated by this method will remain the same if the series of prior calls to the random instance
haven't changed. This makes it possible to reproduce and fix a failed test case.
out - the OutputStream to use for writing the datalength - the number of random bytes to fill the file withmaxChunkSize - maximum size of a data chunk written to the file. Size of chunks is comprised between 1 and
this value (inclusive).
java.io.IOException - if an error occurred while writing to the OutputStream
java.security.NoSuchAlgorithmException - should not happen
protected java.lang.String createFile(AbstractFile file,
long length)
throws java.io.IOException,
java.security.NoSuchAlgorithmException
length random bytes. The file will be overwritten if it
already exists. Before returning, this method asserts that the file exists and that its size by
AbstractFile.getSize() matches the specified length argument.
file - the file to create or overwritelength - the number of random bytes to fill the file with
java.io.IOException - if the file already exists or if an error occurred while writing to it
java.security.NoSuchAlgorithmException - should not happenprotected void sleep(long timeMs)
timeMs - number of milliseconds to sleepprotected java.lang.String getPseudoUniqueFilename(java.lang.String prefix)
prefix - the string to prepend to the filename, can be null.
protected boolean byteArraysEqual(byte[] b1,
byte[] b2)
true if both byte arrays are equal.
b1 - the first byte array to testb2 - the second byte array to test
public ChecksumOutputStream getMd5OutputStream(java.io.OutputStream out)
throws java.security.NoSuchAlgorithmException
ChecksumOutputStream that generates an md5 checksum as data
is written to it.
out - the underlying OutputStream used by the DigestOutputStream
java.security.NoSuchAlgorithmException - should not happen
protected java.lang.String calculateMd5(java.io.InputStream in)
throws java.io.IOException,
java.security.NoSuchAlgorithmException
InputStream's contents.
The provided stream is read completely (until EOF) but is not closed.
in - the InputStream to digest
java.io.IOException - should not happen
java.security.NoSuchAlgorithmException - should not happen
protected java.lang.String calculateMd5(AbstractFile file)
throws java.io.IOException,
java.security.NoSuchAlgorithmException
AbstractFile's contents.
file - the file to digest
java.io.IOException - should not happen
java.security.NoSuchAlgorithmException - should not happen
protected void assertEquals(java.io.InputStream in1,
java.io.InputStream in2)
throws java.io.IOException,
java.security.NoSuchAlgorithmException
InputStream contain the same data, by calculating their checksum and comparing
them. Both streams are read completely (until EOF) but are not closed.
in1 - the first InputStream to comparein2 - the second InputStream to compare
java.io.IOException - should not happen
java.security.NoSuchAlgorithmException - should not happen
protected void assertContentsEquals(AbstractFile file1,
AbstractFile file2)
throws java.io.IOException,
java.security.NoSuchAlgorithmException
file1 - the first file to comparefile2 - the second file to compare
java.io.IOException - should not happen
java.security.NoSuchAlgorithmException - should not happen
protected void testPathResolution(AbstractFile file,
java.lang.String path)
throws java.io.IOException,
java.security.NoSuchAlgorithmException
FileFactory.getFile(String) into
a file, and that this file is equal to the given one. If the given file is not a directory, the contents of both
file instances are compared to make sure they are equal.
file - the file instance that corresponds to the given pathpath - the path that should be resolved into the specified file
java.io.IOException - should not happen
java.security.NoSuchAlgorithmException - should not happen
public void testDigest()
throws java.io.IOException,
java.security.NoSuchAlgorithmException
AbstractFile.calculateChecksum(java.security.MessageDigest) and ByteUtils.toHexString(byte[])
by computing file digests using different algorithms (MD5, SHA-1, ...) and comparing them against known values.
java.io.IOException - should not happen
java.security.NoSuchAlgorithmException - should not happenpublic void testSeparator()
AbstractFile.getSeparator() by simply asserting that the return value is not null.
public void testAbsolutePath()
throws java.io.IOException,
java.security.NoSuchAlgorithmException
AbstractFile.getAbsolutePath() by asserting that it returns a non-null value, that the file can
be resolved again using this path, and that the resolved file is the same as the orginal file.
The tests are performed on a regular file and a directory file.
java.io.IOException - should not happen
java.security.NoSuchAlgorithmException - should not happen
public void testCanonicalPath()
throws java.io.IOException,
java.security.NoSuchAlgorithmException
AbstractFile.getCanonicalPath() by asserting that it returns a non-null value, that the file can
be resolved again using this path, and that the resolved file is the same as the orginal file.
The tests are performed on a regular file and a directory file.
java.io.IOException - should not happen
java.security.NoSuchAlgorithmException - should not happen
public void testFileURL()
throws java.io.IOException,
java.security.NoSuchAlgorithmException
AbstractFile.getURL() by asserting that it returns a non-null value, that the file can
be resolved again using its string representation (with credentials), and that the resolved file is the same as
the orginal file. The tests are performed on a regular file and a directory file.
java.io.IOException - should not happen
java.security.NoSuchAlgorithmException - should not happen
public void testJavaNetURL()
throws java.io.IOException,
java.security.NoSuchAlgorithmException
java.net.URL returned by AbstractFile.getJavaNetURL()
and its associated java.net.URLConnection.
java.io.IOException - should not happen
java.security.NoSuchAlgorithmException - should not happen
public void testRoot()
throws java.io.IOException
AbstractFile.getRoot() and AbstractFile.isRoot() methods.
java.io.IOException - should not happen
public void testParent()
throws java.io.IOException
AbstractFile.getParent() and AbstractFile.isParentOf(AbstractFile) methods.
java.io.IOException - should not happen
public void testExists()
throws java.io.IOException
AbstractFile.exists() in various situations.
java.io.IOException - should not happen
public void testDelete()
throws java.io.IOException
AbstractFile.delete() method in various situations.
java.io.IOException - should not happen
public void testMkdir()
throws java.io.IOException
AbstractFile.mkdir() method in various situations.
java.io.IOException - should not happen
public void testMkdirs()
throws java.io.IOException
AbstractFile.mkdirs() method in various situations.
java.io.IOException - should not happen
public void testMkfile()
throws java.io.IOException
AbstractFile.mkfile() method in various situations.
java.io.IOException - should not happen
public void testIsDirectory()
throws java.io.IOException
AbstractFile.isDirectory() method in various situations.
java.io.IOException - should not happen
public void testPermissions()
throws java.io.IOException,
java.security.NoSuchAlgorithmException
AbstractFile permission methods.
java.io.IOException - should not happen
java.security.NoSuchAlgorithmException - should not happen
public void testDate()
throws java.io.IOException,
java.security.NoSuchAlgorithmException
AbstractFile.getDate(), AbstractFile.canChangeDate() and AbstractFile.changeDate(long),
no matter if dates can be changed or not.
java.io.IOException - should not happen
java.security.NoSuchAlgorithmException - should not happen
public void testInputStream()
throws java.io.IOException,
java.security.NoSuchAlgorithmException
AbstractFile.getInputStream().
java.io.IOException - should not happen
java.security.NoSuchAlgorithmException - should not happen
public void testRandomAccessInputStream()
throws java.io.IOException,
java.security.NoSuchAlgorithmException
AbstractFile.hasRandomAccessInputStream() and AbstractFile.getRandomAccessInputStream().
java.io.IOException - should not happen
java.security.NoSuchAlgorithmException - should not happen
public void testOutputStream()
throws java.io.IOException,
java.security.NoSuchAlgorithmException
AbstractFile.getOutputStream(boolean).
java.io.IOException - should not happen
java.security.NoSuchAlgorithmException - should not happen
public void testRandomAccessOutputStream()
throws java.io.IOException,
java.security.NoSuchAlgorithmException
AbstractFile.hasRandomAccessOutputStream() and AbstractFile.getRandomAccessOutputStream().
java.io.IOException - should not happen
java.security.NoSuchAlgorithmException - should not happen
public void testLs()
throws java.io.IOException
AbstractFile.ls().
java.io.IOException - should not happenpublic void testFreeSpace()
AbstractFile.getFreeSpace() by asserting that the returned value is either -1
(not available), or a positive (potentially null) value.
public void testTotalSpace()
AbstractFile.getTotalSpace() by asserting that the returned value is either -1
(not available), or a positive (potentially null) value.
public void testCopyTo()
throws java.io.IOException,
java.security.NoSuchAlgorithmException
AbstractFile.getCopyToHint(AbstractFile) and AbstractFile.copyTo(AbstractFile).
java.io.IOException - should not happen
java.security.NoSuchAlgorithmException - should not happen
public void testMoveTo()
throws java.io.IOException,
java.security.NoSuchAlgorithmException
AbstractFile.getMoveToHint(AbstractFile) and AbstractFile.moveTo(AbstractFile).
java.io.IOException - should not happen
java.security.NoSuchAlgorithmException - should not happens
public void testIcon()
throws java.io.IOException
AbstractFile.getIcon() and AbstractFile.getIcon(java.awt.Dimension).
java.io.IOException - should not happen
public void testUnicodeFilenames()
throws java.io.IOException
java.io.IOException - should not happen
public abstract AbstractFile getTemporaryFile()
throws java.io.IOException
AbstractFile.exists()
returns false.
java.io.IOException - if an error occurred while creating a temporary file
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard