Skip to content

Commit 6a811a9

Browse files
committed
Port to JUnit 4 and more tests while working out possible issue with UTF-32.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1371719 13f79535-47bb-0310-9956-ffa450edef68
1 parent d9268be commit 6a811a9

1 file changed

Lines changed: 61 additions & 2 deletions

File tree

src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java

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

19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertNotNull;
22+
import static org.junit.Assert.assertNull;
23+
import static org.junit.Assert.assertTrue;
24+
import static org.junit.Assert.fail;
25+
1926
import java.io.ByteArrayInputStream;
2027
import java.io.IOException;
2128
import java.io.InputStream;
2229
import java.nio.charset.Charset;
2330

24-
import junit.framework.TestCase;
31+
import javax.xml.parsers.DocumentBuilderFactory;
2532

2633
import org.apache.commons.io.ByteOrderMark;
2734
import org.apache.commons.io.Charsets;
2835
import org.junit.Assert;
2936
import org.junit.Assume;
37+
import org.junit.Ignore;
3038
import org.junit.Test;
39+
import org.w3c.dom.Document;
40+
import org.xml.sax.InputSource;
3141

3242
/**
3343
* Test case for {@link BOMInputStream}.
3444
*
3545
* @version $Id$
3646
*/
37-
public class BOMInputStreamTest extends TestCase {
47+
public class BOMInputStreamTest {
3848
//----------------------------------------------------------------------------
3949
// Support code
4050
//----------------------------------------------------------------------------
@@ -219,6 +229,55 @@ public void testReadWithBOMUtf8() throws Exception {
219229
}
220230
}
221231

232+
@Test
233+
public void testReadXmlWithBOMUtf8() throws Exception {
234+
byte[] data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><X/>".getBytes(Charsets.UTF_8);
235+
BOMInputStream in = new BOMInputStream(createUtf8DataStream(data, true));
236+
final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(in));
237+
assertNotNull(doc);
238+
assertEquals("X", doc.getFirstChild().getNodeName());
239+
}
240+
241+
@Test
242+
public void testReadXmlWithBOMUtf16Be() throws Exception {
243+
byte[] data = "<?xml version=\"1.0\" encoding=\"UTF-16BE\"?><X/>".getBytes(Charsets.UTF_16BE);
244+
BOMInputStream in = new BOMInputStream(createUtf16BeDataStream(data, true));
245+
final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(in));
246+
assertNotNull(doc);
247+
assertEquals("X", doc.getFirstChild().getNodeName());
248+
}
249+
250+
@Test
251+
public void testReadXmlWithBOMUtf16Le() throws Exception {
252+
byte[] data = "<?xml version=\"1.0\" encoding=\"UTF-16LE\"?><X/>".getBytes(Charsets.UTF_16LE);
253+
BOMInputStream in = new BOMInputStream(createUtf16LeDataStream(data, true));
254+
final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(in));
255+
assertNotNull(doc);
256+
assertEquals("X", doc.getFirstChild().getNodeName());
257+
}
258+
259+
@Ignore
260+
@Test
261+
public void testReadXmlWithBOMUtf32Be() throws Exception {
262+
Assume.assumeTrue(Charset.isSupported("UTF_32BE"));
263+
byte[] data = "<?xml version=\"1.0\" encoding=\"UTF-32BE\"?><X/>".getBytes("UTF_32BE");
264+
BOMInputStream in = new BOMInputStream(createUtf32BeDataStream(data, true));
265+
final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(in));
266+
assertNotNull(doc);
267+
assertEquals("X", doc.getFirstChild().getNodeName());
268+
}
269+
270+
@Ignore
271+
@Test
272+
public void testReadXmlWithBOMUtf32Le() throws Exception {
273+
Assume.assumeTrue(Charset.isSupported("UTF_32LE"));
274+
byte[] data = "<?xml version=\"1.0\" encoding=\"UTF-32LE\"?><X/>".getBytes("UTF_32LE");
275+
BOMInputStream in = new BOMInputStream(createUtf32LeDataStream(data, true));
276+
final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(in));
277+
assertNotNull(doc);
278+
assertEquals("X", doc.getFirstChild().getNodeName());
279+
}
280+
222281
@Test
223282
public void testReadWithBOMUtf16Be() throws Exception {
224283
byte[] data = "ABC".getBytes(Charsets.UTF_16BE);

0 commit comments

Comments
 (0)