View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   */ 
19  package org.apache.rat.document.impl;
20  
21  import org.apache.rat.api.Document;
22  import org.apache.rat.test.utils.Resources;
23  import org.junit.Before;
24  import org.junit.Test;
25  
26  import java.io.BufferedReader;
27  import java.io.File;
28  import java.io.Reader;
29  
30  import static org.junit.Assert.assertEquals;
31  import static org.junit.Assert.assertNotNull;
32  
33  public class SingularFileDocumentTest {
34      private Document document;
35      private File file;
36      
37      @Before
38      public void setUp() throws Exception {
39          file = Resources.getResourceFile("elements/Source.java");
40          document = new MonolithicFileDocument(file);
41      }
42  
43      @Test
44      public void reader() throws Exception {
45          Reader reader = document.reader();
46          assertNotNull("Reader should be returned", reader);
47          assertEquals("First file line expected", "package elements;", 
48                   new BufferedReader(reader).readLine());
49      }
50  
51      @Test
52      public void getName() {
53          final String name = document.getName();
54          assertNotNull("Name is set", name);
55          assertEquals("Name is filename", DocumentImplUtils.toName(file), name);
56      }
57  }