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 [5/6] - in
/commons/proper/io/trunk/src/test/java/org/apache/commons/io: ./
comparator/ filefilter/ input/ monitor/ output/ testtools/
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/comparator/SizeFileComparatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/comparator/SizeFileComparatorTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/comparator/SizeFileComparatorTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/comparator/SizeFileComparatorTest.java Wed Dec 9 19:50:30 2015
@@ -16,7 +16,19 @@
*/
package org.apache.commons.io.comparator;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.testtools.TestUtils;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.BufferedOutputStream;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
/**
* Test case for {@link SizeFileComparator}.
@@ -28,19 +40,9 @@ public class SizeFileComparatorTest exte
private File smallerFile;
private File largerFile;
- /**
- * Construct a new test case with the specified name.
- *
- * @param name Name of the test
- */
- public SizeFileComparatorTest(final String name) {
- super(name);
- }
-
/** @see junit.framework.TestCase#setUp() */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
comparator = (AbstractFileComparator) SizeFileComparator.SIZE_COMPARATOR;
reverse = SizeFileComparator.SIZE_REVERSE;
final File dir = getTestDirectory();
@@ -51,9 +53,39 @@ public class SizeFileComparatorTest exte
largerFile = new File(largerDir, "larger.txt");
smallerDir.mkdir();
largerDir.mkdir();
- createFile(smallerFile, 32);
- createFile(equalFile, 48);
- createFile(largerFile, 64);
+ if (!smallerFile.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + smallerFile
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output2 =
+ new BufferedOutputStream(new FileOutputStream(smallerFile));
+ try {
+ TestUtils.generateTestData(output2, (long) 32);
+ } finally {
+ IOUtils.closeQuietly(output2);
+ }
+ if (!equalFile.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + equalFile
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output1 =
+ new BufferedOutputStream(new FileOutputStream(equalFile));
+ try {
+ TestUtils.generateTestData(output1, (long) 48);
+ } finally {
+ IOUtils.closeQuietly(output1);
+ }
+ if (!largerFile.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + largerFile
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(largerFile));
+ try {
+ TestUtils.generateTestData(output, (long) 64);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
equalFile1 = equalFile;
equalFile2 = equalFile;
lessFile = smallerFile;
@@ -63,6 +95,7 @@ public class SizeFileComparatorTest exte
/**
* Test a file which doesn't exist.
*/
+ @Test
public void testNonexistantFile() {
final File nonexistantFile = new File(new File("."), "nonexistant.txt");
assertFalse(nonexistantFile.exists());
@@ -72,6 +105,7 @@ public class SizeFileComparatorTest exte
/**
* Test a file which doesn't exist.
*/
+ @Test
public void testCompareDirectorySizes() {
assertEquals("sumDirectoryContents=false", 0, comparator.compare(smallerDir, largerDir));
assertEquals("less", -1, SizeFileComparator.SIZE_SUMDIR_COMPARATOR.compare(smallerDir, largerDir));
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/AndFileFilterTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/AndFileFilterTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/AndFileFilterTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/AndFileFilterTestCase.java Wed Dec 9 19:50:30 2015
@@ -16,6 +16,8 @@
*/
package org.apache.commons.io.filefilter;
+import org.junit.Before;
+
import java.util.ArrayList;
import java.util.List;
@@ -30,16 +32,6 @@ public class AndFileFilterTestCase exten
private List<Boolean> testFileResults;
private List<Boolean> testFilenameResults;
- public AndFileFilterTestCase(final String name) {
- super(name);
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- this.setUpTestFilters();
- }
-
@Override
protected IOFileFilter buildFilterUsingAdd(final List<IOFileFilter> filters) {
final AndFileFilter filter = new AndFileFilter();
@@ -94,7 +86,8 @@ public class AndFileFilterTestCase exten
return WORKING_PATH_NAME_PROPERTY_KEY;
}
- private void setUpTestFilters() {
+ @Before
+ public void setUpTestFilters() {
// filters
//tests
this.testFilters = new ArrayList<List<IOFileFilter>>();
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/ConditionalFileFilterAbstractTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/ConditionalFileFilterAbstractTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/ConditionalFileFilterAbstractTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/ConditionalFileFilterAbstractTestCase.java Wed Dec 9 19:50:30 2015
@@ -16,10 +16,16 @@
*/
package org.apache.commons.io.filefilter;
+import org.junit.Before;
+import org.junit.Test;
+
import java.io.File;
import java.util.ArrayList;
import java.util.List;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
public abstract class ConditionalFileFilterAbstractTestCase extends IOFileFilterAbstractTestCase {
private static final String TEST_FILE_NAME_PREFIX = "TestFile";
@@ -31,11 +37,7 @@ public abstract class ConditionalFileFil
private File file;
private File workingPath;
- public ConditionalFileFilterAbstractTestCase(final String name) {
- super(name);
- }
-
- @Override
+ @Before
public void setUp() throws Exception {
this.workingPath = determineWorkingDirectoryPath(this.getWorkingPathNamePropertyKey(), this.getDefaultWorkingPath());
this.file = new File(this.workingPath, TEST_FILE_NAME_PREFIX + 1 + TEST_FILE_TYPE);
@@ -49,6 +51,7 @@ public abstract class ConditionalFileFil
this.falseFilters[3] = new TesterFalseFileFilter();
}
+ @Test
public void testAdd() {
final List<TesterTrueFileFilter> filters = new ArrayList<TesterTrueFileFilter>();
final ConditionalFileFilter fileFilter = this.getConditionalFileFilter();
@@ -67,6 +70,7 @@ public abstract class ConditionalFileFil
assertEquals("file filters count", filters.size(), fileFilter.getFileFilters().size());
}
+ @Test
public void testRemove() {
final List<TesterTrueFileFilter> filters = new ArrayList<TesterTrueFileFilter>();
final ConditionalFileFilter fileFilter = this.getConditionalFileFilter();
@@ -81,6 +85,7 @@ public abstract class ConditionalFileFil
assertEquals("file filters count", 0, fileFilter.getFileFilters().size());
}
+ @Test
public void testNoFilters() throws Exception {
final ConditionalFileFilter fileFilter = this.getConditionalFileFilter();
final File file = new File(this.workingPath, TEST_FILE_NAME_PREFIX + 1 + TEST_FILE_TYPE);
@@ -88,6 +93,7 @@ public abstract class ConditionalFileFil
assertFilenameFiltering(1, (IOFileFilter) fileFilter, file, false);
}
+ @Test
public void testFilterBuiltUsingConstructor() throws Exception {
final List<List<IOFileFilter>> testFilters = this.getTestFilters();
final List<boolean[]> testTrueResults = this.getTrueResults();
@@ -121,6 +127,7 @@ public abstract class ConditionalFileFil
}
}
+ @Test
public void testFilterBuiltUsingAdd() throws Exception {
final List<List<IOFileFilter>> testFilters = this.getTestFilters();
final List<boolean[]> testTrueResults = this.getTrueResults();
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/FileFilterTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/FileFilterTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/FileFilterTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/FileFilterTestCase.java Wed Dec 9 19:50:30 2015
@@ -16,23 +16,25 @@
*/
package org.apache.commons.io.filefilter;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FilenameFilter;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
import org.apache.commons.io.Charsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOCase;
import org.apache.commons.io.IOUtils;
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.util.*;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* Used to test FileFilterUtils.
@@ -46,16 +48,12 @@ public class FileFilterTestCase extends
private static final boolean WINDOWS = File.separatorChar == '\\';
- public FileFilterTestCase(final String name) {
- super(name);
- }
-
- @Override
+ @Before
public void setUp() {
- getTestDirectory().mkdirs();
+ getTestDirectory();
}
- @Override
+ @After
public void tearDown() throws Exception {
FileUtils.deleteDirectory(getTestDirectory());
}
@@ -79,6 +77,9 @@ public class FileFilterTestCase extends
assertNotNull(filter.toString());
}
+
+
+ @Test
public void testSuffix() throws Exception {
IOFileFilter filter = new SuffixFileFilter(new String[] { "tes", "est" });
final File testFile = new File( "test" );
@@ -111,22 +112,23 @@ public class FileFilterTestCase extends
try {
new SuffixFileFilter((String) null);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
try {
new SuffixFileFilter((String[]) null);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
try {
new SuffixFileFilter((List<String>) null);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
}
+ @Test
public void testSuffixCaseInsensitive() throws Exception {
IOFileFilter filter = new SuffixFileFilter(new String[] { "tes", "est" }, IOCase.INSENSITIVE);
@@ -151,19 +153,19 @@ public class FileFilterTestCase extends
try {
new SuffixFileFilter((String) null, IOCase.INSENSITIVE);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
try {
new SuffixFileFilter((String[]) null, IOCase.INSENSITIVE);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
try {
new SuffixFileFilter((List<String>) null, IOCase.INSENSITIVE);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
// FileFilterUtils.suffixFileFilter(String, IOCase) tests
@@ -178,6 +180,7 @@ public class FileFilterTestCase extends
}
}
+ @Test
public void testDirectory() throws Exception {
// XXX: This test presumes the current working dir is the base dir of the source checkout.
final IOFileFilter filter = new DirectoryFileFilter();
@@ -195,6 +198,7 @@ public class FileFilterTestCase extends
assertSame(DirectoryFileFilter.DIRECTORY, DirectoryFileFilter.INSTANCE);
}
+ @Test
public void testFiles() throws Exception {
// XXX: This test presumes the current working dir is the base dir of the source checkout.
final IOFileFilter filter = FileFileFilter.FILE;
@@ -210,6 +214,7 @@ public class FileFilterTestCase extends
assertFiltering(filter, new File("LICENSE.txt"), true);
}
+ @Test
public void testPrefix() throws Exception {
IOFileFilter filter = new PrefixFileFilter(new String[] { "foo", "bar" });
final File testFile = new File( "test" );
@@ -244,22 +249,23 @@ public class FileFilterTestCase extends
try {
new PrefixFileFilter((String) null);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
try {
new PrefixFileFilter((String[]) null);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
try {
new PrefixFileFilter((List<String>) null);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
}
+ @Test
public void testPrefixCaseInsensitive() throws Exception {
IOFileFilter filter = new PrefixFileFilter(new String[] { "foo", "bar" }, IOCase.INSENSITIVE);
@@ -284,19 +290,19 @@ public class FileFilterTestCase extends
try {
new PrefixFileFilter((String) null, IOCase.INSENSITIVE);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
try {
new PrefixFileFilter((String[]) null, IOCase.INSENSITIVE);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
try {
new PrefixFileFilter((List<String>) null, IOCase.INSENSITIVE);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
// FileFilterUtils.prefixFileFilter(String, IOCase) tests
@@ -309,10 +315,11 @@ public class FileFilterTestCase extends
try {
FileFilterUtils.prefixFileFilter(null, IOCase.INSENSITIVE);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
}
+ @Test
public void testNameFilter() throws Exception {
IOFileFilter filter = new NameFileFilter(new String[] { "foo", "bar" });
assertFiltering(filter, new File("foo"), true);
@@ -368,39 +375,36 @@ public class FileFilterTestCase extends
assertFiltering(filter, new File("fred"), false);
}
+ @Test
public void testNameFilterNullArgument() throws Exception {
final String test = null;
try {
new NameFileFilter(test);
fail( "constructing a NameFileFilter with a null String argument should fail.");
- } catch( final IllegalArgumentException iae ) {
+ } catch( final IllegalArgumentException ignore ) {
}
try {
FileFilterUtils.nameFileFilter(test, IOCase.INSENSITIVE);
fail( "constructing a NameFileFilter with a null String argument should fail.");
- } catch( final IllegalArgumentException iae ) {
+ } catch( final IllegalArgumentException ignore ) {
}
}
+ @Test(expected = IllegalArgumentException.class)
public void testNameFilterNullArrayArgument() throws Exception {
- final String[] test = null;
- try {
- new NameFileFilter(test);
- fail( "constructing a NameFileFilter with a null String[] argument should fail.");
- } catch( final IllegalArgumentException iae ) {
- }
+ new NameFileFilter((String[]) null);
+ fail( "constructing a NameFileFilter with a null String[] argument should fail.");
}
+ @Test(expected = IllegalArgumentException.class)
public void testNameFilterNullListArgument() throws Exception {
final List<String> test = null;
- try {
- new NameFileFilter(test);
- fail( "constructing a NameFileFilter with a null List argument should fail.");
- } catch( final IllegalArgumentException iae ) {
- }
+ new NameFileFilter(test);
+ fail("constructing a NameFileFilter with a null List argument should fail.");
}
+ @Test
public void testTrue() throws Exception {
final IOFileFilter filter = FileFilterUtils.trueFileFilter();
assertFiltering(filter, new File("foo.test"), true);
@@ -409,6 +413,7 @@ public class FileFilterTestCase extends
assertSame(TrueFileFilter.TRUE, TrueFileFilter.INSTANCE);
}
+ @Test
public void testFalse() throws Exception {
final IOFileFilter filter = FileFilterUtils.falseFileFilter();
assertFiltering(filter, new File("foo.test"), false);
@@ -417,18 +422,16 @@ public class FileFilterTestCase extends
assertSame(FalseFileFilter.FALSE, FalseFileFilter.INSTANCE);
}
+ @Test(expected = IllegalArgumentException.class)
public void testNot() throws Exception {
final IOFileFilter filter = FileFilterUtils.notFileFilter(FileFilterUtils.trueFileFilter());
assertFiltering(filter, new File("foo.test"), false);
assertFiltering(filter, new File("foo"), false);
assertFiltering(filter, null, false);
- try {
- new NotFileFilter(null);
- fail();
- } catch (final IllegalArgumentException ex) {
- }
+ new NotFileFilter(null);
}
+ @Test
public void testAnd() throws Exception {
final IOFileFilter trueFilter = TrueFileFilter.INSTANCE;
final IOFileFilter falseFilter = FalseFileFilter.INSTANCE;
@@ -444,13 +447,13 @@ public class FileFilterTestCase extends
try {
new AndFileFilter(falseFilter, null);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
try {
new AndFileFilter(null, falseFilter);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
}
final AndFileFilter f = new AndFileFilter(null);
@@ -459,6 +462,7 @@ public class FileFilterTestCase extends
assertNotNull(f.toString()); // TODO better tests
}
+ @Test
public void testOr() throws Exception {
final IOFileFilter trueFilter = TrueFileFilter.INSTANCE;
final IOFileFilter falseFilter = FalseFileFilter.INSTANCE;
@@ -495,6 +499,8 @@ public class FileFilterTestCase extends
final OrFileFilter f = new OrFileFilter(null);
assertTrue(f.getFileFilters().isEmpty());
}
+
+ @Test
public void testFileFilterUtils_and() throws Exception {
final IOFileFilter trueFilter = TrueFileFilter.INSTANCE;
final IOFileFilter falseFilter = FalseFileFilter.INSTANCE;
@@ -504,6 +510,7 @@ public class FileFilterTestCase extends
assertFiltering(FileFilterUtils.and(falseFilter, falseFilter), new File("foo.test"), false);
}
+ @Test
public void testFileFilterUtils_or() throws Exception {
final IOFileFilter trueFilter = TrueFileFilter.INSTANCE;
final IOFileFilter falseFilter = FalseFileFilter.INSTANCE;
@@ -515,6 +522,7 @@ public class FileFilterTestCase extends
}
@SuppressWarnings("deprecation")
+ @Test
public void testDeprecatedWildcard() throws Exception {
IOFileFilter filter = new WildcardFilter("*.txt");
final List<String> patternList = Arrays.asList("*.txt", "*.xml", "*.gif");
@@ -576,6 +584,7 @@ public class FileFilterTestCase extends
}
}
+ @Test
public void testWildcard() throws Exception {
IOFileFilter filter = new WildcardFileFilter("*.txt");
assertFiltering(filter, new File("log.txt"), true);
@@ -639,17 +648,18 @@ public class FileFilterTestCase extends
try {
new WildcardFileFilter((String) null);
fail();
- } catch (final IllegalArgumentException ex) {}
+ } catch (final IllegalArgumentException ignore) {}
try {
new WildcardFileFilter((String[]) null);
fail();
- } catch (final IllegalArgumentException ex) {}
+ } catch (final IllegalArgumentException ignore) {}
try {
new WildcardFileFilter((List<String>) null);
fail();
- } catch (final IllegalArgumentException ex) {}
+ } catch (final IllegalArgumentException ignore) {}
}
+ @Test
public void testDelegateFileFilter() throws Exception {
final OrFileFilter orFilter = new OrFileFilter();
final File testFile = new File( "test.txt" );
@@ -665,17 +675,18 @@ public class FileFilterTestCase extends
try {
new DelegateFileFilter((FileFilter) null);
fail();
- } catch( final IllegalArgumentException iae ) {
+ } catch( final IllegalArgumentException ignore ) {
}
try {
new DelegateFileFilter((FilenameFilter) null);
fail();
- } catch( final IllegalArgumentException iae ) {
+ } catch( final IllegalArgumentException ignore ) {
}
}
+ @Test
public void testMakeCVSAware() throws Exception {
final IOFileFilter filter1 = FileFilterUtils.makeCVSAware(null);
final IOFileFilter filter2 = FileFilterUtils.makeCVSAware(FileFilterUtils
@@ -688,21 +699,52 @@ public class FileFilterTestCase extends
FileUtils.deleteDirectory(file);
file = new File(getTestDirectory(), "test-file1.txt");
- createFile(file, 0);
+ if (!file.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + file
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output2 =
+ new BufferedOutputStream(new FileOutputStream(file));
+ try {
+ TestUtils.generateTestData(output2, (long) 0);
+ } finally {
+ IOUtils.closeQuietly(output2);
+ }
assertFiltering(filter1, file, true);
assertFiltering(filter2, file, true);
file = new File(getTestDirectory(), "test-file2.log");
- createFile(file, 0);
+ if (!file.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + file
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output1 =
+ new BufferedOutputStream(new FileOutputStream(file));
+ try {
+ TestUtils.generateTestData(output1, (long) 0);
+ } finally {
+ IOUtils.closeQuietly(output1);
+ }
assertFiltering(filter1, file, true);
assertFiltering(filter2, file, false);
file = new File(getTestDirectory(), "CVS");
- createFile(file, 0);
+ if (!file.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + file
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(file));
+ try {
+ TestUtils.generateTestData(output, (long) 0);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
assertFiltering(filter1, file, true);
assertFiltering(filter2, file, false);
}
+ @Test
public void testMakeSVNAware() throws Exception {
final IOFileFilter filter1 = FileFilterUtils.makeSVNAware(null);
final IOFileFilter filter2 = FileFilterUtils.makeSVNAware(FileFilterUtils
@@ -715,27 +757,68 @@ public class FileFilterTestCase extends
FileUtils.deleteDirectory(file);
file = new File(getTestDirectory(), "test-file1.txt");
- createFile(file, 0);
+ if (!file.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + file
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output2 =
+ new BufferedOutputStream(new FileOutputStream(file));
+ try {
+ TestUtils.generateTestData(output2, (long) 0);
+ } finally {
+ IOUtils.closeQuietly(output2);
+ }
assertFiltering(filter1, file, true);
assertFiltering(filter2, file, true);
file = new File(getTestDirectory(), "test-file2.log");
- createFile(file, 0);
+ if (!file.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + file
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output1 =
+ new BufferedOutputStream(new FileOutputStream(file));
+ try {
+ TestUtils.generateTestData(output1, (long) 0);
+ } finally {
+ IOUtils.closeQuietly(output1);
+ }
assertFiltering(filter1, file, true);
assertFiltering(filter2, file, false);
file = new File(getTestDirectory(), SVN_DIR_NAME);
- createFile(file, 0);
+ if (!file.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + file
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(file));
+ try {
+ TestUtils.generateTestData(output, (long) 0);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
assertFiltering(filter1, file, true);
assertFiltering(filter2, file, false);
}
+ @Test
public void testAgeFilter() throws Exception {
final File oldFile = new File(getTestDirectory(), "old.txt");
final File reference = new File(getTestDirectory(), "reference.txt");
final File newFile = new File(getTestDirectory(), "new.txt");
- createFile(oldFile, 0);
+ if (!oldFile.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + oldFile
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output1 =
+ new BufferedOutputStream(new FileOutputStream(oldFile));
+ try {
+ TestUtils.generateTestData(output1, (long) 0);
+ } finally {
+ IOUtils.closeQuietly(output1);
+ }
do {
try {
@@ -743,7 +826,17 @@ public class FileFilterTestCase extends
} catch(final InterruptedException ie) {
// ignore
}
- createFile(reference, 0);
+ if (!reference.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + reference
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(reference));
+ try {
+ TestUtils.generateTestData(output, (long) 0);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
} while( oldFile.lastModified() == reference.lastModified() );
final Date date = new Date();
@@ -755,7 +848,17 @@ public class FileFilterTestCase extends
} catch(final InterruptedException ie) {
// ignore
}
- createFile(newFile, 0);
+ if (!newFile.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + newFile
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(newFile));
+ try {
+ TestUtils.generateTestData(output, (long) 0);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
} while( reference.lastModified() == newFile.lastModified() );
final IOFileFilter filter1 = FileFilterUtils.ageFileFilter(now);
@@ -788,11 +891,32 @@ public class FileFilterTestCase extends
assertFiltering(filter9, newFile, true);
}
+ @Test
public void testSizeFilter() throws Exception {
final File smallFile = new File(getTestDirectory(), "small.txt");
- createFile(smallFile, 32);
+ if (!smallFile.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + smallFile
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output1 =
+ new BufferedOutputStream(new FileOutputStream(smallFile));
+ try {
+ TestUtils.generateTestData(output1, (long) 32);
+ } finally {
+ IOUtils.closeQuietly(output1);
+ }
final File largeFile = new File(getTestDirectory(), "large.txt");
- createFile(largeFile, 128);
+ if (!largeFile.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + largeFile
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(largeFile));
+ try {
+ TestUtils.generateTestData(output, (long) 128);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
final IOFileFilter filter1 = FileFilterUtils.sizeFileFilter(64);
final IOFileFilter filter2 = FileFilterUtils.sizeFileFilter(64, true);
final IOFileFilter filter3 = FileFilterUtils.sizeFileFilter(64, false);
@@ -829,6 +953,7 @@ public class FileFilterTestCase extends
}
}
+ @Test
public void testHidden() throws Exception {
final File hiddenDir = new File(SVN_DIR_NAME);
if (hiddenDir.exists()) {
@@ -839,9 +964,20 @@ public class FileFilterTestCase extends
assertFiltering(HiddenFileFilter.VISIBLE, getTestDirectory(), true);
}
+ @Test
public void testCanRead() throws Exception {
final File readOnlyFile = new File(getTestDirectory(), "read-only-file1.txt");
- createFile(readOnlyFile, 32);
+ if (!readOnlyFile.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + readOnlyFile
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(readOnlyFile));
+ try {
+ TestUtils.generateTestData(output, (long) 32);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
readOnlyFile.setReadOnly();
assertFiltering(CanReadFileFilter.CAN_READ, readOnlyFile, true);
assertFiltering(CanReadFileFilter.CANNOT_READ, readOnlyFile, false);
@@ -849,9 +985,20 @@ public class FileFilterTestCase extends
readOnlyFile.delete();
}
+ @Test
public void testCanWrite() throws Exception {
final File readOnlyFile = new File(getTestDirectory(), "read-only-file2.txt");
- createFile(readOnlyFile, 32);
+ if (!readOnlyFile.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + readOnlyFile
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(readOnlyFile));
+ try {
+ TestUtils.generateTestData(output, (long) 32);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
readOnlyFile.setReadOnly();
assertFiltering(CanWriteFileFilter.CAN_WRITE, getTestDirectory(), true);
assertFiltering(CanWriteFileFilter.CANNOT_WRITE, getTestDirectory(), false);
@@ -860,6 +1007,7 @@ public class FileFilterTestCase extends
readOnlyFile.delete();
}
+ @Test
public void testEmpty() throws Exception {
// Empty Dir
@@ -870,7 +1018,17 @@ public class FileFilterTestCase extends
// Empty File
final File emptyFile = new File(emptyDir, "empty-file.txt");
- createFile(emptyFile, 0);
+ if (!emptyFile.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + emptyFile
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output1 =
+ new BufferedOutputStream(new FileOutputStream(emptyFile));
+ try {
+ TestUtils.generateTestData(output1, (long) 0);
+ } finally {
+ IOUtils.closeQuietly(output1);
+ }
assertFiltering(EmptyFileFilter.EMPTY, emptyFile, true);
assertFiltering(EmptyFileFilter.NOT_EMPTY, emptyFile, false);
@@ -880,13 +1038,24 @@ public class FileFilterTestCase extends
// Not Empty File
final File notEmptyFile = new File(emptyDir, "not-empty-file.txt");
- createFile(notEmptyFile, 32);
+ if (!notEmptyFile.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + notEmptyFile
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(notEmptyFile));
+ try {
+ TestUtils.generateTestData(output, (long) 32);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
assertFiltering(EmptyFileFilter.EMPTY, notEmptyFile, false);
assertFiltering(EmptyFileFilter.NOT_EMPTY, notEmptyFile, true);
FileUtils.forceDelete(emptyDir);
}
//-----------------------------------------------------------------------
+ @Test
public void testMakeDirectoryOnly() throws Exception {
assertSame(DirectoryFileFilter.DIRECTORY, FileFilterUtils.makeDirectoryOnly(null));
@@ -905,8 +1074,28 @@ public class FileFilterTestCase extends
FileUtils.deleteDirectory(fileA);
FileUtils.deleteDirectory(fileB);
- createFile(fileA, 32);
- createFile(fileB, 32);
+ if (!fileA.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + fileA
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output1 =
+ new BufferedOutputStream(new FileOutputStream(fileA));
+ try {
+ TestUtils.generateTestData(output1, (long) 32);
+ } finally {
+ IOUtils.closeQuietly(output1);
+ }
+ if (!fileB.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + fileB
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(fileB));
+ try {
+ TestUtils.generateTestData(output, (long) 32);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
assertFiltering(filter, fileA, false);
assertFiltering(filter, fileB, false);
@@ -916,6 +1105,7 @@ public class FileFilterTestCase extends
}
//-----------------------------------------------------------------------
+ @Test
public void testMakeFileOnly() throws Exception {
assertSame(FileFileFilter.FILE, FileFilterUtils.makeFileOnly(null));
@@ -934,8 +1124,28 @@ public class FileFilterTestCase extends
FileUtils.deleteDirectory(fileA);
FileUtils.deleteDirectory(fileB);
- createFile(fileA, 32);
- createFile(fileB, 32);
+ if (!fileA.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + fileA
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output1 =
+ new BufferedOutputStream(new FileOutputStream(fileA));
+ try {
+ TestUtils.generateTestData(output1, (long) 32);
+ } finally {
+ IOUtils.closeQuietly(output1);
+ }
+ if (!fileB.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + fileB
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(fileB));
+ try {
+ TestUtils.generateTestData(output, (long) 32);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
assertFiltering(filter, fileA, false);
assertFiltering(filter, fileB, true);
@@ -947,6 +1157,7 @@ public class FileFilterTestCase extends
//-----------------------------------------------------------------------
@SuppressWarnings("deprecation") // unavoidable until Java 7
+ @Test
public void testMagicNumberFileFilterBytes() throws Exception {
final byte[] classFileMagicNumber =
new byte[] {(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE};
@@ -961,7 +1172,7 @@ public class FileFilterTestCase extends
final OutputStream classFileAStream = FileUtils.openOutputStream(classFileA);
IOUtils.write(classFileMagicNumber, classFileAStream);
- generateTestData(classFileAStream, 32);
+ TestUtils.generateTestData(classFileAStream, (long) 32);
classFileAStream.close();
FileUtils.write(xmlFileB, xmlFileContent, Charsets.UTF_8);
@@ -983,6 +1194,7 @@ public class FileFilterTestCase extends
assertFiltering(filter, dir, false);
}
+ @Test
public void testMagicNumberFileFilterBytesOffset() throws Exception {
final byte[] tarMagicNumber = new byte[] {0x75, 0x73, 0x74, 0x61, 0x72};
final long tarMagicNumberOffset = 257;
@@ -993,11 +1205,21 @@ public class FileFilterTestCase extends
dir.mkdirs();
final OutputStream tarFileAStream = FileUtils.openOutputStream(tarFileA);
- generateTestData(tarFileAStream, tarMagicNumberOffset);
+ TestUtils.generateTestData(tarFileAStream, tarMagicNumberOffset);
IOUtils.write(tarMagicNumber, tarFileAStream);
tarFileAStream.close();
- createFile(randomFileB, 2 * tarMagicNumberOffset);
+ if (!randomFileB.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + randomFileB
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(randomFileB));
+ try {
+ TestUtils.generateTestData(output, 2 * tarMagicNumberOffset);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
IOFileFilter filter =
new MagicNumberFileFilter(tarMagicNumber, tarMagicNumberOffset);
@@ -1015,6 +1237,7 @@ public class FileFilterTestCase extends
}
@SuppressWarnings("deprecation") // unavoidable until Java 7
+ @Test
public void testMagicNumberFileFilterString() throws Exception {
final byte[] classFileMagicNumber =
new byte[] {(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE};
@@ -1029,7 +1252,7 @@ public class FileFilterTestCase extends
final OutputStream classFileAStream = FileUtils.openOutputStream(classFileA);
IOUtils.write(classFileMagicNumber, classFileAStream);
- generateTestData(classFileAStream, 32);
+ TestUtils.generateTestData(classFileAStream, (long) 32);
classFileAStream.close();
FileUtils.write(xmlFileB, xmlFileContent, Charsets.UTF_8);
@@ -1048,6 +1271,7 @@ public class FileFilterTestCase extends
}
@SuppressWarnings("deprecation") // unavoidable until Java 7
+ @Test
public void testMagicNumberFileFilterStringOffset() throws Exception {
final String tarMagicNumber = "ustar";
final long tarMagicNumberOffset = 257;
@@ -1058,11 +1282,21 @@ public class FileFilterTestCase extends
dir.mkdirs();
final OutputStream tarFileAStream = FileUtils.openOutputStream(tarFileA);
- generateTestData(tarFileAStream, tarMagicNumberOffset);
+ TestUtils.generateTestData(tarFileAStream, tarMagicNumberOffset);
IOUtils.write(tarMagicNumber, tarFileAStream, Charsets.UTF_8);
tarFileAStream.close();
- createFile(randomFileB, 2 * tarMagicNumberOffset);
+ if (!randomFileB.getParentFile().exists()) {
+ throw new IOException("Cannot create file " + randomFileB
+ + " as the parent directory does not exist");
+ }
+ final BufferedOutputStream output =
+ new BufferedOutputStream(new FileOutputStream(randomFileB));
+ try {
+ TestUtils.generateTestData(output, 2 * tarMagicNumberOffset);
+ } finally {
+ IOUtils.closeQuietly(output);
+ }
IOFileFilter filter =
new MagicNumberFileFilter(tarMagicNumber, tarMagicNumberOffset);
@@ -1079,6 +1313,7 @@ public class FileFilterTestCase extends
assertFiltering(filter, dir, false);
}
+ @Test
public void testMagicNumberFileFilterValidation() {
try {
new MagicNumberFileFilter((String)null, 0);
@@ -1122,9 +1357,10 @@ public class FileFilterTestCase extends
* Test method for {@link FileFilterUtils#filter(IOFileFilter, File...)}
* that tests that the method properly filters files from the list.
*/
+ @Test
public void testFilterArray() throws Exception {
- final File fileA = newFile("A");
- final File fileB = newFile("B");
+ final File fileA = TestUtils.newFile(getTestDirectory(), "A");
+ final File fileB = TestUtils.newFile(getTestDirectory(), "B");
final IOFileFilter filter = FileFilterUtils.nameFileFilter("A");
@@ -1138,9 +1374,10 @@ public class FileFilterTestCase extends
* Test method for {@link FileFilterUtils#filter(IOFileFilter, java.lang.Iterable)}
* that tests that the method properly filters files from the list.
*/
+ @Test
public void testFilterArray_fromList() throws Exception {
- final File fileA = newFile("A");
- final File fileB = newFile("B");
+ final File fileA = TestUtils.newFile(getTestDirectory(), "A");
+ final File fileB = TestUtils.newFile(getTestDirectory(), "B");
final List<File> fileList = Arrays.asList(fileA, fileB);
final IOFileFilter filter = FileFilterUtils.nameFileFilter("A");
@@ -1156,9 +1393,10 @@ public class FileFilterTestCase extends
* that tests {@code null} parameters and {@code null} elements
* in the provided list.
*/
+ @Test
public void testFilterArrayNullParameters() throws Exception {
- final File fileA = newFile("A");
- final File fileB = newFile("B");
+ final File fileA = TestUtils.newFile(getTestDirectory(), "A");
+ final File fileB = TestUtils.newFile(getTestDirectory(), "B");
try {
FileFilterUtils.filter(null, fileA, fileB);
fail();
@@ -1182,9 +1420,10 @@ public class FileFilterTestCase extends
* Test method for {@link FileFilterUtils#filterList(IOFileFilter, java.lang.Iterable)}
* that tests that the method properly filters files from the list.
*/
+ @Test
public void testFilterList() throws Exception {
- final File fileA = newFile("A");
- final File fileB = newFile("B");
+ final File fileA = TestUtils.newFile(getTestDirectory(), "A");
+ final File fileB = TestUtils.newFile(getTestDirectory(), "B");
final List<File> fileList = Arrays.asList(fileA, fileB);
final IOFileFilter filter = FileFilterUtils.nameFileFilter("A");
@@ -1199,9 +1438,10 @@ public class FileFilterTestCase extends
* Test method for {@link FileFilterUtils#filterList(IOFileFilter, File...)}
* that tests that the method properly filters files from the list.
*/
+ @Test
public void testFilterList_fromArray() throws Exception {
- final File fileA = newFile("A");
- final File fileB = newFile("B");
+ final File fileA = TestUtils.newFile(getTestDirectory(), "A");
+ final File fileB = TestUtils.newFile(getTestDirectory(), "B");
final IOFileFilter filter = FileFilterUtils.nameFileFilter("A");
@@ -1216,6 +1456,7 @@ public class FileFilterTestCase extends
* that tests {@code null} parameters and {@code null} elements
* in the provided list.
*/
+ @Test
public void testFilterListNullParameters() {
try {
FileFilterUtils.filterList(null, Collections.<File>emptyList());
@@ -1240,9 +1481,10 @@ public class FileFilterTestCase extends
* Test method for {@link FileFilterUtils#filterSet(IOFileFilter, java.lang.Iterable)}
* that tests that the method properly filters files from the set.
*/
+ @Test
public void testFilterSet() throws Exception {
- final File fileA = newFile("A");
- final File fileB = newFile("B");
+ final File fileA = TestUtils.newFile(getTestDirectory(), "A");
+ final File fileB = TestUtils.newFile(getTestDirectory(), "B");
final Set<File> fileList = new HashSet<File>(Arrays.asList(fileA, fileB));
final IOFileFilter filter = FileFilterUtils.nameFileFilter("A");
@@ -1257,9 +1499,10 @@ public class FileFilterTestCase extends
* Test method for {@link FileFilterUtils#filterSet(IOFileFilter, File...)}
* that tests that the method properly filters files from the set.
*/
+ @Test
public void testFilterSet_fromArray() throws Exception {
- final File fileA = newFile("A");
- final File fileB = newFile("B");
+ final File fileA = TestUtils.newFile(getTestDirectory(), "A");
+ final File fileB = TestUtils.newFile(getTestDirectory(), "B");
final IOFileFilter filter = FileFilterUtils.nameFileFilter("A");
@@ -1274,6 +1517,7 @@ public class FileFilterTestCase extends
* that tests {@code null} parameters and {@code null} elements
* in the provided set.
*/
+ @Test
public void testFilterSetNullParameters() {
try {
FileFilterUtils.filterSet(null, Collections.<File>emptySet());
@@ -1294,27 +1538,30 @@ public class FileFilterTestCase extends
assertEquals(0, filteredSet.size());
}
- public void testEnsureTestCoverage() {
- assertNotNull(new FileFilterUtils()); // dummy for test coverage
- }
-
- public void testNullFilters() {
- try {
- FileFilterUtils.toList((IOFileFilter)null);
- fail("Expected IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected
- }
- try {
- FileFilterUtils.toList(new IOFileFilter[]{null});
- fail("Expected IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
+ @Test
+ public void testEnsureTestCoverage() {
+ assertNotNull(new FileFilterUtils()); // dummy for test coverage
+ }
+
+ @Test
+ public void testNullFilters() {
+ try {
+ FileFilterUtils.toList((IOFileFilter) null);
+ fail("Expected IllegalArgumentException");
+ } catch (final IllegalArgumentException ignore) {
+ // expected
+ }
+ try {
+ FileFilterUtils.toList(new IOFileFilter[]{null});
+ fail("Expected IllegalArgumentException");
+ } catch (final IllegalArgumentException ignore) {
// expected
- }
- }
+ }
+ }
- public void testDelegation() { // TODO improve these tests
- assertNotNull(FileFilterUtils.asFileFilter((FileFilter)FalseFileFilter.INSTANCE));
- assertNotNull(FileFilterUtils.asFileFilter((FilenameFilter)FalseFileFilter.INSTANCE).toString());
- }
+ @Test
+ public void testDelegation() { // TODO improve these tests
+ assertNotNull(FileFilterUtils.asFileFilter((FileFilter) FalseFileFilter.INSTANCE));
+ assertNotNull(FileFilterUtils.asFileFilter((FilenameFilter) FalseFileFilter.INSTANCE).toString());
+ }
}
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/IOFileFilterAbstractTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/IOFileFilterAbstractTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/IOFileFilterAbstractTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/IOFileFilterAbstractTestCase.java Wed Dec 9 19:50:30 2015
@@ -20,11 +20,9 @@ import java.io.File;
import junit.framework.TestCase;
-public abstract class IOFileFilterAbstractTestCase extends TestCase {
+import static org.junit.Assert.assertEquals;
- public IOFileFilterAbstractTestCase(final String name) {
- super(name);
- }
+public abstract class IOFileFilterAbstractTestCase {
public static void assertFileFiltering(final int testNumber, final IOFileFilter filter, final File file, final boolean expected)
throws Exception {
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/OrFileFilterTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/OrFileFilterTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/OrFileFilterTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/OrFileFilterTestCase.java Wed Dec 9 19:50:30 2015
@@ -16,6 +16,8 @@
*/
package org.apache.commons.io.filefilter;
+import org.junit.Before;
+
import java.util.ArrayList;
import java.util.List;
@@ -30,16 +32,6 @@ public class OrFileFilterTestCase extend
private List<Boolean> testFileResults;
private List<Boolean> testFilenameResults;
- public OrFileFilterTestCase(final String name) {
- super(name);
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- this.setUpTestFilters();
- }
-
@Override
protected IOFileFilter buildFilterUsingAdd(final List<IOFileFilter> filters) {
final OrFileFilter filter = new OrFileFilter();
@@ -94,7 +86,8 @@ public class OrFileFilterTestCase extend
return WORKING_PATH_NAME_PROPERTY_KEY;
}
- private void setUpTestFilters() {
+ @Before
+ public void setUpTestFilters() {
// filters
//tests
this.testFilters = new ArrayList<List<IOFileFilter>>();
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/RegexFileFilterTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/RegexFileFilterTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/RegexFileFilterTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/RegexFileFilterTestCase.java Wed Dec 9 19:50:30 2015
@@ -22,22 +22,24 @@ import java.util.regex.Pattern;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOCase;
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.fail;
/**
* Used to test RegexFileFilterUtils.
*/
public class RegexFileFilterTestCase extends FileBasedTestCase {
- public RegexFileFilterTestCase(final String name) {
- super(name);
- }
-
- @Override
+ @Before
public void setUp() {
getTestDirectory().mkdirs();
}
- @Override
+ @After
public void tearDown() throws Exception {
FileUtils.deleteDirectory(getTestDirectory());
}
@@ -60,6 +62,7 @@ public class RegexFileFilterTestCase ext
}
}
+ @Test
public void testRegex() throws Exception {
IOFileFilter filter = new RegexFileFilter("^.*[tT]est(-\\d+)?\\.java$");
assertFiltering(filter, new File("Test.java"), true);
@@ -89,28 +92,28 @@ public class RegexFileFilterTestCase ext
try {
new RegexFileFilter((String)null);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
// expected
}
try {
new RegexFileFilter(null, Pattern.CASE_INSENSITIVE);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
// expected
}
try {
new RegexFileFilter(null, IOCase.INSENSITIVE);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
// expected
}
try {
new RegexFileFilter((java.util.regex.Pattern)null);
fail();
- } catch (final IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ignore) {
// expected
}
}
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/AutoCloseInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/AutoCloseInputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/AutoCloseInputStreamTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/AutoCloseInputStreamTest.java Wed Dec 9 19:50:30 2015
@@ -16,16 +16,21 @@
*/
package org.apache.commons.io.input;
+import org.junit.Before;
+import org.junit.Test;
+
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
/**
* JUnit Test Case for {@link AutoCloseInputStream}.
*/
-public class AutoCloseInputStreamTest extends TestCase {
+public class AutoCloseInputStreamTest {
private byte[] data;
@@ -33,8 +38,8 @@ public class AutoCloseInputStreamTest ex
private boolean closed;
- @Override
- protected void setUp() {
+ @Before
+ public void setUp() {
data = new byte[] { 'x', 'y', 'z' };
stream = new AutoCloseInputStream(new ByteArrayInputStream(data) {
@Override
@@ -45,6 +50,7 @@ public class AutoCloseInputStreamTest ex
closed = false;
}
+ @Test
public void testClose() throws IOException {
stream.close();
assertTrue("closed", closed);
@@ -52,6 +58,7 @@ public class AutoCloseInputStreamTest ex
}
+ @Test
public void testRead() throws IOException {
for (final byte element : data) {
assertEquals("read()", element, stream.read());
@@ -61,6 +68,7 @@ public class AutoCloseInputStreamTest ex
assertTrue("closed", closed);
}
+ @Test
public void testReadBuffer() throws IOException {
final byte[] b = new byte[data.length * 2];
int total = 0;
@@ -76,6 +84,7 @@ public class AutoCloseInputStreamTest ex
assertEquals("read(b)", -1, stream.read(b));
}
+ @Test
public void testReadBufferOffsetLength() throws IOException {
final byte[] b = new byte[data.length * 2];
int total = 0;
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BoundedInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BoundedInputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BoundedInputStreamTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BoundedInputStreamTest.java Wed Dec 9 19:50:30 2015
@@ -16,25 +16,23 @@
*/
package org.apache.commons.io.input;
-import java.io.ByteArrayInputStream;
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
-import junit.framework.TestCase;
+import java.io.ByteArrayInputStream;
-import org.apache.commons.io.IOUtils;
+import static org.junit.Assert.assertEquals;
/**
* Tests for {@link BoundedInputStream}.
*
* @version $Id$
*/
-public class BoundedInputStreamTest extends TestCase {
-
- public BoundedInputStreamTest(final String name) {
- super(name);
- }
+public class BoundedInputStreamTest {
+ @Test
public void testReadSingle() throws Exception {
- BoundedInputStream bounded = null;
+ BoundedInputStream bounded;
final byte[] helloWorld = "Hello World".getBytes();
final byte[] hello = "Hello".getBytes();
@@ -60,9 +58,10 @@ public class BoundedInputStreamTest exte
assertEquals("limit < length end", -1, bounded.read());
}
+ @Test
public void testReadArray() throws Exception {
- BoundedInputStream bounded = null;
+ BoundedInputStream bounded;
final byte[] helloWorld = "Hello World".getBytes();
final byte[] hello = "Hello".getBytes();
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BrokenInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BrokenInputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BrokenInputStreamTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BrokenInputStreamTest.java Wed Dec 9 19:50:30 2015
@@ -16,26 +16,32 @@
*/
package org.apache.commons.io.input;
+import org.junit.Before;
+import org.junit.Test;
+
import java.io.IOException;
import java.io.InputStream;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* JUnit Test Case for {@link BrokenInputStream}.
*/
-public class BrokenInputStreamTest extends TestCase {
+@SuppressWarnings("ResultOfMethodCallIgnored")
+public class BrokenInputStreamTest {
private IOException exception;
private InputStream stream;
- @Override
- protected void setUp() {
+ @Before
+ public void setUp() {
exception = new IOException("test exception");
stream = new BrokenInputStream(exception);
}
+ @Test
public void testRead() {
try {
stream.read();
@@ -59,6 +65,7 @@ public class BrokenInputStreamTest exten
}
}
+ @Test
public void testAvailable() {
try {
stream.available();
@@ -68,6 +75,7 @@ public class BrokenInputStreamTest exten
}
}
+ @Test
public void testSkip() {
try {
stream.skip(1);
@@ -77,6 +85,7 @@ public class BrokenInputStreamTest exten
}
}
+ @Test
public void testReset() {
try {
stream.reset();
@@ -86,6 +95,7 @@ public class BrokenInputStreamTest exten
}
}
+ @Test
public void testClose() {
try {
stream.close();
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClassLoaderObjectInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClassLoaderObjectInputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClassLoaderObjectInputStreamTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClassLoaderObjectInputStreamTest.java Wed Dec 9 19:50:30 2015
@@ -16,24 +16,17 @@
*/
package org.apache.commons.io.input;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
+import java.io.*;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
* Tests the CountingInputStream.
*
* @version $Id$
*/
-public class ClassLoaderObjectInputStreamTest extends TestCase {
-
- public ClassLoaderObjectInputStreamTest(final String name) {
- super(name);
- }
+public class ClassLoaderObjectInputStreamTest {
/* Note: This test case tests the simplest functionality of
* ObjectInputStream. IF we really wanted to test ClassLoaderObjectInputStream
@@ -41,6 +34,7 @@ public class ClassLoaderObjectInputStrea
*/
+ @org.junit.Test
public void testExpected() throws Exception {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -58,6 +52,7 @@ public class ClassLoaderObjectInputStrea
clois.close();
}
+ @org.junit.Test
public void testLong() throws Exception {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -75,6 +70,7 @@ public class ClassLoaderObjectInputStrea
clois.close();
}
+ @org.junit.Test
public void testPrimitiveLong() throws Exception {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -134,6 +130,7 @@ public class ClassLoaderObjectInputStrea
}
}
+ @org.junit.Test
public void testObject1() throws Exception {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -152,6 +149,7 @@ public class ClassLoaderObjectInputStrea
clois.close();
}
+ @org.junit.Test
public void testObject2() throws Exception {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -170,6 +168,7 @@ public class ClassLoaderObjectInputStrea
clois.close();
}
+ @org.junit.Test
public void testResolveProxyClass() throws Exception {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CloseShieldInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CloseShieldInputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CloseShieldInputStreamTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CloseShieldInputStreamTest.java Wed Dec 9 19:50:30 2015
@@ -16,16 +16,20 @@
*/
package org.apache.commons.io.input;
+import org.junit.Before;
+import org.junit.Test;
+
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
/**
* JUnit Test Case for {@link CloseShieldInputStream}.
*/
-public class CloseShieldInputStreamTest extends TestCase {
+public class CloseShieldInputStreamTest {
private byte[] data;
@@ -35,8 +39,8 @@ public class CloseShieldInputStreamTest
private boolean closed;
- @Override
- protected void setUp() {
+ @Before
+ public void setUp() {
data = new byte[] { 'x', 'y', 'z' };
original = new ByteArrayInputStream(data) {
@Override
@@ -48,6 +52,7 @@ public class CloseShieldInputStreamTest
closed = false;
}
+ @Test
public void testClose() throws IOException {
shielded.close();
assertFalse("closed", closed);
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClosedInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClosedInputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClosedInputStreamTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ClosedInputStreamTest.java Wed Dec 9 19:50:30 2015
@@ -16,13 +16,16 @@
*/
package org.apache.commons.io.input;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
/**
* JUnit Test Case for {@link ClosedInputStream}.
*/
-public class ClosedInputStreamTest extends TestCase {
+public class ClosedInputStreamTest {
+ @Test
public void testRead() throws Exception {
final ClosedInputStream cis = new ClosedInputStream();
assertEquals("read()", -1, cis.read());
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CountingInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CountingInputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CountingInputStreamTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CountingInputStreamTest.java Wed Dec 9 19:50:30 2015
@@ -16,26 +16,25 @@
*/
package org.apache.commons.io.input;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.output.NullOutputStream;
+import org.junit.Test;
+
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.OutputStream;
-import junit.framework.TestCase;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.io.output.NullOutputStream;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* Tests the CountingInputStream.
*
* @version $Id$
*/
-public class CountingInputStreamTest extends TestCase {
-
- public CountingInputStreamTest(final String name) {
- super(name);
- }
+public class CountingInputStreamTest {
+ @Test
public void testCounting() throws Exception {
final String text = "A piece of text";
final byte[] bytes = text.getBytes();
@@ -73,6 +72,7 @@ public class CountingInputStreamTest ext
/*
* Test for files > 2GB in size - see issue IO-84
*/
+ @Test
public void testLargeFiles_IO84() throws Exception {
final long size = (long)Integer.MAX_VALUE + (long)1;
final NullInputStream mock = new NullInputStream(size);
@@ -102,6 +102,7 @@ public class CountingInputStreamTest ext
assertEquals("resetByteCount()", size, cis.resetByteCount());
}
+ @Test
public void testResetting() throws Exception {
final String text = "A piece of text";
final byte[] bytes = text.getBytes();
@@ -119,6 +120,7 @@ public class CountingInputStreamTest ext
cis.close();
}
+ @Test
public void testZeroLength1() throws Exception {
final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]);
final CountingInputStream cis = new CountingInputStream(bais);
@@ -129,6 +131,7 @@ public class CountingInputStreamTest ext
cis.close();
}
+ @Test
public void testZeroLength2() throws Exception {
final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]);
final CountingInputStream cis = new CountingInputStream(bais);
@@ -141,6 +144,7 @@ public class CountingInputStreamTest ext
cis.close();
}
+ @Test
public void testZeroLength3() throws Exception {
final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]);
final CountingInputStream cis = new CountingInputStream(bais);
@@ -153,6 +157,7 @@ public class CountingInputStreamTest ext
cis.close();
}
+ @Test
public void testEOF1() throws Exception {
final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[2]);
final CountingInputStream cis = new CountingInputStream(bais);
@@ -169,6 +174,7 @@ public class CountingInputStreamTest ext
cis.close();
}
+ @Test
public void testEOF2() throws Exception {
final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[2]);
final CountingInputStream cis = new CountingInputStream(bais);
@@ -181,6 +187,7 @@ public class CountingInputStreamTest ext
cis.close();
}
+ @Test
public void testEOF3() throws Exception {
final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[2]);
final CountingInputStream cis = new CountingInputStream(bais);
@@ -193,6 +200,7 @@ public class CountingInputStreamTest ext
cis.close();
}
+ @Test
public void testSkipping() throws IOException {
final String text = "Hello World!";
final byte[] bytes = text.getBytes();
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/NullInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/NullInputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/NullInputStreamTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/NullInputStreamTest.java Wed Dec 9 19:50:30 2015
@@ -16,33 +16,25 @@
*/
package org.apache.commons.io.input;
+import org.junit.Test;
+
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* JUnit Test Case for {@link NullInputStream}.
*
* @version $Id$
*/
-public class NullInputStreamTest extends TestCase {
-
- public NullInputStreamTest(final String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
+public class NullInputStreamTest {
+ @Test
public void testRead() throws Exception {
final int size = 5;
final InputStream input = new TestNullInputStream(size);
@@ -69,6 +61,7 @@ public class NullInputStreamTest extends
assertEquals("Available after close", size, input.available());
}
+ @Test
public void testReadByteArray() throws Exception {
final byte[] bytes = new byte[10];
final InputStream input = new TestNullInputStream(15);
@@ -112,6 +105,7 @@ public class NullInputStreamTest extends
}
}
+ @Test
public void testEOFException() throws Exception {
final InputStream input = new TestNullInputStream(2, false, true);
assertEquals("Read 1", 0, input.read());
@@ -125,6 +119,7 @@ public class NullInputStreamTest extends
input.close();
}
+ @Test
public void testMarkAndReset() throws Exception {
int position = 0;
final int readlimit = 10;
@@ -176,6 +171,7 @@ public class NullInputStreamTest extends
input.close();
}
+ @Test
public void testMarkNotSupported() throws Exception {
final InputStream input = new TestNullInputStream(100, false, true);
assertFalse("Mark Should NOT be Supported", input.markSupported());
@@ -196,7 +192,8 @@ public class NullInputStreamTest extends
input.close();
}
- public void testSkip() throws Exception {
+ @Test
+ public void testSkip() throws Exception {
final InputStream input = new TestNullInputStream(10, true, false);
assertEquals("Read 1", 0, input.read());
assertEquals("Read 2", 1, input.read());
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/NullReaderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/NullReaderTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/NullReaderTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/NullReaderTest.java Wed Dec 9 19:50:30 2015
@@ -16,33 +16,25 @@
*/
package org.apache.commons.io.input;
+import org.junit.Test;
+
import java.io.EOFException;
import java.io.IOException;
import java.io.Reader;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* JUnit Test Case for {@link NullReader}.
*
* @version $Id$
*/
-public class NullReaderTest extends TestCase {
-
- public NullReaderTest(final String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
+public class NullReaderTest {
+ @Test
public void testRead() throws Exception {
final int size = 5;
final TestNullReader reader = new TestNullReader(size);
@@ -66,6 +58,7 @@ public class NullReaderTest extends Test
assertEquals("Available after close", 0, reader.getPosition());
}
+ @Test
public void testReadCharArray() throws Exception {
final char[] chars = new char[10];
final Reader reader = new TestNullReader(15);
@@ -109,6 +102,7 @@ public class NullReaderTest extends Test
}
}
+ @Test
public void testEOFException() throws Exception {
final Reader reader = new TestNullReader(2, false, true);
assertEquals("Read 1", 0, reader.read());
@@ -122,6 +116,7 @@ public class NullReaderTest extends Test
reader.close();
}
+ @Test
public void testMarkAndReset() throws Exception {
int position = 0;
final int readlimit = 10;
@@ -173,6 +168,7 @@ public class NullReaderTest extends Test
reader.close();
}
+ @Test
public void testMarkNotSupported() throws Exception {
final Reader reader = new TestNullReader(100, false, true);
assertFalse("Mark Should NOT be Supported", reader.markSupported());
@@ -193,7 +189,8 @@ public class NullReaderTest extends Test
reader.close();
}
- public void testSkip() throws Exception {
+ @Test
+ public void testSkip() throws Exception {
final Reader reader = new TestNullReader(10, true, false);
assertEquals("Read 1", 0, reader.read());
assertEquals("Read 2", 1, reader.read());
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ProxyReaderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ProxyReaderTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ProxyReaderTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ProxyReaderTest.java Wed Dec 9 19:50:30 2015
@@ -16,23 +16,22 @@
*/
package org.apache.commons.io.input;
+import org.junit.Test;
+
import java.io.IOException;
import java.io.Reader;
import java.nio.CharBuffer;
-import junit.framework.TestCase;
+import static org.junit.Assert.fail;
/**
* Test {@link ProxyReader}.
*
* @version $Id$
*/
-public class ProxyReaderTest extends TestCase {
-
- public ProxyReaderTest(final String name) {
- super(name);
- }
+public class ProxyReaderTest {
+ @Test
public void testNullCharArray() throws Exception {
final ProxyReader proxy = new ProxyReaderImpl(new CustomNullReader(0));
@@ -51,6 +50,7 @@ public class ProxyReaderTest extends Tes
proxy.close();
}
+ @Test
public void testNullCharBuffer() throws Exception {
final ProxyReader proxy = new ProxyReaderImpl(new CustomNullReader(0));
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/SwappedDataInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/SwappedDataInputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/SwappedDataInputStreamTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/SwappedDataInputStreamTest.java Wed Dec 9 19:50:30 2015
@@ -17,10 +17,15 @@
package org.apache.commons.io.input;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
import java.io.ByteArrayInputStream;
import java.io.IOException;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
@@ -30,16 +35,12 @@ import junit.framework.TestCase;
* @version $Id$
*/
-public class SwappedDataInputStreamTest extends TestCase {
+public class SwappedDataInputStreamTest {
private SwappedDataInputStream sdis;
private byte[] bytes;
- public SwappedDataInputStreamTest(final String name) {
- super(name);
- }
-
- @Override
+ @Before
public void setUp() {
bytes = new byte[] {
0x01,
@@ -55,11 +56,12 @@ public class SwappedDataInputStreamTest
this.sdis = new SwappedDataInputStream( bais );
}
- @Override
+ @After
public void tearDown() {
this.sdis = null;
}
+ @Test
public void testReadBoolean() throws IOException {
bytes = new byte[] {
0x00,
@@ -74,22 +76,27 @@ public class SwappedDataInputStreamTest
sdis.close();
}
+ @Test
public void testReadByte() throws IOException {
assertEquals( 0x01, this.sdis.readByte() );
}
+ @Test
public void testReadChar() throws IOException {
assertEquals( (char) 0x0201, this.sdis.readChar() );
}
+ @Test
public void testReadDouble() throws IOException {
assertEquals( Double.longBitsToDouble(0x0807060504030201L), this.sdis.readDouble(), 0 );
}
+ @Test
public void testReadFloat() throws IOException {
assertEquals( Float.intBitsToFloat(0x04030201), this.sdis.readFloat(), 0 );
}
+ @Test
public void testReadFully() throws IOException {
final byte[] bytesIn = new byte[8];
this.sdis.readFully(bytesIn);
@@ -98,42 +105,44 @@ public class SwappedDataInputStreamTest
}
}
+ @Test
public void testReadInt() throws IOException {
assertEquals( 0x04030201, this.sdis.readInt() );
}
+ @Test(expected = UnsupportedOperationException.class)
public void testReadLine() throws IOException {
- try {
- this.sdis.readLine();
- fail("readLine should be unsupported. ");
- } catch(final UnsupportedOperationException uoe) {
- }
+ this.sdis.readLine();
+ fail("readLine should be unsupported. ");
}
+ @Test
public void testReadLong() throws IOException {
assertEquals( 0x0807060504030201L, this.sdis.readLong() );
}
+ @Test
public void testReadShort() throws IOException {
assertEquals( (short) 0x0201, this.sdis.readShort() );
}
+ @Test
public void testReadUnsignedByte() throws IOException {
assertEquals( 0x01, this.sdis.readUnsignedByte() );
}
+ @Test
public void testReadUnsignedShort() throws IOException {
assertEquals( (short) 0x0201, this.sdis.readUnsignedShort() );
}
+ @Test(expected = UnsupportedOperationException.class)
public void testReadUTF() throws IOException {
- try {
- this.sdis.readUTF();
- fail("readUTF should be unsupported. ");
- } catch(final UnsupportedOperationException uoe) {
- }
+ this.sdis.readUTF();
+ fail("readUTF should be unsupported. ");
}
+ @Test
public void testSkipBytes() throws IOException {
this.sdis.skipBytes(4);
assertEquals( 0x08070605, this.sdis.readInt() );
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TaggedInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TaggedInputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TaggedInputStreamTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TaggedInputStreamTest.java Wed Dec 9 19:50:30 2015
@@ -24,12 +24,19 @@ import java.util.UUID;
import junit.framework.TestCase;
import org.apache.commons.io.TaggedIOException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* JUnit Test Case for {@link TaggedInputStream}.
*/
-public class TaggedInputStreamTest extends TestCase {
+public class TaggedInputStreamTest {
+ @Test
public void testEmptyStream() {
try {
final InputStream stream = new TaggedInputStream(new ClosedInputStream());
@@ -43,6 +50,7 @@ public class TaggedInputStreamTest exten
}
}
+ @Test
public void testNormalStream() {
try {
final InputStream stream = new TaggedInputStream(
@@ -61,6 +69,7 @@ public class TaggedInputStreamTest exten
}
}
+ @Test
public void testBrokenStream() {
final IOException exception = new IOException("test exception");
final TaggedInputStream stream =
@@ -109,6 +118,7 @@ public class TaggedInputStreamTest exten
}
}
+ @Test
public void testOtherException() throws Exception {
final IOException exception = new IOException("test exception");
final InputStream closed = new ClosedInputStream();