Skip to content

Commit 4d49a19

Browse files
committed
Converted all tests to JUnit4
Test count is 1157 as oppsoed to 1156 because JUnit4 counts @ignored tests as run. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1718944 13f79535-47bb-0310-9956-ffa450edef68
1 parent 234b006 commit 4d49a19

76 files changed

Lines changed: 2808 additions & 1555 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/test/java/org/apache/commons/io/ByteOrderMarkTestCase.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,41 @@
1616
*/
1717
package org.apache.commons.io;
1818

19+
1920
import java.nio.charset.Charset;
2021
import java.util.Arrays;
2122

22-
import org.apache.commons.io.testtools.FileBasedTestCase;
23+
import org.junit.Test;
24+
25+
import static org.junit.Assert.assertEquals;
26+
import static org.junit.Assert.assertFalse;
27+
import static org.junit.Assert.assertNotNull;
28+
import static org.junit.Assert.assertTrue;
29+
import static org.junit.Assert.fail;
2330

2431

2532
/**
2633
* Test for {@link ByteOrderMark}.
2734
*
2835
* @version $Id$
2936
*/
30-
public class ByteOrderMarkTestCase extends FileBasedTestCase {
37+
public class ByteOrderMarkTestCase {
3138

3239
private static final ByteOrderMark TEST_BOM_1 = new ByteOrderMark("test1", 1);
3340
private static final ByteOrderMark TEST_BOM_2 = new ByteOrderMark("test2", 1, 2);
3441
private static final ByteOrderMark TEST_BOM_3 = new ByteOrderMark("test3", 1, 2, 3);
3542

36-
public ByteOrderMarkTestCase(final String name) {
37-
super(name);
38-
}
39-
4043
/** Test {@link ByteOrderMark#getCharsetName()} */
41-
public void testCharsetName() {
44+
@Test
45+
public void charsetName() {
4246
assertEquals("test1 name", "test1", TEST_BOM_1.getCharsetName());
4347
assertEquals("test2 name", "test2", TEST_BOM_2.getCharsetName());
4448
assertEquals("test3 name", "test3", TEST_BOM_3.getCharsetName());
4549
}
4650

4751
/** Tests that {@link ByteOrderMark#getCharsetName()} can be loaded as a {@link java.nio.charset.Charset} as advertised. */
48-
public void testConstantCharsetNames() {
52+
@Test
53+
public void constantCharsetNames() {
4954
assertNotNull(Charset.forName(ByteOrderMark.UTF_8.getCharsetName()));
5055
assertNotNull(Charset.forName(ByteOrderMark.UTF_16BE.getCharsetName()));
5156
assertNotNull(Charset.forName(ByteOrderMark.UTF_16LE.getCharsetName()));
@@ -54,14 +59,15 @@ public void testConstantCharsetNames() {
5459
}
5560

5661
/** Test {@link ByteOrderMark#length()} */
57-
public void testLength() {
58-
assertEquals("test1 length", 1, TEST_BOM_1.length());
62+
@Test
63+
public void testLength() { assertEquals("test1 length", 1, TEST_BOM_1.length());
5964
assertEquals("test2 length", 2, TEST_BOM_2.length());
6065
assertEquals("test3 length", 3, TEST_BOM_3.length());
6166
}
6267

6368
/** Test {@link ByteOrderMark#get(int)} */
64-
public void testGet() {
69+
@Test
70+
public void get() {
6571
assertEquals("test1 get(0)", 1, TEST_BOM_1.get(0));
6672
assertEquals("test2 get(0)", 1, TEST_BOM_2.get(0));
6773
assertEquals("test2 get(1)", 2, TEST_BOM_2.get(1));
@@ -71,13 +77,16 @@ public void testGet() {
7177
}
7278

7379
/** Test {@link ByteOrderMark#getBytes()} */
74-
public void testGetBytes() {
80+
@Test
81+
public void getBytes() {
7582
assertTrue("test1 bytes", Arrays.equals(TEST_BOM_1.getBytes(), new byte[] {(byte)1}));
7683
assertTrue("test1 bytes", Arrays.equals(TEST_BOM_2.getBytes(), new byte[] {(byte)1, (byte)2}));
7784
assertTrue("test1 bytes", Arrays.equals(TEST_BOM_3.getBytes(), new byte[] {(byte)1, (byte)2, (byte)3}));
7885
}
7986

8087
/** Test {@link ByteOrderMark#equals(Object)} */
88+
@SuppressWarnings("EqualsWithItself")
89+
@Test
8190
public void testEquals() {
8291
assertTrue("test1 equals", TEST_BOM_1.equals(TEST_BOM_1));
8392
assertTrue("test2 equals", TEST_BOM_2.equals(TEST_BOM_2));
@@ -91,6 +100,7 @@ public void testEquals() {
91100
}
92101

93102
/** Test {@link ByteOrderMark#hashCode()} */
103+
@Test
94104
public void testHashCode() {
95105
final int bomClassHash = ByteOrderMark.class.hashCode();
96106
assertEquals("hash test1 ", bomClassHash + 1, TEST_BOM_1.hashCode());
@@ -99,7 +109,8 @@ public void testHashCode() {
99109
}
100110

101111
/** Test Erros */
102-
public void testErrors() {
112+
@Test
113+
public void errors() {
103114
try {
104115
new ByteOrderMark(null, 1,2,3);
105116
fail("null charset name, expected IllegalArgumentException");
@@ -127,6 +138,7 @@ public void testErrors() {
127138
}
128139

129140
/** Test {@link ByteOrderMark#toString()} */
141+
@Test
130142
public void testToString() {
131143
assertEquals("test1 ", "ByteOrderMark[test1: 0x1]", TEST_BOM_1.toString());
132144
assertEquals("test2 ", "ByteOrderMark[test2: 0x1,0x2]", TEST_BOM_2.toString());

src/test/java/org/apache/commons/io/CopyUtilsTest.java

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,15 @@
2626

2727
import org.apache.commons.io.output.ByteArrayOutputStream;
2828
import org.apache.commons.io.testtools.FileBasedTestCase;
29+
import org.apache.commons.io.testtools.TestUtils;
2930
import org.apache.commons.io.testtools.YellOnCloseInputStream;
3031
import org.apache.commons.io.testtools.YellOnFlushAndCloseOutputStream;
32+
import org.junit.After;
33+
import org.junit.Before;
34+
import org.junit.Test;
35+
36+
import static org.junit.Assert.assertEquals;
37+
import static org.junit.Assert.assertTrue;
3138

3239
@SuppressWarnings("deprecation") // these are test cases for the deprecated CopyUtils
3340

@@ -49,34 +56,20 @@ public class CopyUtilsTest extends FileBasedTestCase {
4956
private static final int FILE_SIZE = 1024 * 4 + 1;
5057

5158

52-
private final byte[] inData = generateTestData(FILE_SIZE);
53-
54-
public CopyUtilsTest(final String testName) {
55-
super(testName);
56-
}
57-
58-
// ----------------------------------------------------------------
59-
// Setup
60-
// ----------------------------------------------------------------
61-
62-
@Override
63-
public void setUp() throws Exception {
64-
}
65-
66-
@Override
67-
public void tearDown() throws Exception {
68-
}
59+
private final byte[] inData = TestUtils.generateTestData((long) FILE_SIZE);
6960

7061
// ----------------------------------------------------------------
7162
// Tests
7263
// ----------------------------------------------------------------
7364

65+
@Test
7466
public void testCtor() {
7567
new CopyUtils();
7668
// Nothing to assert, the constructor is public and does not blow up.
7769
}
7870

79-
public void testCopy_byteArrayToOutputStream() throws Exception {
71+
@Test
72+
public void copy_byteArrayToOutputStream() throws Exception {
8073
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
8174
final OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true);
8275

@@ -86,7 +79,8 @@ public void testCopy_byteArrayToOutputStream() throws Exception {
8679
assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
8780
}
8881

89-
public void testCopy_byteArrayToWriter() throws Exception {
82+
@Test
83+
public void copy_byteArrayToWriter() throws Exception {
9084
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
9185
final OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true);
9286
final Writer writer = new java.io.OutputStreamWriter(out, "US-ASCII");
@@ -98,6 +92,7 @@ public void testCopy_byteArrayToWriter() throws Exception {
9892
assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
9993
}
10094

95+
@Test
10196
public void testCopy_byteArrayToWriterWithEncoding() throws Exception {
10297
final String inDataStr = "data";
10398
final String charsetName = "UTF-8";
@@ -107,6 +102,7 @@ public void testCopy_byteArrayToWriterWithEncoding() throws Exception {
107102
}
108103

109104
@SuppressWarnings("resource") // 'in' is deliberately not closed
105+
@Test
110106
public void testCopy_inputStreamToOutputStream() throws Exception {
111107
InputStream in = new ByteArrayInputStream(inData);
112108
in = new YellOnCloseInputStream(in);
@@ -123,7 +119,8 @@ public void testCopy_inputStreamToOutputStream() throws Exception {
123119
}
124120

125121
@SuppressWarnings("resource") // 'in' is deliberately not closed
126-
public void testCopy_inputStreamToWriter() throws Exception {
122+
@Test
123+
public void copy_inputStreamToWriter() throws Exception {
127124
InputStream in = new ByteArrayInputStream(inData);
128125
in = new YellOnCloseInputStream(in);
129126

@@ -139,7 +136,8 @@ public void testCopy_inputStreamToWriter() throws Exception {
139136
assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
140137
}
141138

142-
public void testCopy_inputStreamToWriterWithEncoding() throws Exception {
139+
@Test
140+
public void copy_inputStreamToWriterWithEncoding() throws Exception {
143141
final String inDataStr = "data";
144142
final String charsetName = "UTF-8";
145143
final StringWriter writer = new StringWriter();
@@ -148,6 +146,7 @@ public void testCopy_inputStreamToWriterWithEncoding() throws Exception {
148146
}
149147

150148
@SuppressWarnings("resource") // 'in' is deliberately not closed
149+
@Test
151150
public void testCopy_readerToOutputStream() throws Exception {
152151
InputStream in = new ByteArrayInputStream(inData);
153152
in = new YellOnCloseInputStream(in);
@@ -169,7 +168,8 @@ public void testCopy_readerToOutputStream() throws Exception {
169168
}
170169

171170
@SuppressWarnings("resource") // 'in' is deliberately not closed
172-
public void testCopy_readerToWriter() throws Exception {
171+
@Test
172+
public void copy_readerToWriter() throws Exception {
173173
InputStream in = new ByteArrayInputStream(inData);
174174
in = new YellOnCloseInputStream(in);
175175
final Reader reader = new java.io.InputStreamReader(in, "US-ASCII");
@@ -188,7 +188,8 @@ public void testCopy_readerToWriter() throws Exception {
188188
assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
189189
}
190190

191-
public void testCopy_stringToOutputStream() throws Exception {
191+
@Test
192+
public void copy_stringToOutputStream() throws Exception {
192193
final String str = new String(inData, "US-ASCII");
193194

194195
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
@@ -206,7 +207,8 @@ public void testCopy_stringToOutputStream() throws Exception {
206207
assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray()));
207208
}
208209

209-
public void testCopy_stringToWriter() throws Exception {
210+
@Test
211+
public void copy_stringToWriter() throws Exception {
210212
final String str = new String(inData, "US-ASCII");
211213

212214
final ByteArrayOutputStream baout = new ByteArrayOutputStream();

0 commit comments

Comments
 (0)