2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package org
.apache
.tika
.parser
;
19 import java
.io
.ByteArrayInputStream
;
20 import java
.io
.InputStream
;
21 import java
.io
.Reader
;
23 import junit
.framework
.TestCase
;
25 public class ParsingReaderTest
extends TestCase
{
27 public void testPlainText() throws Exception
{
28 String data
= "test content";
29 InputStream stream
= new ByteArrayInputStream(data
.getBytes("UTF-8"));
30 Reader reader
= new ParsingReader(stream
, "test.txt");
31 assertEquals('t', reader
.read());
32 assertEquals('e', reader
.read());
33 assertEquals('s', reader
.read());
34 assertEquals('t', reader
.read());
35 assertEquals(' ', reader
.read());
36 assertEquals('c', reader
.read());
37 assertEquals('o', reader
.read());
38 assertEquals('n', reader
.read());
39 assertEquals('t', reader
.read());
40 assertEquals('e', reader
.read());
41 assertEquals('n', reader
.read());
42 assertEquals('t', reader
.read());
43 assertEquals(-1, reader
.read());
45 assertEquals(-1, stream
.read());
48 public void testXML() throws Exception
{
49 String data
= "<p>test <span>content</span></p>";
50 InputStream stream
= new ByteArrayInputStream(data
.getBytes("UTF-8"));
51 Reader reader
= new ParsingReader(stream
, "test.xml");
52 assertEquals('t', reader
.read());
53 assertEquals('e', reader
.read());
54 assertEquals('s', reader
.read());
55 assertEquals('t', reader
.read());
56 assertEquals(' ', reader
.read());
57 assertEquals('c', reader
.read());
58 assertEquals('o', reader
.read());
59 assertEquals('n', reader
.read());
60 assertEquals('t', reader
.read());
61 assertEquals('e', reader
.read());
62 assertEquals('n', reader
.read());
63 assertEquals('t', reader
.read());
64 assertEquals(-1, reader
.read());
66 assertEquals(-1, stream
.read());