Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java Wed Dec 9 19:50:30 2015 @@ -16,17 +16,7 @@ */ package org.apache.commons.io.input; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.RandomAccessFile; -import java.io.Writer; +import java.io.*; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collections; @@ -38,6 +28,16 @@ import org.apache.commons.io.Charsets; import org.apache.commons.io.FileUtils; 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.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * Tests for {@link Tailer}. @@ -48,12 +48,8 @@ public class TailerTest extends FileBase private Tailer tailer; - public TailerTest(final String name) { - super(name); - } - - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { if (tailer != null) { tailer.stop(); Thread.sleep(1000); @@ -62,6 +58,7 @@ public class TailerTest extends FileBase Thread.sleep(1000); } + @Test public void testLongFile() throws Exception { final long delay = 50; @@ -91,6 +88,7 @@ public class TailerTest extends FileBase listener.clear(); } + @Test public void testBufferBreak() throws Exception { final long delay = 50; @@ -113,6 +111,7 @@ public class TailerTest extends FileBase } @SuppressWarnings("deprecation") // unavoidable until Java 7 + @Test public void testMultiByteBreak() throws Exception { System.out.println("testMultiByteBreak() Default charset: "+Charset.defaultCharset().displayName()); final long delay = 50; @@ -133,7 +132,7 @@ public class TailerTest extends FileBase try{ List<String> lines = new ArrayList<String>(); reader = new BufferedReader(new InputStreamReader(new FileInputStream(origin), charsetUTF8)); - String line = null; + String line; while((line = reader.readLine()) != null){ out.write(line); out.write("\n"); @@ -161,6 +160,7 @@ public class TailerTest extends FileBase } } + @Test public void testTailerEof() throws Exception { // Create & start the Tailer final long delay = 50; @@ -195,6 +195,7 @@ public class TailerTest extends FileBase } } + @Test public void testTailer() throws Exception { // Create & start the Tailer @@ -262,6 +263,7 @@ public class TailerTest extends FileBase assertEquals("fileRotated should be be called", 1 , listener.rotated); } + @Test public void testTailerEndOfFileReached() throws Exception { // Create & start the Tailer final long delayMillis = 50; @@ -290,10 +292,19 @@ public class TailerTest extends FileBase assertEquals("end of file reached 3 times", 3, listener.reachedEndOfFile); } - @Override protected void createFile(final File file, final long size) throws IOException { - super.createFile(file, size); + 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, size); + } finally { + IOUtils.closeQuietly(output); + } // try to make sure file is found // (to stop continuum occasionally failing) @@ -302,11 +313,11 @@ public class TailerTest extends FileBase while (reader == null) { try { reader = new RandomAccessFile(file.getPath(), "r"); - } catch (final FileNotFoundException e) { + } catch (final FileNotFoundException ignore) { } try { Thread.sleep(200L); - } catch (final InterruptedException e) { + } catch (final InterruptedException ignore) { // ignore } } @@ -341,6 +352,8 @@ public class TailerTest extends FileBase } } + + @Test public void testStopWithNoFile() throws Exception { final File file = new File(getTestDirectory(),"nosuchfile"); assertFalse("nosuchfile should not exist", file.exists()); @@ -362,6 +375,7 @@ public class TailerTest extends FileBase /* * Tests [IO-357][Tailer] InterruptedException while the thead is sleeping is silently ignored. */ + @Test public void testInterrupt() throws Exception { final File file = new File(getTestDirectory(), "nosuchfile"); assertFalse("nosuchfile should not exist", file.exists()); @@ -385,6 +399,7 @@ public class TailerTest extends FileBase assertEquals("end of file never reached", 0, listener.reachedEndOfFile); } + @Test public void testStopWithNoFileUsingExecutor() throws Exception { final File file = new File(getTestDirectory(),"nosuchfile"); assertFalse("nosuchfile should not exist", file.exists()); @@ -405,6 +420,7 @@ public class TailerTest extends FileBase assertEquals("end of file never reached", 0, listener.reachedEndOfFile); } + @Test public void testIO335() throws Exception { // test CR behaviour // Create & start the Tailer final long delayMillis = 50;
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TeeInputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TeeInputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TeeInputStreamTest.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TeeInputStreamTest.java Wed Dec 9 19:50:30 2015 @@ -21,11 +21,15 @@ import java.io.ByteArrayOutputStream; import java.io.InputStream; import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; /** * JUnit Test Case for {@link TeeInputStream}. */ -public class TeeInputStreamTest extends TestCase { +public class TeeInputStreamTest { private final String ASCII = "US-ASCII"; @@ -33,22 +37,25 @@ public class TeeInputStreamTest extends private ByteArrayOutputStream output; - @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { final InputStream input = new ByteArrayInputStream("abc".getBytes(ASCII)); output = new ByteArrayOutputStream(); tee = new TeeInputStream(input, output); } + @Test public void testReadNothing() throws Exception { assertEquals("", new String(output.toString(ASCII))); } + @Test public void testReadOneByte() throws Exception { assertEquals('a', tee.read()); assertEquals("a", new String(output.toString(ASCII))); } + @Test public void testReadEverything() throws Exception { assertEquals('a', tee.read()); assertEquals('b', tee.read()); @@ -57,6 +64,7 @@ public class TeeInputStreamTest extends assertEquals("abc", new String(output.toString(ASCII))); } + @Test public void testReadToArray() throws Exception { final byte[] buffer = new byte[8]; assertEquals(3, tee.read(buffer)); @@ -67,6 +75,7 @@ public class TeeInputStreamTest extends assertEquals("abc", new String(output.toString(ASCII))); } + @Test public void testReadToArrayWithOffset() throws Exception { final byte[] buffer = new byte[8]; assertEquals(3, tee.read(buffer, 4, 4)); @@ -77,6 +86,7 @@ public class TeeInputStreamTest extends assertEquals("abc", new String(output.toString(ASCII))); } + @Test public void testSkip() throws Exception { assertEquals('a', tee.read()); assertEquals(1, tee.skip(1)); @@ -85,6 +95,7 @@ public class TeeInputStreamTest extends assertEquals("ac", new String(output.toString(ASCII))); } + @Test public void testMarkReset() throws Exception { assertEquals('a', tee.read()); tee.mark(1); Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/monitor/AbstractMonitorTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/monitor/AbstractMonitorTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/monitor/AbstractMonitorTestCase.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/monitor/AbstractMonitorTestCase.java Wed Dec 9 19:50:30 2015 @@ -25,11 +25,16 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.FileFilterUtils; import org.apache.commons.io.filefilter.HiddenFileFilter; import org.apache.commons.io.filefilter.IOFileFilter; +import org.junit.After; +import org.junit.Before; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** * {@link FileAlterationObserver} Test Case. */ -public abstract class AbstractMonitorTestCase extends TestCase { +public abstract class AbstractMonitorTestCase { /** File observer */ protected FileAlterationObserver observer; @@ -46,17 +51,8 @@ public abstract class AbstractMonitorTes /** Time in milliseconds to pause in tests */ protected long pauseTime = 100L; - /** - * Construct a new test case. - * - * @param name The name of the test - */ - public AbstractMonitorTestCase(final String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { testDir = new File(new File("."), testDirName); if (testDir.exists()) { FileUtils.cleanDirectory(testDir); @@ -94,8 +90,8 @@ public abstract class AbstractMonitorTes } } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { FileUtils.deleteDirectory(testDir); } Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/monitor/FileAlterationMonitorTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/monitor/FileAlterationMonitorTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/monitor/FileAlterationMonitorTestCase.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/monitor/FileAlterationMonitorTestCase.java Wed Dec 9 19:50:30 2015 @@ -16,11 +16,18 @@ */ package org.apache.commons.io.monitor; +import org.junit.Test; + import java.io.File; import java.util.Collection; import java.util.Iterator; import java.util.concurrent.Executors; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * {@link FileAlterationMonitor} Test Case. */ @@ -29,22 +36,16 @@ public class FileAlterationMonitorTestCa /** * Construct a new test case. * - * @param name The name of the test */ - public FileAlterationMonitorTestCase(final String name) { - super(name); + public FileAlterationMonitorTestCase() { testDirName = "test-monitor"; - } - - @Override - protected void setUp() throws Exception { listener = new CollectionFileListener(false); - super.setUp(); } /** * Test default constructor. */ + @Test public void testDefaultConstructor() { final FileAlterationMonitor monitor = new FileAlterationMonitor(); assertEquals("Interval", 10000, monitor.getInterval()); @@ -53,6 +54,7 @@ public class FileAlterationMonitorTestCa /** * Test add/remove observers. */ + @Test public void testAddRemoveObservers() { FileAlterationObserver[] observers = null; FileAlterationMonitor monitor = null; @@ -88,6 +90,7 @@ public class FileAlterationMonitorTestCa /** * Test checkAndNotify() method */ + @Test public void testMonitor() { try { final long interval = 100; @@ -137,6 +140,7 @@ public class FileAlterationMonitorTestCa /** * Test using a thread factory. */ + @Test public void testThreadFactory() { try { final long interval = 100; Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/monitor/FileAlterationObserverTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/monitor/FileAlterationObserverTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/monitor/FileAlterationObserverTestCase.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/monitor/FileAlterationObserverTestCase.java Wed Dec 9 19:50:30 2015 @@ -23,6 +23,12 @@ import java.util.Iterator; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.CanReadFileFilter; import org.apache.commons.io.filefilter.FileFilterUtils; +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; /** * {@link FileAlterationObserver} Test Case. @@ -32,22 +38,16 @@ public class FileAlterationObserverTestC /** * Construct a new test case. * - * @param name The name of the test */ - public FileAlterationObserverTestCase(final String name) { - super(name); + public FileAlterationObserverTestCase() { testDirName = "test-observer"; - } - - @Override - protected void setUp() throws Exception { listener = new CollectionFileListener(true); - super.setUp(); } /** * Test add/remove listeners. */ + @Test public void testAddRemoveListeners() { final FileAlterationObserver observer = new FileAlterationObserver("/foo"); // Null Listener @@ -72,6 +72,7 @@ public class FileAlterationObserverTestC /** * Test toString(). */ + @Test public void testToString() { final File file = new File("/foo"); FileAlterationObserver observer = null; @@ -90,6 +91,7 @@ public class FileAlterationObserverTestC /** * Test checkAndNotify() method */ + @Test public void testDirectory() { try { checkAndNotify(); @@ -152,6 +154,7 @@ public class FileAlterationObserverTestC /** * Test checkAndNotify() creating */ + @Test public void testFileCreate() { try { checkAndNotify(); @@ -214,6 +217,7 @@ public class FileAlterationObserverTestC /** * Test checkAndNotify() creating */ + @Test public void testFileUpdate() { try { checkAndNotify(); @@ -273,6 +277,7 @@ public class FileAlterationObserverTestC /** * Test checkAndNotify() deleting */ + @Test public void testFileDelete() { try { checkAndNotify(); @@ -336,6 +341,7 @@ public class FileAlterationObserverTestC /** * Test checkAndNotify() method */ + @Test public void testObserveSingleFile() { try { final File testDirA = new File(testDir, "test-dir-A"); Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/BrokenOutputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/BrokenOutputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/BrokenOutputStreamTest.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/BrokenOutputStreamTest.java Wed Dec 9 19:50:30 2015 @@ -16,26 +16,31 @@ */ package org.apache.commons.io.output; +import org.junit.Before; +import org.junit.Test; + import java.io.IOException; import java.io.OutputStream; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** * JUnit Test Case for {@link BrokenOutputStream}. */ -public class BrokenOutputStreamTest extends TestCase { +public class BrokenOutputStreamTest { private IOException exception; private OutputStream stream; - @Override - protected void setUp() { + @Before + public void setUp() { exception = new IOException("test exception"); stream = new BrokenOutputStream(exception); } + @Test public void testWrite() { try { stream.write(1); @@ -59,6 +64,7 @@ public class BrokenOutputStreamTest exte } } + @Test public void testFlush() { try { stream.flush(); @@ -68,6 +74,7 @@ public class BrokenOutputStreamTest exte } } + @Test public void testClose() { try { stream.close(); Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ByteArrayOutputStreamTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ByteArrayOutputStreamTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ByteArrayOutputStreamTestCase.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ByteArrayOutputStreamTestCase.java Wed Dec 9 19:50:30 2015 @@ -16,18 +16,21 @@ */ package org.apache.commons.io.output; +import org.apache.commons.io.IOUtils; +import org.junit.Test; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import org.apache.commons.io.IOUtils; - -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.fail; /** * Basic unit tests for the alternative ByteArrayOutputStream implementation. */ -public class ByteArrayOutputStreamTestCase extends TestCase { +public class ByteArrayOutputStreamTestCase { private static final byte[] DATA; @@ -38,10 +41,6 @@ public class ByteArrayOutputStreamTestCa } } - public ByteArrayOutputStreamTestCase(final String name) { - super(name); - } - private int writeData(final ByteArrayOutputStream baout, final java.io.ByteArrayOutputStream ref, final int count) { @@ -96,6 +95,7 @@ public class ByteArrayOutputStreamTestCa checkByteArrays(buf, refbuf); } + @Test public void testToInputStream() throws IOException { ByteArrayOutputStream baout = new ByteArrayOutputStream(); java.io.ByteArrayOutputStream ref = new java.io.ByteArrayOutputStream(); @@ -127,6 +127,7 @@ public class ByteArrayOutputStreamTestCa in.close(); } + @Test public void testToInputStreamWithReset() throws IOException { //Make sure reset() do not destroy InputStream returned from toInputStream() ByteArrayOutputStream baout = new ByteArrayOutputStream(); @@ -161,6 +162,7 @@ public class ByteArrayOutputStreamTestCa in.close(); } + @Test public void testStream() throws Exception { int written; Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/CloseShieldOutputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/CloseShieldOutputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/CloseShieldOutputStreamTest.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/CloseShieldOutputStreamTest.java Wed Dec 9 19:50:30 2015 @@ -16,15 +16,20 @@ */ package org.apache.commons.io.output; +import org.junit.Before; +import org.junit.Test; + import java.io.IOException; import java.io.OutputStream; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; /** * JUnit Test Case for {@link CloseShieldOutputStream}. */ -public class CloseShieldOutputStreamTest extends TestCase { +public class CloseShieldOutputStreamTest { private ByteArrayOutputStream original; @@ -32,8 +37,8 @@ public class CloseShieldOutputStreamTest private boolean closed; - @Override - protected void setUp() { + @Before + public void setUp() { original = new ByteArrayOutputStream() { @Override public void close() { @@ -44,13 +49,14 @@ public class CloseShieldOutputStreamTest closed = false; } + @Test public void testClose() throws IOException { shielded.close(); assertFalse("closed", closed); try { shielded.write('x'); fail("write(b)"); - } catch (final IOException e) { + } catch (final IOException ignore) { // expected } original.write('y'); Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ClosedOutputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ClosedOutputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ClosedOutputStreamTest.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ClosedOutputStreamTest.java Wed Dec 9 19:50:30 2015 @@ -19,16 +19,20 @@ package org.apache.commons.io.output; import java.io.IOException; import junit.framework.TestCase; +import org.junit.Test; + +import static org.junit.Assert.fail; /** * JUnit Test Case for {@link ClosedOutputStream}. */ -public class ClosedOutputStreamTest extends TestCase { +public class ClosedOutputStreamTest { /** * Test the <code>write(b)</code> method. * @throws Exception */ + @Test public void testRead() throws Exception { ClosedOutputStream cos = null; try { Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/CountingOutputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/CountingOutputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/CountingOutputStreamTest.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/CountingOutputStreamTest.java Wed Dec 9 19:50:30 2015 @@ -21,22 +21,22 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; -import junit.framework.TestCase; - import org.apache.commons.io.IOUtils; import org.apache.commons.io.input.NullInputStream; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** * @version $Id$ */ -public class CountingOutputStreamTest extends TestCase { +public class CountingOutputStreamTest { - public CountingOutputStreamTest(final String name) { - super(name); - } + @Test public void testCounting() throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final CountingOutputStream cos = new CountingOutputStream(baos); @@ -77,6 +77,7 @@ public class CountingOutputStreamTest ex /* * 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; Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java Wed Dec 9 19:50:30 2015 @@ -16,20 +16,27 @@ */ package org.apache.commons.io.output; +import org.junit.Test; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Arrays; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * Unit tests for the <code>DeferredFileOutputStream</code> class. * * @version $Id$ */ -public class DeferredFileOutputStreamTest extends TestCase +public class DeferredFileOutputStreamTest { /** @@ -43,19 +50,10 @@ public class DeferredFileOutputStreamTes private final byte[] testBytes = testString.getBytes(); /** - * Standard JUnit test case constructor. - * - * @param name The name of the test case. - */ - public DeferredFileOutputStreamTest(final String name) - { - super(name); - } - - /** * Tests the case where the amount of data falls below the threshold, and * is therefore confined to memory. */ + @Test public void testBelowThreshold() { final DeferredFileOutputStream dfos = @@ -80,6 +78,7 @@ public class DeferredFileOutputStreamTes * threshold. The behavior should be the same as that for the amount of * data being below (i.e. not exceeding) the threshold. */ + @Test public void testAtThreshold() { final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length, null); @@ -103,6 +102,7 @@ public class DeferredFileOutputStreamTes * therefore written to disk. The actual data written to disk is verified, * as is the file itself. */ + @Test public void testAboveThreshold() { final File testFile = new File("testAboveThreshold.dat"); @@ -133,6 +133,7 @@ public class DeferredFileOutputStreamTes * ensure that the <code>thresholdReached()</code> method is only called * once, as the threshold is crossed for the first time. */ + @Test public void testThresholdReached() { final File testFile = new File("testThresholdReached.dat"); @@ -167,6 +168,7 @@ public class DeferredFileOutputStreamTes /** * Test wether writeTo() properly writes small content. */ + @Test public void testWriteToSmall(){ final File testFile = new File("testWriteToMem.dat"); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -202,6 +204,7 @@ public class DeferredFileOutputStreamTes /** * Test wether writeTo() properly writes large content. */ + @Test public void testWriteToLarge(){ final File testFile = new File("testWriteToFile.dat"); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -237,6 +240,7 @@ public class DeferredFileOutputStreamTes /** * Test specifying a temporary file and the threshold not reached. */ + @Test public void testTempFileBelowThreshold() { final String prefix = "commons-io-test"; @@ -260,6 +264,7 @@ public class DeferredFileOutputStreamTes /** * Test specifying a temporary file and the threshold is reached. */ + @Test public void testTempFileAboveThreshold() { final String prefix = "commons-io-test"; @@ -293,6 +298,7 @@ public class DeferredFileOutputStreamTes /** * Test specifying a temporary file and the threshold is reached. */ + @Test public void testTempFileAboveThresholdPrefixOnly() { final String prefix = "commons-io-test"; @@ -326,6 +332,7 @@ public class DeferredFileOutputStreamTes * Test specifying a temporary file and the threshold is reached. * @throws Exception */ + @Test public void testTempFileError() throws Exception { final String prefix = null; Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/FileWriterWithEncodingTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/FileWriterWithEncodingTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/FileWriterWithEncodingTest.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/FileWriterWithEncodingTest.java Wed Dec 9 19:50:30 2015 @@ -29,6 +29,14 @@ import junit.framework.AssertionFailedEr import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.io.testtools.FileBasedTestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.apache.commons.io.testtools.TestUtils.checkFile; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * Tests that the encoding is actually set and used. @@ -43,11 +51,7 @@ public class FileWriterWithEncodingTest private String textContent; private char[] anotherTestContent = new char[]{'f', 'z', 'x'}; - public FileWriterWithEncodingTest(final String name) { - super(name); - } - - @Override + @Before public void setUp() { final File encodingFinder = new File(getTestDirectory(), "finder.txt"); OutputStreamWriter out = null; @@ -69,7 +73,7 @@ public class FileWriterWithEncodingTest textContent = new String(arr); } - @Override + @After public void tearDown() throws Exception { FileUtils.deleteDirectory(getTestDirectory()); defaultEncoding = null; @@ -77,28 +81,34 @@ public class FileWriterWithEncodingTest } //----------------------------------------------------------------------- - public void testSameEncoding_string_constructor() throws Exception { + @Test + public void sameEncoding_string_constructor() throws Exception { succesfulRun(new FileWriterWithEncoding(file2, defaultEncoding)); } - public void testSameEncoding_string_string_constructor() throws Exception { + @Test + public void sameEncoding_string_string_constructor() throws Exception { succesfulRun(new FileWriterWithEncoding(file2.getPath(), defaultEncoding)); } - public void testSameEncoding_Charset_constructor() throws Exception { + @Test + public void sameEncoding_Charset_constructor() throws Exception { succesfulRun(new FileWriterWithEncoding(file2, Charset.defaultCharset())); } - public void testSameEncoding_string_Charset_constructor() throws Exception { + @Test + public void sameEncoding_string_Charset_constructor() throws Exception { succesfulRun(new FileWriterWithEncoding(file2.getPath(), Charset.defaultCharset())); } - public void testSameEncoding_CharsetEncoder_constructor() throws Exception { + @Test + public void sameEncoding_CharsetEncoder_constructor() throws Exception { CharsetEncoder enc = Charset.defaultCharset().newEncoder(); succesfulRun(new FileWriterWithEncoding(file2, enc)); } - public void testSameEncoding_string_CharsetEncoder_constructor() throws Exception { + @Test + public void sameEncoding_string_CharsetEncoder_constructor() throws Exception { CharsetEncoder enc = Charset.defaultCharset().newEncoder(); succesfulRun(new FileWriterWithEncoding(file2.getPath(), enc)); } @@ -120,6 +130,7 @@ public class FileWriterWithEncodingTest assertTrue(file2.exists()); } + @Test public void testDifferentEncoding() throws Exception { if (Charset.isSupported("UTF-16BE")) { FileWriter fw1 = null; @@ -131,7 +142,7 @@ public class FileWriterWithEncodingTest try { checkFile(file1, file2); fail(); - } catch (final AssertionFailedError ex) { + } catch (final AssertionError ex) { // success } @@ -152,7 +163,7 @@ public class FileWriterWithEncodingTest try { checkFile(file1, file2); fail(); - } catch (final AssertionFailedError ex) { + } catch (final AssertionError ex) { // success } @@ -185,7 +196,8 @@ public class FileWriterWithEncodingTest } //----------------------------------------------------------------------- - public void testConstructor_File_encoding_badEncoding() { + @Test + public void constructor_File_encoding_badEncoding() { Writer writer = null; try { writer = new FileWriterWithEncoding(file1, "BAD-ENCODE"); @@ -200,7 +212,8 @@ public class FileWriterWithEncodingTest } //----------------------------------------------------------------------- - public void testConstructor_File_directory() { + @Test + public void constructor_File_directory() { Writer writer = null; try { writer = new FileWriterWithEncoding(getTestDirectory(), defaultEncoding); @@ -215,7 +228,8 @@ public class FileWriterWithEncodingTest } //----------------------------------------------------------------------- - public void testConstructor_File_nullFile() throws IOException { + @Test + public void constructor_File_nullFile() throws IOException { Writer writer = null; try { writer = new FileWriterWithEncoding((File) null, defaultEncoding); @@ -230,7 +244,8 @@ public class FileWriterWithEncodingTest } //----------------------------------------------------------------------- - public void testConstructor_fileName_nullFile() throws IOException { + @Test + public void constructor_fileName_nullFile() throws IOException { Writer writer = null; try { writer = new FileWriterWithEncoding((String) null, defaultEncoding); @@ -244,7 +259,8 @@ public class FileWriterWithEncodingTest assertFalse(file1.exists()); } - public void testSameEncoding_null_Charset_constructor() throws Exception { + @Test + public void sameEncoding_null_Charset_constructor() throws Exception { try { succesfulRun(new FileWriterWithEncoding(file2, (Charset) null)); fail(); Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/LockableFileWriterTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/LockableFileWriterTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/LockableFileWriterTest.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/LockableFileWriterTest.java Wed Dec 9 19:50:30 2015 @@ -24,6 +24,13 @@ import java.nio.charset.UnsupportedChars import org.apache.commons.io.Charsets; import org.apache.commons.io.IOUtils; 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; /** * Tests that files really lock, although no writing is done as @@ -39,11 +46,7 @@ public class LockableFileWriterTest exte private File altLockDir; private File altLockFile; - public LockableFileWriterTest(final String name) { - super(name); - } - - @Override + @Before public void setUp() { file = new File(getTestDirectory(), "testlockfile"); lockDir = new File(System.getProperty("java.io.tmpdir")); @@ -52,7 +55,7 @@ public class LockableFileWriterTest exte altLockFile = new File(altLockDir, file.getName() + ".lck"); } - @Override + @After public void tearDown() { file.delete(); lockFile.delete(); @@ -60,7 +63,7 @@ public class LockableFileWriterTest exte } //----------------------------------------------------------------------- - public void testFileLocked() throws IOException { + @Test public void testFileLocked() throws IOException { LockableFileWriter lfw1 = null; LockableFileWriter lfw2 = null; LockableFileWriter lfw3 = null; @@ -105,7 +108,7 @@ public class LockableFileWriterTest exte //----------------------------------------------------------------------- @SuppressWarnings("deprecation") // unavoidable until Java 7 - public void testAlternateLockDir() throws IOException { + @Test public void testAlternateLockDir() throws IOException { LockableFileWriter lfw1 = null; LockableFileWriter lfw2 = null; try { @@ -135,7 +138,7 @@ public class LockableFileWriterTest exte } //----------------------------------------------------------------------- - public void testFileNotLocked() throws IOException { + @Test public void testFileNotLocked() throws IOException { // open a valid locakable writer LockableFileWriter lfw1 = null; try { @@ -162,7 +165,7 @@ public class LockableFileWriterTest exte } //----------------------------------------------------------------------- - public void testConstructor_File_encoding_badEncoding() throws IOException { + @Test public void testConstructor_File_encoding_badEncoding() throws IOException { Writer writer = null; try { writer = new LockableFileWriter(file, "BAD-ENCODE"); @@ -179,7 +182,7 @@ public class LockableFileWriterTest exte } //----------------------------------------------------------------------- - public void testConstructor_File_directory() { + @Test public void testConstructor_File_directory() { Writer writer = null; try { writer = new LockableFileWriter(getTestDirectory()); @@ -196,7 +199,7 @@ public class LockableFileWriterTest exte } //----------------------------------------------------------------------- - public void testConstructor_File_nullFile() throws IOException { + @Test public void testConstructor_File_nullFile() throws IOException { Writer writer = null; try { writer = new LockableFileWriter((File) null); @@ -213,7 +216,7 @@ public class LockableFileWriterTest exte } //----------------------------------------------------------------------- - public void testConstructor_fileName_nullFile() throws IOException { + @Test public void testConstructor_fileName_nullFile() throws IOException { Writer writer = null; try { writer = new LockableFileWriter((String) null); Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/NullOutputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/NullOutputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/NullOutputStreamTest.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/NullOutputStreamTest.java Wed Dec 9 19:50:30 2015 @@ -17,9 +17,9 @@ package org.apache.commons.io.output; -import java.io.IOException; +import org.junit.Test; -import junit.framework.TestCase; +import java.io.IOException; /** @@ -29,12 +29,9 @@ import junit.framework.TestCase; * @version $Id$ */ -public class NullOutputStreamTest extends TestCase { - - public NullOutputStreamTest(final String name) { - super(name); - } +public class NullOutputStreamTest { + @Test public void testNull() throws IOException { final NullOutputStream nos = new NullOutputStream(); nos.write("string".getBytes()); Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/NullWriterTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/NullWriterTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/NullWriterTest.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/NullWriterTest.java Wed Dec 9 19:50:30 2015 @@ -16,7 +16,7 @@ */ package org.apache.commons.io.output; -import junit.framework.TestCase; +import org.junit.Test; /** * Really not a lot to do here, but checking that no @@ -24,12 +24,9 @@ import junit.framework.TestCase; * * @version $Id$ */ -public class NullWriterTest extends TestCase { - - public NullWriterTest(final String name) { - super(name); - } +public class NullWriterTest { + @Test public void testNull() { final char[] chars = new char[] {'A', 'B', 'C'}; final NullWriter writer = new NullWriter(); Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ProxyOutputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ProxyOutputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ProxyOutputStreamTest.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ProxyOutputStreamTest.java Wed Dec 9 19:50:30 2015 @@ -16,22 +16,25 @@ */ package org.apache.commons.io.output; +import org.junit.Before; +import org.junit.Test; + import java.io.IOException; import java.io.OutputStream; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; /** * JUnit Test Case for {@link CloseShieldOutputStream}. */ -public class ProxyOutputStreamTest extends TestCase { +public class ProxyOutputStreamTest { private ByteArrayOutputStream original; private OutputStream proxied; - @Override - protected void setUp() { + @Before + public void setUp() { original = new ByteArrayOutputStream(){ @Override public void write(final byte[] ba) throws IOException { @@ -43,12 +46,14 @@ public class ProxyOutputStreamTest exten proxied = new ProxyOutputStream(original); } + @Test public void testWrite() throws Exception { proxied.write('y'); assertEquals(1, original.size()); assertEquals('y', original.toByteArray()[0]); } + @Test public void testWriteNullBaSucceeds() throws Exception { final byte[] ba = null; original.write(ba); Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/StringBuilderWriterTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/StringBuilderWriterTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/StringBuilderWriterTest.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/StringBuilderWriterTest.java Wed Dec 9 19:50:30 2015 @@ -16,23 +16,25 @@ */ package org.apache.commons.io.output; +import org.junit.Test; + import java.io.IOException; import java.io.Writer; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.fail; /** * Test case for {@link StringBuilderWriter}. * * @version $Id$ */ -public class StringBuilderWriterTest extends TestCase { +public class StringBuilderWriterTest { private static final char[] FOOBAR_CHARS = new char[] {'F', 'o', 'o', 'B', 'a', 'r'}; - public StringBuilderWriterTest(final String name) { - super(name); - } + @Test public void testAppendConstructCapacity() throws IOException { final Writer writer = new StringBuilderWriter(100); writer.append("Foo"); @@ -40,6 +42,7 @@ public class StringBuilderWriterTest ext writer.close(); } + @Test public void testAppendConstructStringBuilder() { final StringBuilder builder = new StringBuilder("Foo"); final StringBuilderWriter writer = new StringBuilderWriter(builder); @@ -49,6 +52,7 @@ public class StringBuilderWriterTest ext writer.close(); } + @Test public void testAppendConstructNull() throws IOException { final Writer writer = new StringBuilderWriter(null); writer.append("Foo"); @@ -56,6 +60,7 @@ public class StringBuilderWriterTest ext writer.close(); } + @Test public void testAppendChar() throws IOException { final Writer writer = new StringBuilderWriter(); writer.append('F').append('o').append('o'); @@ -63,6 +68,7 @@ public class StringBuilderWriterTest ext writer.close(); } + @Test public void testAppendCharSequence() throws IOException { final Writer writer = new StringBuilderWriter(); writer.append("Foo").append("Bar"); @@ -70,6 +76,7 @@ public class StringBuilderWriterTest ext writer.close(); } + @Test public void testAppendCharSequencePortion() throws IOException { final Writer writer = new StringBuilderWriter(); writer.append("FooBar", 3, 6).append(new StringBuffer("FooBar"), 0, 3); @@ -77,6 +84,7 @@ public class StringBuilderWriterTest ext writer.close(); } + @Test public void testClose() { final Writer writer = new StringBuilderWriter(); try { @@ -89,6 +97,7 @@ public class StringBuilderWriterTest ext assertEquals("FooBar", writer.toString()); } + @Test public void testWriteChar() throws IOException { final Writer writer = new StringBuilderWriter(); writer.write('F'); @@ -100,6 +109,7 @@ public class StringBuilderWriterTest ext writer.close(); } + @Test public void testWriteCharArray() throws IOException { final Writer writer = new StringBuilderWriter(); writer.write(new char[] {'F', 'o', 'o'}); @@ -109,6 +119,7 @@ public class StringBuilderWriterTest ext writer.close(); } + @Test public void testWriteCharArrayPortion() throws IOException { final Writer writer = new StringBuilderWriter(); writer.write(FOOBAR_CHARS, 3, 3); @@ -118,6 +129,7 @@ public class StringBuilderWriterTest ext writer.close(); } + @Test public void testWriteString() throws IOException { final Writer writer = new StringBuilderWriter(); writer.write("Foo"); @@ -127,6 +139,7 @@ public class StringBuilderWriterTest ext writer.close(); } + @Test public void testWriteStringPortion() throws IOException { final Writer writer = new StringBuilderWriter(); writer.write("FooBar", 3, 3); Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/TaggedOutputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/TaggedOutputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/TaggedOutputStreamTest.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/TaggedOutputStreamTest.java Wed Dec 9 19:50:30 2015 @@ -23,12 +23,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 TaggedOutputStream}. */ -public class TaggedOutputStreamTest extends TestCase { +public class TaggedOutputStreamTest { + @Test public void testNormalStream() { try { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); @@ -47,6 +54,7 @@ public class TaggedOutputStreamTest exte } } + @Test public void testBrokenStream() { final IOException exception = new IOException("test exception"); final TaggedOutputStream stream = @@ -95,6 +103,7 @@ public class TaggedOutputStreamTest exte } } + @Test public void testOtherException() throws Exception { final IOException exception = new IOException("test exception"); final OutputStream closed = new ClosedOutputStream(); Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/TeeOutputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/TeeOutputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/TeeOutputStreamTest.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/TeeOutputStreamTest.java Wed Dec 9 19:50:30 2015 @@ -16,18 +16,19 @@ */ package org.apache.commons.io.output; +import org.junit.Assert; +import org.junit.Test; + import java.io.ByteArrayOutputStream; import java.io.IOException; -import junit.framework.TestCase; - -import org.junit.Assert; +import static org.junit.Assert.assertEquals; /** * @version $Id$ */ -public class TeeOutputStreamTest extends TestCase { +public class TeeOutputStreamTest { private static class ExceptionOnCloseByteArrayOutputStream extends ByteArrayOutputStream { @@ -48,14 +49,11 @@ public class TeeOutputStreamTest extends } } - public TeeOutputStreamTest(final String name) { - super(name); - } - /** * Tests that the branch {@code OutputStream} is closed when closing the main {@code OutputStream} throws an * exception on {@link TeeOutputStream#close()}. */ + @Test public void testCloseBranchIOException() { final ByteArrayOutputStream badOs = new ExceptionOnCloseByteArrayOutputStream(); final RecordCloseByteArrayOutputStream goodOs = new RecordCloseByteArrayOutputStream(); @@ -72,6 +70,7 @@ public class TeeOutputStreamTest extends * Tests that the main {@code OutputStream} is closed when closing the branch {@code OutputStream} throws an * exception on {@link TeeOutputStream#close()}. */ + @Test public void testCloseMainIOException() { final ByteArrayOutputStream badOs = new ExceptionOnCloseByteArrayOutputStream(); final RecordCloseByteArrayOutputStream goodOs = new RecordCloseByteArrayOutputStream(); @@ -84,6 +83,7 @@ public class TeeOutputStreamTest extends } } + @Test public void testTee() throws IOException { final ByteArrayOutputStream baos1 = new ByteArrayOutputStream(); final ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/WriterOutputStreamTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/WriterOutputStreamTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/WriterOutputStreamTest.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/WriterOutputStreamTest.java Wed Dec 9 19:50:30 2015 @@ -16,13 +16,15 @@ */ package org.apache.commons.io.output; +import org.junit.Test; + import java.io.IOException; import java.io.StringWriter; import java.util.Random; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; -public class WriterOutputStreamTest extends TestCase { +public class WriterOutputStreamTest { private static final String TEST_STRING = "\u00e0 peine arriv\u00e9s nous entr\u00e2mes dans sa chambre"; private static final String LARGE_TEST_STRING; @@ -61,47 +63,58 @@ public class WriterOutputStreamTest exte assertEquals(testString, writer.toString()); } + @Test public void testUTF8WithSingleByteWrite() throws IOException { testWithSingleByteWrite(TEST_STRING, "UTF-8"); } + @Test public void testLargeUTF8WithSingleByteWrite() throws IOException { testWithSingleByteWrite(LARGE_TEST_STRING, "UTF-8"); } + @Test public void testUTF8WithBufferedWrite() throws IOException { testWithBufferedWrite(TEST_STRING, "UTF-8"); } + @Test public void testLargeUTF8WithBufferedWrite() throws IOException { testWithBufferedWrite(LARGE_TEST_STRING, "UTF-8"); } + @Test public void testUTF16WithSingleByteWrite() throws IOException { testWithSingleByteWrite(TEST_STRING, "UTF-16"); } + @Test public void testUTF16WithBufferedWrite() throws IOException { testWithBufferedWrite(TEST_STRING, "UTF-16"); } + @Test public void testUTF16BEWithSingleByteWrite() throws IOException { testWithSingleByteWrite(TEST_STRING, "UTF-16BE"); } + @Test public void testUTF16BEWithBufferedWrite() throws IOException { testWithBufferedWrite(TEST_STRING, "UTF-16BE"); } + @Test public void testUTF16LEWithSingleByteWrite() throws IOException { testWithSingleByteWrite(TEST_STRING, "UTF-16LE"); } + @Test public void testUTF16LEWithBufferedWrite() throws IOException { testWithBufferedWrite(TEST_STRING, "UTF-16LE"); } + @Test public void testFlush() throws IOException { final StringWriter writer = new StringWriter(); final WriterOutputStream out = new WriterOutputStream(writer, "us-ascii", 1024, false); @@ -112,6 +125,7 @@ public class WriterOutputStreamTest exte out.close(); } + @Test public void testWriteImmediately() throws IOException { final StringWriter writer = new StringWriter(); final WriterOutputStream out = new WriterOutputStream(writer, "us-ascii", 1024, true); Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/XmlStreamWriterTest.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/XmlStreamWriterTest.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/XmlStreamWriterTest.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/XmlStreamWriterTest.java Wed Dec 9 19:50:30 2015 @@ -16,16 +16,19 @@ */ package org.apache.commons.io.output; +import org.junit.Test; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * @version $Id$ */ -public class XmlStreamWriterTest extends TestCase { +public class XmlStreamWriterTest { /** french */ private static final String TEXT_LATIN1 = "eacute: \u00E9"; /** greek */ @@ -43,8 +46,7 @@ public class XmlStreamWriterTest extends if (encoding != null) { xmlDecl = "<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>"; } - final String xml = xmlDecl + "\n<text>" + text + "</text>"; - return xml; + return xmlDecl + "\n<text>" + text + "</text>"; } private static void checkXmlContent(final String xml, final String encoding, final String defaultEncoding) @@ -74,11 +76,13 @@ public class XmlStreamWriterTest extends checkXmlContent(xml, effectiveEncoding, defaultEncoding); } + @Test public void testNoXmlHeader() throws IOException { final String xml = "<text>text with no XML header</text>"; checkXmlContent(xml, "UTF-8", null); } + @Test public void testEmpty() throws IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final XmlStreamWriter writer = new XmlStreamWriter(out); @@ -90,6 +94,7 @@ public class XmlStreamWriterTest extends writer.close(); } + @Test public void testDefaultEncoding() throws IOException { checkXmlWriter(TEXT_UNICODE, null, null); checkXmlWriter(TEXT_UNICODE, null, "UTF-8"); @@ -98,38 +103,47 @@ public class XmlStreamWriterTest extends checkXmlWriter(TEXT_UNICODE, null, "ISO-8859-1"); } + @Test public void testUTF8Encoding() throws IOException { checkXmlWriter(TEXT_UNICODE, "UTF-8"); } + @Test public void testUTF16Encoding() throws IOException { checkXmlWriter(TEXT_UNICODE, "UTF-16"); } + @Test public void testUTF16BEEncoding() throws IOException { checkXmlWriter(TEXT_UNICODE, "UTF-16BE"); } + @Test public void testUTF16LEEncoding() throws IOException { checkXmlWriter(TEXT_UNICODE, "UTF-16LE"); } + @Test public void testLatin1Encoding() throws IOException { checkXmlWriter(TEXT_LATIN1, "ISO-8859-1"); } + @Test public void testLatin7Encoding() throws IOException { checkXmlWriter(TEXT_LATIN7, "ISO-8859-7"); } + @Test public void testLatin15Encoding() throws IOException { checkXmlWriter(TEXT_LATIN15, "ISO-8859-15"); } + @Test public void testEUC_JPEncoding() throws IOException { checkXmlWriter(TEXT_EUC_JP, "EUC-JP"); } + @Test public void testEBCDICEncoding() throws IOException { checkXmlWriter("simple text in EBCDIC", "CP1047"); } Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/testtools/FileBasedTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/testtools/FileBasedTestCase.java?rev=1718944&r1=1718943&r2=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/testtools/FileBasedTestCase.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/testtools/FileBasedTestCase.java Wed Dec 9 19:50:30 2015 @@ -16,36 +16,16 @@ */ package org.apache.commons.io.testtools; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.io.Reader; -import java.io.Writer; -import java.util.Arrays; - -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.output.ByteArrayOutputStream; +import java.io.*; /** * Base class for testcases doing tests with files. */ -public abstract class FileBasedTestCase extends TestCase { +public abstract class FileBasedTestCase { private static volatile File testDir; - public FileBasedTestCase(final String name) { - super(name); - } - + @SuppressWarnings("ResultOfMethodCallIgnored") public static File getTestDirectory() { if (testDir == null) { testDir = new File("test/io/").getAbsoluteFile(); @@ -54,191 +34,5 @@ public abstract class FileBasedTestCase return testDir; } - protected void createFile(final File file, final long size) - throws IOException { - if (!file.getParentFile().exists()) { - throw new IOException("Cannot create file " + file - + " as the parent directory does not exist"); - } - final BufferedOutputStream output = - new BufferedOutputStream(new java.io.FileOutputStream(file)); - try { - generateTestData(output, size); - } finally { - IOUtils.closeQuietly(output); - } - } - - protected byte[] generateTestData(final long size) { - try { - final ByteArrayOutputStream baout = new ByteArrayOutputStream(); - generateTestData(baout, size); - return baout.toByteArray(); - } catch (final IOException ioe) { - throw new RuntimeException("This should never happen: " + ioe.getMessage()); - } - } - - protected void generateTestData(final OutputStream out, final long size) - throws IOException { - for (int i = 0; i < size; i++) { - //output.write((byte)'X'); - - // nice varied byte pattern compatible with Readers and Writers - out.write( (byte)( (i % 127) + 1) ); - } - } - - protected void createLineBasedFile(final File file, final String[] data) throws IOException { - if (file.getParentFile() != null && !file.getParentFile().exists()) { - throw new IOException("Cannot create file " + file + " as the parent directory does not exist"); - } - final PrintWriter output = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8")); - try { - for (final String element : data) { - output.println(element); - } - } finally { - IOUtils.closeQuietly(output); - } - } - - protected File newFile(final String filename) throws IOException { - final File destination = new File( getTestDirectory(), filename ); - /* - assertTrue( filename + "Test output data file shouldn't previously exist", - !destination.exists() ); - */ - if (destination.exists()) { - FileUtils.forceDelete(destination); - } - return destination; - } - - protected void checkFile( final File file, final File referenceFile ) - throws Exception { - assertTrue( "Check existence of output file", file.exists() ); - assertEqualContent( referenceFile, file ); - } - - /** Assert that the content of two files is the same. */ - private void assertEqualContent( final File f0, final File f1 ) - throws IOException - { - /* This doesn't work because the filesize isn't updated until the file - * is closed. - assertTrue( "The files " + f0 + " and " + f1 + - " have differing file sizes (" + f0.length() + - " vs " + f1.length() + ")", ( f0.length() == f1.length() ) ); - */ - final InputStream is0 = new java.io.FileInputStream( f0 ); - try { - final InputStream is1 = new java.io.FileInputStream( f1 ); - try { - final byte[] buf0 = new byte[ 1024 ]; - final byte[] buf1 = new byte[ 1024 ]; - int n0 = 0; - int n1 = 0; - - while( -1 != n0 ) - { - n0 = is0.read( buf0 ); - n1 = is1.read( buf1 ); - assertTrue( "The files " + f0 + " and " + f1 + - " have differing number of bytes available (" + n0 + - " vs " + n1 + ")", ( n0 == n1 ) ); - - assertTrue( "The files " + f0 + " and " + f1 + - " have different content", Arrays.equals( buf0, buf1 ) ); - } - } finally { - is1.close(); - } - } finally { - is0.close(); - } - } - - /** - * Assert that the content of a file is equal to that in a byte[]. - * - * @param b0 the expected contents - * @param file the file to check - * - * @throws IOException If an I/O error occurs while reading the file contents - */ - protected void assertEqualContent(final byte[] b0, final File file) throws IOException { - final InputStream is = new java.io.FileInputStream(file); - int count = 0, numRead = 0; - final byte[] b1 = new byte[b0.length]; - try { - while (count < b0.length && numRead >= 0) { - numRead = is.read(b1, count, b0.length); - count += numRead; - } - assertEquals("Different number of bytes: ", b0.length, count); - for (int i = 0; i < count; i++) { - assertEquals("byte " + i + " differs", b0[i], b1[i]); - } - } finally { - is.close(); - } - } - - /** - * Assert that the content of a file is equal to that in a char[]. - * - * @param c0 the expected contents - * @param file the file to check - * - * @throws IOException If an I/O error occurs while reading the file contents - */ - protected void assertEqualContent(final char[] c0, final File file) throws IOException { - final Reader ir = new java.io.FileReader(file); - int count = 0, numRead = 0; - final char[] c1 = new char[c0.length]; - try { - while (count < c0.length && numRead >= 0) { - numRead = ir.read(c1, count, c0.length); - count += numRead; - } - assertEquals("Different number of chars: ", c0.length, count); - for (int i = 0; i < count; i++) { - assertEquals("char " + i + " differs", c0[i], c1[i]); - } - } finally { - ir.close(); - } - } - - protected void checkWrite(final OutputStream output) throws Exception { - try { - new java.io.PrintStream(output).write(0); - } catch (final Throwable t) { - throw new AssertionFailedError( - "The copy() method closed the stream " - + "when it shouldn't have. " - + t.getMessage()); - } - } - - protected void checkWrite(final Writer output) throws Exception { - try { - new java.io.PrintWriter(output).write('a'); - } catch (final Throwable t) { - throw new AssertionFailedError( - "The copy() method closed the stream " - + "when it shouldn't have. " - + t.getMessage()); - } - } - - protected void deleteFile( final File file ) - throws Exception { - if (file.exists()) { - assertTrue("Couldn't delete file: " + file, file.delete()); - } - } - } Copied: commons/proper/io/trunk/src/test/java/org/apache/commons/io/testtools/TestUtils.java (from r1718920, commons/proper/io/trunk/src/test/java/org/apache/commons/io/testtools/FileBasedTestCase.java) URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/testtools/TestUtils.java?p2=commons/proper/io/trunk/src/test/java/org/apache/commons/io/testtools/TestUtils.java&p1=commons/proper/io/trunk/src/test/java/org/apache/commons/io/testtools/FileBasedTestCase.java&r1=1718920&r2=1718944&rev=1718944&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/java/org/apache/commons/io/testtools/FileBasedTestCase.java (original) +++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/testtools/TestUtils.java Wed Dec 9 19:50:30 2015 @@ -16,6 +16,9 @@ */ package org.apache.commons.io.testtools; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; @@ -29,7 +32,6 @@ import java.io.Writer; import java.util.Arrays; import junit.framework.AssertionFailedError; -import junit.framework.TestCase; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; @@ -38,30 +40,20 @@ import org.apache.commons.io.output.Byte /** * Base class for testcases doing tests with files. */ -public abstract class FileBasedTestCase extends TestCase { +public abstract class TestUtils { - private static volatile File testDir; + private TestUtils() { - public FileBasedTestCase(final String name) { - super(name); } - public static File getTestDirectory() { - if (testDir == null) { - testDir = new File("test/io/").getAbsoluteFile(); - } - testDir.mkdirs(); - return testDir; - } - - protected void createFile(final File file, final long size) + public static void createFile(final File file, final long size) throws IOException { if (!file.getParentFile().exists()) { throw new IOException("Cannot create file " + file - + " as the parent directory does not exist"); + + " as the parent directory does not exist"); } final BufferedOutputStream output = - new BufferedOutputStream(new java.io.FileOutputStream(file)); + new BufferedOutputStream(new java.io.FileOutputStream(file)); try { generateTestData(output, size); } finally { @@ -69,7 +61,7 @@ public abstract class FileBasedTestCase } } - protected byte[] generateTestData(final long size) { + public static byte[] generateTestData(final long size) { try { final ByteArrayOutputStream baout = new ByteArrayOutputStream(); generateTestData(baout, size); @@ -79,8 +71,8 @@ public abstract class FileBasedTestCase } } - protected void generateTestData(final OutputStream out, final long size) - throws IOException { + public static void generateTestData(final OutputStream out, final long size) + throws IOException { for (int i = 0; i < size; i++) { //output.write((byte)'X'); @@ -89,7 +81,7 @@ public abstract class FileBasedTestCase } } - protected void createLineBasedFile(final File file, final String[] data) throws IOException { + public static void createLineBasedFile(final File file, final String[] data) throws IOException { if (file.getParentFile() != null && !file.getParentFile().exists()) { throw new IOException("Cannot create file " + file + " as the parent directory does not exist"); } @@ -103,8 +95,8 @@ public abstract class FileBasedTestCase } } - protected File newFile(final String filename) throws IOException { - final File destination = new File( getTestDirectory(), filename ); + public static File newFile(File testDirectory, final String filename) throws IOException { + final File destination = new File( testDirectory, filename ); /* assertTrue( filename + "Test output data file shouldn't previously exist", !destination.exists() ); @@ -115,15 +107,15 @@ public abstract class FileBasedTestCase return destination; } - protected void checkFile( final File file, final File referenceFile ) - throws Exception { + public static void checkFile( final File file, final File referenceFile ) + throws Exception { assertTrue( "Check existence of output file", file.exists() ); assertEqualContent( referenceFile, file ); } /** Assert that the content of two files is the same. */ - private void assertEqualContent( final File f0, final File f1 ) - throws IOException + private static void assertEqualContent( final File f0, final File f1 ) + throws IOException { /* This doesn't work because the filesize isn't updated until the file * is closed. @@ -138,18 +130,18 @@ public abstract class FileBasedTestCase final byte[] buf0 = new byte[ 1024 ]; final byte[] buf1 = new byte[ 1024 ]; int n0 = 0; - int n1 = 0; + int n1; while( -1 != n0 ) { n0 = is0.read( buf0 ); n1 = is1.read( buf1 ); assertTrue( "The files " + f0 + " and " + f1 + - " have differing number of bytes available (" + n0 + - " vs " + n1 + ")", ( n0 == n1 ) ); + " have differing number of bytes available (" + n0 + + " vs " + n1 + ")", ( n0 == n1 ) ); assertTrue( "The files " + f0 + " and " + f1 + - " have different content", Arrays.equals( buf0, buf1 ) ); + " have different content", Arrays.equals( buf0, buf1 ) ); } } finally { is1.close(); @@ -159,7 +151,7 @@ public abstract class FileBasedTestCase } } - /** + /** * Assert that the content of a file is equal to that in a byte[]. * * @param b0 the expected contents @@ -167,7 +159,7 @@ public abstract class FileBasedTestCase * * @throws IOException If an I/O error occurs while reading the file contents */ - protected void assertEqualContent(final byte[] b0, final File file) throws IOException { + public static void assertEqualContent(final byte[] b0, final File file) throws IOException { final InputStream is = new java.io.FileInputStream(file); int count = 0, numRead = 0; final byte[] b1 = new byte[b0.length]; @@ -185,7 +177,7 @@ public abstract class FileBasedTestCase } } - /** + /** * Assert that the content of a file is equal to that in a char[]. * * @param c0 the expected contents @@ -193,7 +185,7 @@ public abstract class FileBasedTestCase * * @throws IOException If an I/O error occurs while reading the file contents */ - protected void assertEqualContent(final char[] c0, final File file) throws IOException { + public static void assertEqualContent(final char[] c0, final File file) throws IOException { final Reader ir = new java.io.FileReader(file); int count = 0, numRead = 0; final char[] c1 = new char[c0.length]; @@ -211,30 +203,30 @@ public abstract class FileBasedTestCase } } - protected void checkWrite(final OutputStream output) throws Exception { + public static void checkWrite(final OutputStream output) throws Exception { try { new java.io.PrintStream(output).write(0); } catch (final Throwable t) { throw new AssertionFailedError( - "The copy() method closed the stream " - + "when it shouldn't have. " - + t.getMessage()); + "The copy() method closed the stream " + + "when it shouldn't have. " + + t.getMessage()); } } - protected void checkWrite(final Writer output) throws Exception { + public static void checkWrite(final Writer output) throws Exception { try { new java.io.PrintWriter(output).write('a'); } catch (final Throwable t) { throw new AssertionFailedError( - "The copy() method closed the stream " - + "when it shouldn't have. " - + t.getMessage()); + "The copy() method closed the stream " + + "when it shouldn't have. " + + t.getMessage()); } } - protected void deleteFile( final File file ) - throws Exception { + public static void deleteFile( final File file ) + throws Exception { if (file.exists()) { assertTrue("Couldn't delete file: " + file, file.delete()); }
