This project has retired. For details please refer to its Attic page.
CSVReaderBuilderTest xref
View Javadoc
1   /*
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
8    *
9    *  http://www.apache.org/licenses/LICENSE-2.0
10   *
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.
16   */
17  
18  package org.apache.any23.extractor.csv;
19  
20  import org.junit.Assert;
21  import org.junit.Test;
22  
23  import java.io.BufferedInputStream;
24  import java.io.IOException;
25  
26  /**
27   * Test case for {@link CSVReaderBuilder}.
28   *
29   * @author Michele Mostarda (mostarda@fbk.eu)
30   */
31  public class CSVReaderBuilderTest {
32  
33      /**
34       * Tests positive CSV detection.
35       *
36       * @throws IOException
37       *             if there is an error interpreting the input data
38       */
39      @Test
40      public void testPositiveCSVDetection() throws IOException {
41          Assert.assertTrue("Builder cannot detect CVS stream.",
42                  CSVReaderBuilder.isCSV(new BufferedInputStream(this.getClass().getResourceAsStream("test-comma.csv"))));
43          Assert.assertTrue("Builder cannot detect CVS stream.", CSVReaderBuilder
44                  .isCSV(new BufferedInputStream(this.getClass().getResourceAsStream("test-semicolon.csv"))));
45          Assert.assertTrue("Builder cannot detect CVS stream.",
46                  CSVReaderBuilder.isCSV(new BufferedInputStream(this.getClass().getResourceAsStream("test-tab.csv"))));
47      }
48  
49      /**
50       * Tests negative CSV detection.
51       *
52       * @throws IOException
53       *             if there is an error interpreting the input data
54       */
55      @Test
56      public void testNegativeCSVDetection() throws IOException {
57          Assert.assertFalse("Wrong CSV detection.", CSVReaderBuilder
58                  .isCSV(new BufferedInputStream(this.getClass().getResourceAsStream("/application/nquads/test1.nq"))));
59          Assert.assertFalse("Wrong CSV detection.", CSVReaderBuilder
60                  .isCSV(new BufferedInputStream(this.getClass().getResourceAsStream("/application/nquads/test2.nq"))));
61          Assert.assertFalse("Wrong CSV detection.", CSVReaderBuilder.isCSV(new BufferedInputStream(
62                  this.getClass().getResourceAsStream("/org/apache/any23/extractor/rdf/example-ntriples.nt"))));
63      }
64  
65  }