You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by kr...@apache.org on 2015/12/09 20:50:31 UTC
svn commit: r1718944 [1/6] - in
/commons/proper/io/trunk/src/test/java/org/apache/commons/io: ./
comparator/ filefilter/ input/ monitor/ output/ testtools/
Author: krosenvold
Date: Wed Dec 9 19:50:30 2015
New Revision: 1718944
URL: http://svn.apache.org/viewvc?rev=1718944&view=rev
Log:
Converted all tests to JUnit4
Test count is 1157 as oppsoed to 1156 because JUnit4 counts @Ignored tests as run.
Added:
commons/proper/io/trunk/src/test/java/org/apache/commons/io/testtools/TestUtils.java
- copied, changed from r1718920, commons/proper/io/trunk/src/test/java/org/apache/commons/io/testtools/FileBasedTestCase.java
Modified:
commons/proper/io/trunk/src/test/java/org/apache/commons/io/ByteOrderMarkTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/CopyUtilsTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/DirectoryWalkerTestCaseJava4.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/EndianUtilsTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileCleanerTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileCleaningTrackerTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileDeleteStrategyTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileSystemUtilsTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsCleanDirectoryTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsCleanSymlinksTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsDirectoryContainsTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsFileNewerTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsListFilesTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsWaitForTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/FilenameUtilsTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/FilenameUtilsWildcardTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/HexDumpTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/IOCaseTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/IOExceptionWithCauseTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/IOUtilsCopyTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/IOUtilsTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/IOUtilsWriteTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/LineIteratorTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/TaggedIOExceptionTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/ThreadMonitorTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/comparator/ComparatorAbstractTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/comparator/CompositeFileComparatorTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/comparator/DefaultFileComparatorTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/comparator/DirectoryFileComparatorTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/comparator/ExtensionFileComparatorTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/comparator/LastModifiedFileComparatorTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/comparator/NameFileComparatorTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/comparator/PathFileComparatorTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/comparator/SizeFileComparatorTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/AndFileFilterTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/ConditionalFileFilterAbstractTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/FileFilterTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/IOFileFilterAbstractTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/OrFileFilterTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/RegexFileFilterTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/AutoCloseInputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BoundedInputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BrokenInputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClassLoaderObjectInputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CloseShieldInputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClosedInputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CountingInputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/NullInputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/NullReaderTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ProxyReaderTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/SwappedDataInputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TaggedInputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TeeInputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/monitor/AbstractMonitorTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/monitor/FileAlterationMonitorTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/monitor/FileAlterationObserverTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/BrokenOutputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ByteArrayOutputStreamTestCase.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/CloseShieldOutputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ClosedOutputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/CountingOutputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/FileWriterWithEncodingTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/LockableFileWriterTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/NullOutputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/NullWriterTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ProxyOutputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/StringBuilderWriterTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/TaggedOutputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/TeeOutputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/WriterOutputStreamTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/XmlStreamWriterTest.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/testtools/FileBasedTestCase.java
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/ByteOrderMarkTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/ByteOrderMarkTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/ByteOrderMarkTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/ByteOrderMarkTestCase.java Wed Dec 9 19:50:30 2015
@@ -16,10 +16,17 @@
*/
package org.apache.commons.io;
+
import java.nio.charset.Charset;
import java.util.Arrays;
-import org.apache.commons.io.testtools.FileBasedTestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
@@ -27,25 +34,23 @@ import org.apache.commons.io.testtools.F
*
* @version $Id$
*/
-public class ByteOrderMarkTestCase extends FileBasedTestCase {
+public class ByteOrderMarkTestCase {
private static final ByteOrderMark TEST_BOM_1 = new ByteOrderMark("test1", 1);
private static final ByteOrderMark TEST_BOM_2 = new ByteOrderMark("test2", 1, 2);
private static final ByteOrderMark TEST_BOM_3 = new ByteOrderMark("test3", 1, 2, 3);
- public ByteOrderMarkTestCase(final String name) {
- super(name);
- }
-
/** Test {@link ByteOrderMark#getCharsetName()} */
- public void testCharsetName() {
+ @Test
+ public void charsetName() {
assertEquals("test1 name", "test1", TEST_BOM_1.getCharsetName());
assertEquals("test2 name", "test2", TEST_BOM_2.getCharsetName());
assertEquals("test3 name", "test3", TEST_BOM_3.getCharsetName());
}
/** Tests that {@link ByteOrderMark#getCharsetName()} can be loaded as a {@link java.nio.charset.Charset} as advertised. */
- public void testConstantCharsetNames() {
+ @Test
+ public void constantCharsetNames() {
assertNotNull(Charset.forName(ByteOrderMark.UTF_8.getCharsetName()));
assertNotNull(Charset.forName(ByteOrderMark.UTF_16BE.getCharsetName()));
assertNotNull(Charset.forName(ByteOrderMark.UTF_16LE.getCharsetName()));
@@ -54,14 +59,15 @@ public class ByteOrderMarkTestCase exten
}
/** Test {@link ByteOrderMark#length()} */
- public void testLength() {
- assertEquals("test1 length", 1, TEST_BOM_1.length());
+ @Test
+ public void testLength() { assertEquals("test1 length", 1, TEST_BOM_1.length());
assertEquals("test2 length", 2, TEST_BOM_2.length());
assertEquals("test3 length", 3, TEST_BOM_3.length());
}
/** Test {@link ByteOrderMark#get(int)} */
- public void testGet() {
+ @Test
+ public void get() {
assertEquals("test1 get(0)", 1, TEST_BOM_1.get(0));
assertEquals("test2 get(0)", 1, TEST_BOM_2.get(0));
assertEquals("test2 get(1)", 2, TEST_BOM_2.get(1));
@@ -71,13 +77,16 @@ public class ByteOrderMarkTestCase exten
}
/** Test {@link ByteOrderMark#getBytes()} */
- public void testGetBytes() {
+ @Test
+ public void getBytes() {
assertTrue("test1 bytes", Arrays.equals(TEST_BOM_1.getBytes(), new byte[] {(byte)1}));
assertTrue("test1 bytes", Arrays.equals(TEST_BOM_2.getBytes(), new byte[] {(byte)1, (byte)2}));
assertTrue("test1 bytes", Arrays.equals(TEST_BOM_3.getBytes(), new byte[] {(byte)1, (byte)2, (byte)3}));
}
/** Test {@link ByteOrderMark#equals(Object)} */
+ @SuppressWarnings("EqualsWithItself")
+ @Test
public void testEquals() {
assertTrue("test1 equals", TEST_BOM_1.equals(TEST_BOM_1));
assertTrue("test2 equals", TEST_BOM_2.equals(TEST_BOM_2));
@@ -91,6 +100,7 @@ public class ByteOrderMarkTestCase exten
}
/** Test {@link ByteOrderMark#hashCode()} */
+ @Test
public void testHashCode() {
final int bomClassHash = ByteOrderMark.class.hashCode();
assertEquals("hash test1 ", bomClassHash + 1, TEST_BOM_1.hashCode());
@@ -99,7 +109,8 @@ public class ByteOrderMarkTestCase exten
}
/** Test Erros */
- public void testErrors() {
+ @Test
+ public void errors() {
try {
new ByteOrderMark(null, 1,2,3);
fail("null charset name, expected IllegalArgumentException");
@@ -127,6 +138,7 @@ public class ByteOrderMarkTestCase exten
}
/** Test {@link ByteOrderMark#toString()} */
+ @Test
public void testToString() {
assertEquals("test1 ", "ByteOrderMark[test1: 0x1]", TEST_BOM_1.toString());
assertEquals("test2 ", "ByteOrderMark[test2: 0x1,0x2]", TEST_BOM_2.toString());
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/CopyUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/CopyUtilsTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/CopyUtilsTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/CopyUtilsTest.java Wed Dec 9 19:50:30 2015
@@ -26,8 +26,15 @@ import java.util.Arrays;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.commons.io.testtools.FileBasedTestCase;
+import org.apache.commons.io.testtools.TestUtils;
import org.apache.commons.io.testtools.YellOnCloseInputStream;
import org.apache.commons.io.testtools.YellOnFlushAndCloseOutputStream;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
@SuppressWarnings("deprecation") // these are test cases for the deprecated CopyUtils
@@ -49,34 +56,20 @@ public class CopyUtilsTest extends FileB
private static final int FILE_SIZE = 1024 * 4 + 1;
- private final byte[] inData = generateTestData(FILE_SIZE);
-
- public CopyUtilsTest(final String testName) {
- super(testName);
- }
-
- // ----------------------------------------------------------------
- // Setup
- // ----------------------------------------------------------------
-
- @Override
- public void setUp() throws Exception {
- }
-
- @Override
- public void tearDown() throws Exception {
- }
+ private final byte[] inData = TestUtils.generateTestData((long) FILE_SIZE);
// ----------------------------------------------------------------
// Tests
// ----------------------------------------------------------------
+ @Test
public void testCtor() {
new CopyUtils();
// Nothing to assert, the constructor is public and does not blow up.
}
- public void testCopy_byteArrayToOutputStream() throws Exception {
+ @Test
+ public void copy_byteArrayToOutputStream() throws Exception {
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
final OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true);
@@ -86,7 +79,8 @@ public class CopyUtilsTest extends FileB
assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
}
- public void testCopy_byteArrayToWriter() throws Exception {
+ @Test
+ public void copy_byteArrayToWriter() throws Exception {
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
final OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true);
final Writer writer = new java.io.OutputStreamWriter(out, "US-ASCII");
@@ -98,6 +92,7 @@ public class CopyUtilsTest extends FileB
assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
}
+ @Test
public void testCopy_byteArrayToWriterWithEncoding() throws Exception {
final String inDataStr = "data";
final String charsetName = "UTF-8";
@@ -107,6 +102,7 @@ public class CopyUtilsTest extends FileB
}
@SuppressWarnings("resource") // 'in' is deliberately not closed
+ @Test
public void testCopy_inputStreamToOutputStream() throws Exception {
InputStream in = new ByteArrayInputStream(inData);
in = new YellOnCloseInputStream(in);
@@ -123,7 +119,8 @@ public class CopyUtilsTest extends FileB
}
@SuppressWarnings("resource") // 'in' is deliberately not closed
- public void testCopy_inputStreamToWriter() throws Exception {
+ @Test
+ public void copy_inputStreamToWriter() throws Exception {
InputStream in = new ByteArrayInputStream(inData);
in = new YellOnCloseInputStream(in);
@@ -139,7 +136,8 @@ public class CopyUtilsTest extends FileB
assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
}
- public void testCopy_inputStreamToWriterWithEncoding() throws Exception {
+ @Test
+ public void copy_inputStreamToWriterWithEncoding() throws Exception {
final String inDataStr = "data";
final String charsetName = "UTF-8";
final StringWriter writer = new StringWriter();
@@ -148,6 +146,7 @@ public class CopyUtilsTest extends FileB
}
@SuppressWarnings("resource") // 'in' is deliberately not closed
+ @Test
public void testCopy_readerToOutputStream() throws Exception {
InputStream in = new ByteArrayInputStream(inData);
in = new YellOnCloseInputStream(in);
@@ -169,7 +168,8 @@ public class CopyUtilsTest extends FileB
}
@SuppressWarnings("resource") // 'in' is deliberately not closed
- public void testCopy_readerToWriter() throws Exception {
+ @Test
+ public void copy_readerToWriter() throws Exception {
InputStream in = new ByteArrayInputStream(inData);
in = new YellOnCloseInputStream(in);
final Reader reader = new java.io.InputStreamReader(in, "US-ASCII");
@@ -188,7 +188,8 @@ public class CopyUtilsTest extends FileB
assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
}
- public void testCopy_stringToOutputStream() throws Exception {
+ @Test
+ public void copy_stringToOutputStream() throws Exception {
final String str = new String(inData, "US-ASCII");
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
@@ -206,7 +207,8 @@ public class CopyUtilsTest extends FileB
assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
}
- public void testCopy_stringToWriter() throws Exception {
+ @Test
+ public void copy_stringToWriter() throws Exception {
final String str = new String(inData, "US-ASCII");
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/DirectoryWalkerTestCaseJava4.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/DirectoryWalkerTestCaseJava4.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/DirectoryWalkerTestCaseJava4.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/DirectoryWalkerTestCaseJava4.java Wed Dec 9 19:50:30 2015
@@ -16,6 +16,12 @@
*/
package org.apache.commons.io;
+import org.apache.commons.io.filefilter.FileFilterUtils;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.filefilter.NameFileFilter;
+import org.apache.commons.io.filefilter.OrFileFilter;
+import org.junit.Test;
+
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
@@ -23,12 +29,10 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import junit.framework.TestCase;
-import org.apache.commons.io.filefilter.FileFilterUtils;
-import org.apache.commons.io.filefilter.IOFileFilter;
-import org.apache.commons.io.filefilter.NameFileFilter;
-import org.apache.commons.io.filefilter.OrFileFilter;
-import org.junit.Assert;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* This is used to test DirectoryWalker for correctness when using Java4 (i.e. no generics).
@@ -37,7 +41,7 @@ import org.junit.Assert;
* @see DirectoryWalker
*/
@SuppressWarnings({"unchecked", "rawtypes"}) // Java4
-public class DirectoryWalkerTestCaseJava4 extends TestCase {
+public class DirectoryWalkerTestCaseJava4 {
// Directories
private static final File current = new File(".");
@@ -67,25 +71,12 @@ public class DirectoryWalkerTestCaseJava
// Filter to exclude SVN files
private static final IOFileFilter NOT_SVN = FileFilterUtils.makeSVNAware(null);
- public DirectoryWalkerTestCaseJava4(final String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
//-----------------------------------------------------------------------
/**
* Test Filtering
*/
+ @Test
public void testFilter() {
final List<File> results = new TestFileFinder(dirsAndFilesFilter, -1).find(javaDir);
assertEquals("Result Size", 1 + dirs.length + ioFiles.length + outputFiles.length, results.size());
@@ -98,6 +89,7 @@ public class DirectoryWalkerTestCaseJava
/**
* Test Filtering and limit to depth 0
*/
+ @Test
public void testFilterAndLimitA() {
final List<File> results = new TestFileFinder(NOT_SVN, 0).find(javaDir);
assertEquals("[A] Result Size", 1, results.size());
@@ -107,6 +99,7 @@ public class DirectoryWalkerTestCaseJava
/**
* Test Filtering and limit to depth 1
*/
+ @Test
public void testFilterAndLimitB() {
final List<File> results = new TestFileFinder(NOT_SVN, 1).find(javaDir);
assertEquals("[B] Result Size", 2, results.size());
@@ -117,6 +110,7 @@ public class DirectoryWalkerTestCaseJava
/**
* Test Filtering and limit to depth 3
*/
+ @Test
public void testFilterAndLimitC() {
final List<File> results = new TestFileFinder(NOT_SVN, 3).find(javaDir);
assertEquals("[C] Result Size", 4, results.size());
@@ -129,6 +123,7 @@ public class DirectoryWalkerTestCaseJava
/**
* Test Filtering and limit to depth 5
*/
+ @Test
public void testFilterAndLimitD() {
final List<File> results = new TestFileFinder(dirsAndFilesFilter, 5).find(javaDir);
assertEquals("[D] Result Size", 1 + dirs.length + ioFiles.length, results.size());
@@ -140,6 +135,7 @@ public class DirectoryWalkerTestCaseJava
/**
* Test separate dir and file filters
*/
+ @Test
public void testFilterDirAndFile1() {
final List<File> results = new TestFileFinder(dirsFilter, iofilesFilter, -1).find(javaDir);
assertEquals("[DirAndFile1] Result Size", 1 + dirs.length + ioFiles.length, results.size());
@@ -151,6 +147,7 @@ public class DirectoryWalkerTestCaseJava
/**
* Test separate dir and file filters
*/
+ @Test
public void testFilterDirAndFile2() {
final List<File> results = new TestFileFinder(null, null, -1).find(javaDir);
assertTrue("[DirAndFile2] Result Size", results.size() > 1 + dirs.length + ioFiles.length);
@@ -162,6 +159,7 @@ public class DirectoryWalkerTestCaseJava
/**
* Test separate dir and file filters
*/
+ @Test
public void testFilterDirAndFile3() {
final List<File> results = new TestFileFinder(dirsFilter, null, -1).find(javaDir);
final List resultDirs = directoriesOnly(results);
@@ -173,6 +171,7 @@ public class DirectoryWalkerTestCaseJava
/**
* Test separate dir and file filters
*/
+ @Test
public void testFilterDirAndFile4() {
final List<File> results = new TestFileFinder(null, iofilesFilter, -1).find(javaDir);
final List resultFiles = filesOnly(results);
@@ -184,6 +183,7 @@ public class DirectoryWalkerTestCaseJava
/**
* Test Limiting to current directory
*/
+ @Test
public void testLimitToCurrent() {
final List<File> results = new TestFileFinder(null, 0).find(current);
assertEquals("Result Size", 1, results.size());
@@ -193,6 +193,7 @@ public class DirectoryWalkerTestCaseJava
/**
* test an invalid start directory
*/
+ @Test
public void testMissingStartDirectory() {
// TODO is this what we want with invalid directory?
@@ -212,6 +213,7 @@ public class DirectoryWalkerTestCaseJava
/**
* test an invalid start directory
*/
+ @Test
public void testHandleStartDirectoryFalse() {
final List<File> results = new TestFalseFileFinder(null, -1).find(current);
@@ -271,6 +273,7 @@ public class DirectoryWalkerTestCaseJava
/**
* Test Cancel
*/
+ @Test
public void testCancel() {
String cancelName = null;
@@ -312,6 +315,7 @@ public class DirectoryWalkerTestCaseJava
/**
* Test Cancel
*/
+ @Test
public void testMultiThreadCancel() {
String cancelName = "DirectoryWalker.java";
TestMultiThreadCancelWalker walker = new TestMultiThreadCancelWalker(cancelName, false);
@@ -376,7 +380,7 @@ public class DirectoryWalkerTestCaseJava
try {
walk(startDirectory, results);
} catch (final IOException ex) {
- Assert.fail(ex.toString());
+ fail(ex.toString());
}
return results;
}
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/EndianUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/EndianUtilsTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/EndianUtilsTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/EndianUtilsTest.java Wed Dec 9 19:50:30 2015
@@ -16,27 +16,28 @@
*/
package org.apache.commons.io;
+import org.junit.Test;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.IOException;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* @version $Id$
*/
-public class EndianUtilsTest extends TestCase {
-
- public EndianUtilsTest(final String name) {
- super(name);
- }
+public class EndianUtilsTest {
+ @Test
public void testCtor() {
new EndianUtils();
// Constructor does not blow up.
}
+ @Test
public void testEOFException() throws IOException {
final ByteArrayInputStream input = new ByteArrayInputStream(new byte[] {});
try {
@@ -47,6 +48,7 @@ public class EndianUtilsTest extends Tes
}
}
+ @Test
public void testSwapShort() {
assertEquals( (short) 0, EndianUtils.swapShort( (short) 0 ) );
assertEquals( (short) 0x0201, EndianUtils.swapShort( (short) 0x0102 ) );
@@ -54,6 +56,7 @@ public class EndianUtilsTest extends Tes
assertEquals( (short) 0x0102, EndianUtils.swapShort( (short) 0x0201 ) );
}
+ @Test
public void testSwapInteger() {
assertEquals( 0, EndianUtils.swapInteger( 0 ) );
assertEquals( 0x04030201, EndianUtils.swapInteger( 0x01020304 ) );
@@ -64,6 +67,7 @@ public class EndianUtilsTest extends Tes
assertEquals( 0xab, EndianUtils.swapInteger( 0xab000000 ) );
}
+ @Test
public void testSwapLong() {
assertEquals( 0, EndianUtils.swapLong( 0 ) );
assertEquals( 0x0807060504030201L, EndianUtils.swapLong( 0x0102030405060708L ) );
@@ -71,6 +75,7 @@ public class EndianUtilsTest extends Tes
assertEquals( 0xab, EndianUtils.swapLong( 0xab00000000000000L ) );
}
+ @Test
public void testSwapFloat() {
assertEquals( 0.0f, EndianUtils.swapFloat( 0.0f ), 0.0 );
final float f1 = Float.intBitsToFloat( 0x01020304 );
@@ -78,6 +83,7 @@ public class EndianUtilsTest extends Tes
assertEquals( f2, EndianUtils.swapFloat( f1 ), 0.0 );
}
+ @Test
public void testSwapDouble() {
assertEquals( 0.0, EndianUtils.swapDouble( 0.0 ), 0.0 );
final double d1 = Double.longBitsToDouble( 0x0102030405060708L );
@@ -89,6 +95,7 @@ public class EndianUtilsTest extends Tes
* Tests all swapXxxx methods for symmetry when going from one endian
* to another and back again.
*/
+ @Test
public void testSymmetry() {
assertEquals( (short) 0x0102, EndianUtils.swapShort( EndianUtils.swapShort( (short) 0x0102 ) ) );
assertEquals( 0x01020304, EndianUtils.swapInteger( EndianUtils.swapInteger( 0x01020304 ) ) );
@@ -99,6 +106,7 @@ public class EndianUtilsTest extends Tes
assertEquals( d1, EndianUtils.swapDouble( EndianUtils.swapDouble( d1 ) ), 0.0 );
}
+ @Test
public void testReadSwappedShort() throws IOException {
final byte[] bytes = new byte[] { 0x02, 0x01 };
assertEquals( 0x0102, EndianUtils.readSwappedShort( bytes, 0 ) );
@@ -107,6 +115,7 @@ public class EndianUtilsTest extends Tes
assertEquals( 0x0102, EndianUtils.readSwappedShort( input ) );
}
+ @Test
public void testWriteSwappedShort() throws IOException {
byte[] bytes = new byte[2];
EndianUtils.writeSwappedShort( bytes, 0, (short) 0x0102 );
@@ -120,6 +129,7 @@ public class EndianUtilsTest extends Tes
assertEquals( 0x01, bytes[1] );
}
+ @Test
public void testReadSwappedUnsignedShort() throws IOException {
final byte[] bytes = new byte[] { 0x02, 0x01 };
assertEquals( 0x00000102, EndianUtils.readSwappedUnsignedShort( bytes, 0 ) );
@@ -128,6 +138,7 @@ public class EndianUtilsTest extends Tes
assertEquals( 0x00000102, EndianUtils.readSwappedUnsignedShort( input ) );
}
+ @Test
public void testReadSwappedInteger() throws IOException {
final byte[] bytes = new byte[] { 0x04, 0x03, 0x02, 0x01 };
assertEquals( 0x01020304, EndianUtils.readSwappedInteger( bytes, 0 ) );
@@ -136,6 +147,7 @@ public class EndianUtilsTest extends Tes
assertEquals( 0x01020304, EndianUtils.readSwappedInteger( input ) );
}
+ @Test
public void testWriteSwappedInteger() throws IOException {
byte[] bytes = new byte[4];
EndianUtils.writeSwappedInteger( bytes, 0, 0x01020304 );
@@ -153,6 +165,7 @@ public class EndianUtilsTest extends Tes
assertEquals( 0x01, bytes[3] );
}
+ @Test
public void testReadSwappedUnsignedInteger() throws IOException {
final byte[] bytes = new byte[] { 0x04, 0x03, 0x02, 0x01 };
assertEquals( 0x0000000001020304L, EndianUtils.readSwappedUnsignedInteger( bytes, 0 ) );
@@ -161,6 +174,7 @@ public class EndianUtilsTest extends Tes
assertEquals( 0x0000000001020304L, EndianUtils.readSwappedUnsignedInteger( input ) );
}
+ @Test
public void testReadSwappedLong() throws IOException {
final byte[] bytes = new byte[] { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 };
assertEquals( 0x0102030405060708L, EndianUtils.readSwappedLong( bytes, 0 ) );
@@ -169,6 +183,7 @@ public class EndianUtilsTest extends Tes
assertEquals( 0x0102030405060708L, EndianUtils.readSwappedLong( input ) );
}
+ @Test
public void testWriteSwappedLong() throws IOException {
byte[] bytes = new byte[8];
EndianUtils.writeSwappedLong( bytes, 0, 0x0102030405060708L );
@@ -194,6 +209,7 @@ public class EndianUtilsTest extends Tes
assertEquals( 0x01, bytes[7] );
}
+ @Test
public void testReadSwappedFloat() throws IOException {
final byte[] bytes = new byte[] { 0x04, 0x03, 0x02, 0x01 };
final float f1 = Float.intBitsToFloat( 0x01020304 );
@@ -204,6 +220,7 @@ public class EndianUtilsTest extends Tes
assertEquals( f1, EndianUtils.readSwappedFloat( input ), 0.0 );
}
+ @Test
public void testWriteSwappedFloat() throws IOException {
byte[] bytes = new byte[4];
final float f1 = Float.intBitsToFloat( 0x01020304 );
@@ -222,6 +239,7 @@ public class EndianUtilsTest extends Tes
assertEquals( 0x01, bytes[3] );
}
+ @Test
public void testReadSwappedDouble() throws IOException {
final byte[] bytes = new byte[] { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 };
final double d1 = Double.longBitsToDouble( 0x0102030405060708L );
@@ -232,6 +250,7 @@ public class EndianUtilsTest extends Tes
assertEquals( d1, EndianUtils.readSwappedDouble( input ), 0.0 );
}
+ @Test
public void testWriteSwappedDouble() throws IOException {
byte[] bytes = new byte[8];
final double d1 = Double.longBitsToDouble( 0x0102030405060708L );
@@ -259,6 +278,7 @@ public class EndianUtilsTest extends Tes
}
// tests #IO-101
+ @Test
public void testSymmetryOfLong() {
final double[] tests = new double[] {34.345, -345.5645, 545.12, 10.043, 7.123456789123};
@@ -280,6 +300,7 @@ public class EndianUtilsTest extends Tes
}
// tests #IO-117
+ @Test
public void testUnsignedOverrun() throws Exception {
final byte[] target = new byte[] { 0, 0, 0, (byte)0x80 };
final long expected = 0x80000000L;
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileCleanerTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileCleanerTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileCleanerTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileCleanerTestCase.java Wed Dec 9 19:50:30 2015
@@ -29,8 +29,4 @@ public class FileCleanerTestCase extends
protected FileCleaningTracker newInstance() {
return FileCleaner.getInstance();
}
-
- public FileCleanerTestCase(final String name) {
- super(name);
- }
}
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileCleaningTrackerTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileCleaningTrackerTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileCleaningTrackerTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileCleaningTrackerTestCase.java Wed Dec 9 19:50:30 2015
@@ -16,13 +16,21 @@
*/
package org.apache.commons.io;
-import java.io.File;
-import java.io.RandomAccessFile;
+import org.apache.commons.io.testtools.FileBasedTestCase;
+import org.apache.commons.io.testtools.TestUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.*;
import java.lang.ref.ReferenceQueue;
import java.util.ArrayList;
import java.util.List;
-import org.apache.commons.io.testtools.FileBasedTestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* This is used to test {@link FileCleaningTracker} for correctness.
@@ -38,21 +46,18 @@ public class FileCleaningTrackerTestCase
private File testFile;
private FileCleaningTracker theInstance;
- public FileCleaningTrackerTestCase(final String name) {
- super(name);
+ public FileCleaningTrackerTestCase() {
testFile = new File(getTestDirectory(), "file-test.txt");
}
- /** @see junit.framework.TestCase#setUp() */
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
theInstance = newInstance();
- getTestDirectory().mkdirs();
+ getTestDirectory();
}
- /** @see junit.framework.TestCase#tearDown() */
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
FileUtils.deleteDirectory(getTestDirectory());
// reset file cleaner class, so as not to break other tests
@@ -75,6 +80,7 @@ public class FileCleaningTrackerTestCase
}
//-----------------------------------------------------------------------
+ @Test
public void testFileCleanerFile() throws Exception {
final String path = testFile.getPath();
@@ -97,8 +103,9 @@ public class FileCleaningTrackerTestCase
assertEquals(showFailures(), false, new File(path).exists());
}
+ @Test
public void testFileCleanerDirectory() throws Exception {
- createFile(testFile, 100);
+ TestUtils.createFile(testFile, 100);
assertTrue(testFile.exists());
assertTrue(getTestDirectory().exists());
@@ -116,8 +123,9 @@ public class FileCleaningTrackerTestCase
assertTrue(testFile.getParentFile().exists()); // not deleted, as dir not empty
}
+ @Test
public void testFileCleanerDirectory_NullStrategy() throws Exception {
- createFile(testFile, 100);
+ TestUtils.createFile(testFile, 100);
assertTrue(testFile.exists());
assertTrue(getTestDirectory().exists());
@@ -135,8 +143,19 @@ public class FileCleaningTrackerTestCase
assertTrue(testFile.getParentFile().exists()); // not deleted, as dir not empty
}
+ @Test
public void testFileCleanerDirectory_ForceStrategy() throws Exception {
- createFile(testFile, 100);
+ if (!testFile.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + testFile
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(testFile));
+ try {
+ TestUtils.generateTestData(output, (long) 100);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
assertTrue(testFile.exists());
assertTrue(getTestDirectory().exists());
@@ -155,6 +174,7 @@ public class FileCleaningTrackerTestCase
assertEquals(showFailures(), false, testFile.getParentFile().exists());
}
+ @Test
public void testFileCleanerNull() throws Exception {
try {
theInstance.track((File) null, new Object());
@@ -182,6 +202,7 @@ public class FileCleaningTrackerTestCase
}
}
+ @Test
public void testFileCleanerExitWhenFinishedFirst() throws Exception {
assertFalse(theInstance.exitWhenFinished);
theInstance.exitWhenFinished();
@@ -195,6 +216,7 @@ public class FileCleaningTrackerTestCase
assertEquals(null, theInstance.reaper);
}
+ @Test
public void testFileCleanerExitWhenFinished_NoTrackAfter() throws Exception {
assertFalse(theInstance.exitWhenFinished);
theInstance.exitWhenFinished();
@@ -213,6 +235,7 @@ public class FileCleaningTrackerTestCase
assertEquals(null, theInstance.reaper);
}
+ @Test
public void testFileCleanerExitWhenFinished1() throws Exception {
final String path = testFile.getPath();
@@ -244,6 +267,7 @@ public class FileCleaningTrackerTestCase
assertEquals("13-reaper.isAlive", false, theInstance.reaper.isAlive());
}
+ @Test
public void testFileCleanerExitWhenFinished2() throws Exception {
final String path = testFile.getPath();
@@ -284,7 +308,7 @@ public class FileCleaningTrackerTestCase
while(file.exists() && count++ < 40) {
try {
Thread.sleep(500L);
- } catch (final InterruptedException e) {
+ } catch (final InterruptedException ignore) {
}
file = new File(file.getPath());
}
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileDeleteStrategyTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileDeleteStrategyTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileDeleteStrategyTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileDeleteStrategyTestCase.java Wed Dec 9 19:50:30 2015
@@ -16,10 +16,19 @@
*/
package org.apache.commons.io;
+import org.apache.commons.io.testtools.FileBasedTestCase;
+import org.apache.commons.io.testtools.TestUtils;
+import org.junit.Test;
+
+import java.io.BufferedOutputStream;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
-import org.apache.commons.io.testtools.FileBasedTestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* Test for FileDeleteStrategy.
@@ -29,27 +38,24 @@ import org.apache.commons.io.testtools.F
*/
public class FileDeleteStrategyTestCase extends FileBasedTestCase {
- public FileDeleteStrategyTestCase(final String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
//-----------------------------------------------------------------------
+ @Test
public void testDeleteNormal() throws Exception {
final File baseDir = getTestDirectory();
final File subDir = new File(baseDir, "test");
assertTrue(subDir.mkdir());
final File subFile = new File(subDir, "a.txt");
- createFile(subFile, 16);
+ if (!subFile.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + subFile
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(subFile));
+ try {
+ TestUtils.generateTestData(output, (long) 16);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
assertTrue(subDir.exists());
assertTrue(subFile.exists());
@@ -74,12 +80,23 @@ public class FileDeleteStrategyTestCase
assertFalse(subDir.exists());
}
+ @Test
public void testDeleteQuietlyNormal() throws Exception {
final File baseDir = getTestDirectory();
final File subDir = new File(baseDir, "test");
assertTrue(subDir.mkdir());
final File subFile = new File(subDir, "a.txt");
- createFile(subFile, 16);
+ if (!subFile.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + subFile
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(subFile));
+ try {
+ TestUtils.generateTestData(output, (long) 16);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
assertTrue(subDir.exists());
assertTrue(subFile.exists());
@@ -99,12 +116,23 @@ public class FileDeleteStrategyTestCase
assertFalse(subDir.exists());
}
+ @Test
public void testDeleteForce() throws Exception {
final File baseDir = getTestDirectory();
final File subDir = new File(baseDir, "test");
assertTrue(subDir.mkdir());
final File subFile = new File(subDir, "a.txt");
- createFile(subFile, 16);
+ if (!subFile.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + subFile
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(subFile));
+ try {
+ TestUtils.generateTestData(output, (long) 16);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
assertTrue(subDir.exists());
assertTrue(subFile.exists());
@@ -117,6 +145,7 @@ public class FileDeleteStrategyTestCase
assertFalse(subDir.exists());
}
+ @Test
public void testDeleteNull() throws Exception {
try {
FileDeleteStrategy.NORMAL.delete(null);
@@ -127,6 +156,7 @@ public class FileDeleteStrategyTestCase
assertTrue(FileDeleteStrategy.NORMAL.deleteQuietly(null));
}
+ @Test
public void testToString() {
assertEquals("FileDeleteStrategy[Normal]", FileDeleteStrategy.NORMAL.toString());
assertEquals("FileDeleteStrategy[Force]", FileDeleteStrategy.FORCE.toString());
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileSystemUtilsTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileSystemUtilsTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileSystemUtilsTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileSystemUtilsTestCase.java Wed Dec 9 19:50:30 2015
@@ -16,17 +16,15 @@
*/
package org.apache.commons.io;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.util.Locale;
-
import org.apache.commons.io.testtools.FileBasedTestCase;
import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.*;
+import java.util.Locale;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* This is used to test FileSystemUtils.
@@ -35,16 +33,13 @@ import org.junit.Assert;
*/
public class FileSystemUtilsTestCase extends FileBasedTestCase {
- public FileSystemUtilsTestCase(final String name) {
- super(name);
- }
-
//-----------------------------------------------------------------------
+ @Test
public void testGetFreeSpace_String() throws Exception {
// test coverage, as we can't check value
if (File.separatorChar == '/') {
// have to figure out unix block size
- String[] cmd = null;
+ final String[] cmd;
String osName = System.getProperty("os.name");
osName = osName.toLowerCase(Locale.ENGLISH);
@@ -90,48 +85,52 @@ public class FileSystemUtilsTestCase ext
}
//-----------------------------------------------------------------------
+ @Test
public void testGetFreeSpaceOS_String_NullPath() throws Exception {
final FileSystemUtils fsu = new FileSystemUtils();
try {
fsu.freeSpaceOS(null, 1, false, -1);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
try {
fsu.freeSpaceOS(null, 1, true, -1);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
}
+ @Test
public void testGetFreeSpaceOS_String_InitError() throws Exception {
final FileSystemUtils fsu = new FileSystemUtils();
try {
fsu.freeSpaceOS("", -1, false, -1);
fail();
- } catch (final IllegalStateException ex) {
+ } catch (final IllegalStateException ignore) {
}
try {
fsu.freeSpaceOS("", -1, true, -1);
fail();
- } catch (final IllegalStateException ex) {
+ } catch (final IllegalStateException ignore) {
}
}
+ @Test
public void testGetFreeSpaceOS_String_Other() throws Exception {
final FileSystemUtils fsu = new FileSystemUtils();
try {
fsu.freeSpaceOS("", 0, false, -1);
fail();
- } catch (final IllegalStateException ex) {
+ } catch (final IllegalStateException ignore) {
}
try {
fsu.freeSpaceOS("", 0, true, -1);
fail();
- } catch (final IllegalStateException ex) {
+ } catch (final IllegalStateException ignore) {
}
}
+ @Test
public void testGetFreeSpaceOS_String_Windows() throws Exception {
final FileSystemUtils fsu = new FileSystemUtils() {
@Override
@@ -143,6 +142,7 @@ public class FileSystemUtilsTestCase ext
assertEquals(12345L / 1024, fsu.freeSpaceOS("", 1, true, -1));
}
+ @Test
public void testGetFreeSpaceOS_String_Unix() throws Exception {
final FileSystemUtils fsu = new FileSystemUtils() {
@Override
@@ -155,6 +155,7 @@ public class FileSystemUtilsTestCase ext
}
//-----------------------------------------------------------------------
+ @Test
public void testGetFreeSpaceWindows_String_ParseCommaFormatBytes() throws Exception {
// this is the format of response when calling dir /c
// we have now switched to dir /-c, so we should never get this
@@ -175,6 +176,7 @@ public class FileSystemUtilsTestCase ext
}
//-----------------------------------------------------------------------
+ @Test
public void testGetFreeSpaceWindows_String_EmptyPath() throws Exception {
final String lines =
" Volume in drive C is HDD\n" +
@@ -192,6 +194,7 @@ public class FileSystemUtilsTestCase ext
assertEquals(41411551232L, fsu.freeSpaceWindows("", -1));
}
+ @Test
public void testGetFreeSpaceWindows_String_NormalResponse() throws Exception {
final String lines =
" Volume in drive C is HDD\n" +
@@ -209,6 +212,7 @@ public class FileSystemUtilsTestCase ext
assertEquals(41411551232L, fsu.freeSpaceWindows("C:", -1));
}
+ @Test
public void testGetFreeSpaceWindows_String_StripDrive() throws Exception {
final String lines =
" Volume in drive C is HDD\n" +
@@ -226,6 +230,7 @@ public class FileSystemUtilsTestCase ext
assertEquals(41411551232L, fsu.freeSpaceWindows("C:\\somedir", -1));
}
+ @Test
public void testGetFreeSpaceWindows_String_quoted() throws Exception {
final String lines =
" Volume in drive C is HDD\n" +
@@ -243,36 +248,32 @@ public class FileSystemUtilsTestCase ext
assertEquals(41411551232L, fsu.freeSpaceWindows("\"C:\\somedir\"", -1));
}
+ @Test
public void testGetFreeSpaceWindows_String_EmptyResponse() throws Exception {
final String lines = "";
final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
try {
fsu.freeSpaceWindows("C:", -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
}
+ @Test(expected = IOException.class)
public void testGetFreeSpaceWindows_String_EmptyMultiLineResponse() throws Exception {
final String lines = "\n\n";
final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
- try {
- fsu.freeSpaceWindows("C:", -1);
- fail();
- } catch (final IOException ex) {
- }
+ fsu.freeSpaceWindows("C:", -1);
}
+ @Test(expected = IOException.class)
public void testGetFreeSpaceWindows_String_InvalidTextResponse() throws Exception {
final String lines = "BlueScreenOfDeath";
final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
- try {
- fsu.freeSpaceWindows("C:", -1);
- fail();
- } catch (final IOException ex) {
- }
+ fsu.freeSpaceWindows("C:", -1);
}
+ @Test(expected = IOException.class)
public void testGetFreeSpaceWindows_String_NoSuchDirectoryResponse() throws Exception {
final String lines =
" Volume in drive C is HDD\n" +
@@ -281,14 +282,11 @@ public class FileSystemUtilsTestCase ext
" Directory of C:\\Documents and Settings\\empty" +
"\n";
final FileSystemUtils fsu = new MockFileSystemUtils(1, lines);
- try {
- fsu.freeSpaceWindows("C:", -1);
- fail();
- } catch (final IOException ex) {
- }
+ fsu.freeSpaceWindows("C:", -1);
}
//-----------------------------------------------------------------------
+ @Test
public void testGetFreeSpaceUnix_String_EmptyPath() throws Exception {
final String lines =
"Filesystem 1K-blocks Used Available Use% Mounted on\n" +
@@ -297,26 +295,27 @@ public class FileSystemUtilsTestCase ext
try {
fsu.freeSpaceUnix("", false, false, -1);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
try {
fsu.freeSpaceUnix("", true, false, -1);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
try {
fsu.freeSpaceUnix("", true, true, -1);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
try {
fsu.freeSpaceUnix("", false, true, -1);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
}
+ @Test
public void testGetFreeSpaceUnix_String_NormalResponseLinux() throws Exception {
// from Sourceforge 'GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu)'
final String lines =
@@ -326,6 +325,7 @@ public class FileSystemUtilsTestCase ext
assertEquals(189416L, fsu.freeSpaceUnix("/", false, false, -1));
}
+ @Test
public void testGetFreeSpaceUnix_String_NormalResponseFreeBSD() throws Exception {
// from Apache 'FreeBSD 6.1-RELEASE (SMP-turbo)'
final String lines =
@@ -336,6 +336,7 @@ public class FileSystemUtilsTestCase ext
}
//-----------------------------------------------------------------------
+ @Test
public void testGetFreeSpaceUnix_String_NormalResponseKbLinux() throws Exception {
// from Sourceforge 'GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu)'
// df, df -k and df -kP are all identical
@@ -346,6 +347,7 @@ public class FileSystemUtilsTestCase ext
assertEquals(189416L, fsu.freeSpaceUnix("/", true, false, -1));
}
+ @Test
public void testGetFreeSpaceUnix_String_NormalResponseKbFreeBSD() throws Exception {
// from Apache 'FreeBSD 6.1-RELEASE (SMP-turbo)'
// df and df -k are identical, but df -kP uses 512 blocks (not relevant as not used)
@@ -356,6 +358,7 @@ public class FileSystemUtilsTestCase ext
assertEquals(15770L, fsu.freeSpaceUnix("/", true, false, -1));
}
+ @Test
public void testGetFreeSpaceUnix_String_NormalResponseKbSolaris() throws Exception {
// from IO-91 - ' SunOS et 5.10 Generic_118822-25 sun4u sparc SUNW,Ultra-4'
// non-kb response does not contain free space - see IO-91
@@ -366,6 +369,7 @@ public class FileSystemUtilsTestCase ext
assertEquals(481163L, fsu.freeSpaceUnix("/dev/dsk/x0x0x0x0", true, false, -1));
}
+ @Test
public void testGetFreeSpaceUnix_String_LongResponse() throws Exception {
final String lines =
"Filesystem 1K-blocks Used Available Use% Mounted on\n" +
@@ -375,6 +379,7 @@ public class FileSystemUtilsTestCase ext
assertEquals(1472504L, fsu.freeSpaceUnix("/home/users/s", false, false, -1));
}
+ @Test
public void testGetFreeSpaceUnix_String_LongResponseKb() throws Exception {
final String lines =
"Filesystem 1K-blocks Used Available Use% Mounted on\n" +
@@ -383,6 +388,7 @@ public class FileSystemUtilsTestCase ext
final FileSystemUtils fsu = new MockFileSystemUtils(0, lines);
assertEquals(1472504L, fsu.freeSpaceUnix("/home/users/s", true, false, -1));
}
+ @Test
public void testGetFreeSpaceUnix_String_EmptyResponse() throws Exception {
final String lines = "";
@@ -390,25 +396,26 @@ public class FileSystemUtilsTestCase ext
try {
fsu.freeSpaceUnix("/home/users/s", false, false, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
try {
fsu.freeSpaceUnix("/home/users/s", true, false, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
try {
fsu.freeSpaceUnix("/home/users/s", false, true, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
try {
fsu.freeSpaceUnix("/home/users/s", true, true, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
}
+ @Test
public void testGetFreeSpaceUnix_String_InvalidResponse1() throws Exception {
final String lines =
"Filesystem 1K-blocks Used Available Use% Mounted on\n" +
@@ -417,25 +424,26 @@ public class FileSystemUtilsTestCase ext
try {
fsu.freeSpaceUnix("/home/users/s", false, false, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
try {
fsu.freeSpaceUnix("/home/users/s", true, false, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
try {
fsu.freeSpaceUnix("/home/users/s", false, true, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
try {
fsu.freeSpaceUnix("/home/users/s", true, true, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
}
+ @Test
public void testGetFreeSpaceUnix_String_InvalidResponse2() throws Exception {
final String lines =
"Filesystem 1K-blocks Used Available Use% Mounted on\n" +
@@ -444,25 +452,26 @@ public class FileSystemUtilsTestCase ext
try {
fsu.freeSpaceUnix("/home/users/s", false, false, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
try {
fsu.freeSpaceUnix("/home/users/s", true, false, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
try {
fsu.freeSpaceUnix("/home/users/s", false, true, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
try {
fsu.freeSpaceUnix("/home/users/s", true, true, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
}
+ @Test
public void testGetFreeSpaceUnix_String_InvalidResponse3() throws Exception {
final String lines =
"Filesystem 1K-blocks Used Available Use% Mounted on\n" +
@@ -471,25 +480,26 @@ public class FileSystemUtilsTestCase ext
try {
fsu.freeSpaceUnix("/home/users/s", false, false, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
try {
fsu.freeSpaceUnix("/home/users/s", true, false, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
try {
fsu.freeSpaceUnix("/home/users/s", false, true, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
try {
fsu.freeSpaceUnix("/home/users/s", true, true, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
}
+ @Test
public void testGetFreeSpaceUnix_String_InvalidResponse4() throws Exception {
final String lines =
"Filesystem 1K-blocks Used Available Use% Mounted on\n" +
@@ -498,22 +508,22 @@ public class FileSystemUtilsTestCase ext
try {
fsu.freeSpaceUnix("/home/users/s", false, false, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
try {
fsu.freeSpaceUnix("/home/users/s", true, false, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
try {
fsu.freeSpaceUnix("/home/users/s", false, true, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
try {
fsu.freeSpaceUnix("/home/users/s", true, true, -1);
fail();
- } catch (final IOException ex) {
+ } catch (final IOException ignore) {
}
}
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsCleanDirectoryTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsCleanDirectoryTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsCleanDirectoryTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsCleanDirectoryTestCase.java Wed Dec 9 19:50:30 2015
@@ -22,6 +22,13 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.testtools.FileBasedTestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* Test cases for FileUtils.cleanDirectory() method.
@@ -31,10 +38,6 @@ import org.apache.commons.io.testtools.F
public class FileUtilsCleanDirectoryTestCase extends FileBasedTestCase {
final File top = getLocalTestDirectory();
- public FileUtilsCleanDirectoryTestCase(final String name) {
- super(name);
- }
-
private File getLocalTestDirectory() {
return new File(getTestDirectory(), "list-files");
}
@@ -42,21 +45,22 @@ public class FileUtilsCleanDirectoryTest
/**
* @see junit.framework.TestCase#setUp()
*/
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
top.mkdirs();
}
/**
* @see junit.framework.TestCase#tearDown()
*/
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
chmod(top, 775, true);
FileUtils.deleteDirectory(top);
}
//-----------------------------------------------------------------------
+ @Test
public void testCleanEmpty() throws Exception {
assertEquals(0, top.list().length);
@@ -65,6 +69,7 @@ public class FileUtilsCleanDirectoryTest
assertEquals(0, top.list().length);
}
+ @Test
public void testDeletesRegular() throws Exception {
FileUtils.touch(new File(top, "regular"));
FileUtils.touch(new File(top, ".hidden"));
@@ -76,6 +81,7 @@ public class FileUtilsCleanDirectoryTest
assertEquals(0, top.list().length);
}
+ @Test
public void testDeletesNested() throws Exception {
final File nested = new File(top, "nested");
@@ -90,6 +96,7 @@ public class FileUtilsCleanDirectoryTest
assertEquals(0, top.list().length);
}
+ @Test
public void testThrowsOnNullList() throws Exception {
if (System.getProperty("os.name").startsWith("Win") || !chmod(top, 0, false)) {
// test wont work if we can't restrict permissions on the
@@ -106,6 +113,7 @@ public class FileUtilsCleanDirectoryTest
}
}
+ @Test
public void testThrowsOnCannotDeleteFile() throws Exception {
final File file = new File(top, "restricted");
FileUtils.touch(file);
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsCleanSymlinksTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsCleanSymlinksTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsCleanSymlinksTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsCleanSymlinksTestCase.java Wed Dec 9 19:50:30 2015
@@ -21,6 +21,13 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.testtools.FileBasedTestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
/**
* Test cases for FileUtils.cleanDirectory() method that involve symlinks.
@@ -30,20 +37,17 @@ public class FileUtilsCleanSymlinksTestC
final File top = getTestDirectory();
- public FileUtilsCleanSymlinksTestCase(final String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
top.mkdirs();
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
FileUtils.deleteDirectory(top);
}
+ @Test
public void testCleanDirWithSymlinkFile() throws Exception {
if (System.getProperty("os.name").startsWith("Win")) {
// cant create symlinks in windows.
@@ -78,6 +82,7 @@ public class FileUtilsCleanSymlinksTestC
}
+ @Test
public void testCleanDirWithASymlinkDir() throws Exception {
if (System.getProperty("os.name").startsWith("Win")) {
// cant create symlinks in windows.
@@ -112,6 +117,7 @@ public class FileUtilsCleanSymlinksTestC
assertEquals("Contents of sym link should not have been removed", 1, randomDirectory.list().length);
}
+ @Test
public void testCleanDirWithParentSymlinks() throws Exception {
if (System.getProperty("os.name").startsWith("Win")) {
// cant create symlinks in windows.
@@ -150,6 +156,7 @@ public class FileUtilsCleanSymlinksTestC
assertEquals("Contents of sym link should not have been removed", 1, randomDirectory.list().length);
}
+ @Test
public void testStillClearsIfGivenDirectoryIsASymlink() throws Exception {
if (System.getProperty("os.name").startsWith("Win")) {
// cant create symlinks in windows.
@@ -171,6 +178,7 @@ public class FileUtilsCleanSymlinksTestC
}
+ @Test
public void testIdentifiesSymlinkDir() throws Exception {
if (System.getProperty("os.name").startsWith("Win")) {
// cant create symlinks in windows.
@@ -187,6 +195,7 @@ public class FileUtilsCleanSymlinksTestC
assertFalse(FileUtils.isSymlink(randomDirectory));
}
+ @Test
public void testIdentifiesSymlinkFile() throws Exception {
if (System.getProperty("os.name").startsWith("Win")) {
// cant create symlinks in windows.
@@ -203,6 +212,7 @@ public class FileUtilsCleanSymlinksTestC
assertFalse(FileUtils.isSymlink(randomFile));
}
+ @Test
public void testIdentifiesBrokenSymlinkFile() throws Exception {
if (System.getProperty("os.name").startsWith("Win")) {
// cant create symlinks in windows.
@@ -222,6 +232,7 @@ public class FileUtilsCleanSymlinksTestC
assertFalse(FileUtils.isSymlink(badSymlinkInPathFile));
}
+ @Test
public void testCorrectlyIdentifySymlinkWithParentSymLink() throws Exception {
if (System.getProperty("os.name").startsWith("Win")) {
// cant create symlinks in windows.
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsDirectoryContainsTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsDirectoryContainsTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsDirectoryContainsTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsDirectoryContainsTestCase.java Wed Dec 9 19:50:30 2015
@@ -20,8 +20,14 @@ import java.io.File;
import java.io.IOException;
import org.apache.commons.io.testtools.FileBasedTestCase;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
/**
* This class ensure the correctness of {@link FileUtils#directoryContains(File,File)}.
*
@@ -41,12 +47,9 @@ public class FileUtilsDirectoryContainsT
private File file3;
final File top = getTestDirectory();
- public FileUtilsDirectoryContainsTestCase(final String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
+ @SuppressWarnings("ResultOfMethodCallIgnored")
+ @Before
+ public void setUp() throws Exception {
top.mkdirs();
directory1 = new File(top, "directory1");
@@ -70,8 +73,8 @@ public class FileUtilsDirectoryContainsT
FileUtils.touch(file3);
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
FileUtils.deleteDirectory(top);
}
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsFileNewerTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsFileNewerTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsFileNewerTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsFileNewerTestCase.java Wed Dec 9 19:50:30 2015
@@ -16,10 +16,20 @@
*/
package org.apache.commons.io;
+import java.io.BufferedOutputStream;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.util.Date;
import org.apache.commons.io.testtools.FileBasedTestCase;
+import org.apache.commons.io.testtools.TestUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* This is used to test FileUtils for correctness.
@@ -33,24 +43,42 @@ public class FileUtilsFileNewerTestCase
private final File m_testFile1;
private final File m_testFile2;
- public FileUtilsFileNewerTestCase(final String name) {
- super(name);
-
+ public FileUtilsFileNewerTestCase() {
m_testFile1 = new File(getTestDirectory(), "file1-test.txt");
m_testFile2 = new File(getTestDirectory(), "file2-test.txt");
}
/** @see junit.framework.TestCase#setUp() */
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
getTestDirectory().mkdirs();
- createFile(m_testFile1, FILE1_SIZE);
- createFile(m_testFile2, FILE2_SIZE);
+ if (!m_testFile1.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + m_testFile1
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output1 =
+ new BufferedOutputStream(new FileOutputStream(m_testFile1));
+ try {
+ TestUtils.generateTestData(output1, (long) FILE1_SIZE);
+ } finally {
+ IOUtils.closeQuietly(output1);
+ }
+ if (!m_testFile2.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + m_testFile2
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(m_testFile2));
+ try {
+ TestUtils.generateTestData(output, (long) FILE2_SIZE);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
}
/** @see junit.framework.TestCase#tearDown() */
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
m_testFile1.delete();
m_testFile2.delete();
}
@@ -62,6 +90,7 @@ public class FileUtilsFileNewerTestCase
* @see FileUtils#isFileNewer(File, Date)
* @see FileUtils#isFileNewer(File, File)
*/
+ @Test
public void testIsFileNewer() {
if (!m_testFile1.exists()) {
throw new IllegalStateException("The m_testFile1 should exist");
@@ -82,6 +111,7 @@ public class FileUtilsFileNewerTestCase
* @see FileUtils#isFileNewer(File, Date)
* @see FileUtils#isFileNewer(File, File)
*/
+ @Test
public void testIsFileNewerImaginaryFile() {
final File imaginaryFile = new File(getTestDirectory(), "imaginaryFile");
if (imaginaryFile.exists()) {
@@ -130,11 +160,10 @@ public class FileUtilsFileNewerTestCase
* <br>
* The test is successfull if the method throws an <code>IllegalArgumentException</code>.
*/
+ @Test(expected = IllegalArgumentException.class)
public void testIsFileNewerNoFile() {
- try {
- FileUtils.isFileNewer(null,0);
- fail("File not specified");
- } catch (final IllegalArgumentException e) {}
+ FileUtils.isFileNewer(null,0);
+ fail("File not specified");
}
/**
@@ -142,11 +171,10 @@ public class FileUtilsFileNewerTestCase
* <br>
* The test is successfull if the method throws an <code>IllegalArgumentException</code>.
*/
+ @Test(expected = IllegalArgumentException.class)
public void testIsFileNewerNoDate() {
- try {
- FileUtils.isFileNewer(m_testFile1, (Date) null);
- fail("Date not specified");
- } catch (final IllegalArgumentException e) {}
+ FileUtils.isFileNewer(m_testFile1, (Date) null);
+ fail("Date not specified");
}
/**
@@ -154,10 +182,9 @@ public class FileUtilsFileNewerTestCase
* <br>
* The test is successfull if the method throws an <code>IllegalArgumentException</code>.
*/
+ @Test(expected = IllegalArgumentException.class)
public void testIsFileNewerNoFileReference() {
- try {
- FileUtils.isFileNewer(m_testFile1, (File) null);
- fail("Reference file not specified");
- } catch (final IllegalArgumentException e) {}
+ FileUtils.isFileNewer(m_testFile1, (File) null);
+ fail("Reference file not specified");
}
}
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsListFilesTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsListFilesTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsListFilesTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsListFilesTestCase.java Wed Dec 9 19:50:30 2015
@@ -16,24 +16,28 @@
*/
package org.apache.commons.io;
+import org.apache.commons.io.filefilter.FileFilterUtils;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.testtools.FileBasedTestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
-import org.apache.commons.io.filefilter.FileFilterUtils;
-import org.apache.commons.io.filefilter.IOFileFilter;
-import org.apache.commons.io.testtools.FileBasedTestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* Test cases for FileUtils.listFiles() methods.
*/
public class FileUtilsListFilesTestCase extends FileBasedTestCase {
- public FileUtilsListFilesTestCase(final String name) {
- super(name);
- }
-
private File getLocalTestDirectory() {
return new File(getTestDirectory(), "list-files");
}
@@ -41,8 +45,9 @@ public class FileUtilsListFilesTestCase
/**
* @see junit.framework.TestCase#setUp()
*/
- @Override
- protected void setUp() throws Exception {
+ @SuppressWarnings("ResultOfMethodCallIgnored")
+ @Before
+ public void setUp() throws Exception {
File dir = getLocalTestDirectory();
if (dir.exists()) {
FileUtils.deleteDirectory(dir);
@@ -79,8 +84,8 @@ public class FileUtilsListFilesTestCase
/**
* @see junit.framework.TestCase#tearDown()
*/
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
final File dir = getLocalTestDirectory();
FileUtils.deleteDirectory(dir);
}
@@ -101,6 +106,7 @@ public class FileUtilsListFilesTestCase
return filenames;
}
+ @Test
public void testIterateFilesByExtension() throws Exception {
final String[] extensions = { "xml", "txt" };
@@ -125,6 +131,7 @@ public class FileUtilsListFilesTestCase
assertFalse(filenames.contains("dummy-file.txt"));
}
+ @Test
public void testListFilesByExtension() throws Exception {
final String[] extensions = {"xml", "txt"};
@@ -149,6 +156,7 @@ public class FileUtilsListFilesTestCase
assertFalse(filenames.contains("dummy-file.txt"));
}
+ @Test
public void testListFiles() throws Exception {
Collection<File> files;
Collection<String> filenames;