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    *      https://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  package org.apache.commons.io.build;
18  
19  import static org.junit.jupiter.api.Assertions.assertThrows;
20  
21  import java.io.FileNotFoundException;
22  import java.io.FileReader;
23  import java.io.Reader;
24  import java.nio.file.OpenOption;
25  import java.nio.file.StandardOpenOption;
26  
27  import org.apache.commons.io.build.AbstractOrigin.ReaderOrigin;
28  import org.apache.commons.io.input.CharSequenceReader;
29  import org.junit.jupiter.api.Test;
30  import org.junit.jupiter.params.ParameterizedTest;
31  import org.junit.jupiter.params.provider.EnumSource;
32  
33  /**
34   * Tests {@link ReaderOrigin}.
35   *
36   * A ReaderOrigin can convert into some of the other aspects.
37   *
38   * @see Reader
39   */
40  class ReaderOriginTest extends AbstractOriginTest<Reader, ReaderOrigin> {
41  
42      @Override
43      protected ReaderOrigin newOriginRo() throws FileNotFoundException {
44          return new ReaderOrigin(new FileReader(FILE_NAME_RO));
45      }
46  
47      @Override
48      protected ReaderOrigin newOriginRw() {
49          return new ReaderOrigin(new CharSequenceReader("World"));
50      }
51  
52      @Override
53      @Test
54      void testGetFile() {
55          // Cannot convert a Reader to a File.
56          assertThrows(UnsupportedOperationException.class, super::testGetFile);
57      }
58  
59      @Override
60      @Test
61      void testGetOutputStream() {
62          // Cannot convert a Reader to an OutputStream.
63          assertThrows(UnsupportedOperationException.class, super::testGetOutputStream);
64      }
65  
66      @Override
67      @Test
68      void testGetPath() {
69          // Cannot convert a Reader to a Path.
70          assertThrows(UnsupportedOperationException.class, super::testGetPath);
71      }
72  
73      @Override
74      @Test
75      void testGetRandomAccessFile() {
76          // Cannot convert a RandomAccessFile to a File.
77          assertThrows(UnsupportedOperationException.class, super::testGetRandomAccessFile);
78      }
79  
80      @Override
81      @ParameterizedTest
82      @EnumSource(StandardOpenOption.class)
83      void testGetRandomAccessFile(final OpenOption openOption) {
84          // Cannot convert a RandomAccessFile to a File.
85          assertThrows(UnsupportedOperationException.class, () -> super.testGetRandomAccessFile(openOption));
86      }
87  
88      @Override
89      @Test
90      void testGetWriter() {
91          // Cannot convert a Reader to a Writer.
92          assertThrows(UnsupportedOperationException.class, super::testGetWriter);
93      }
94  
95  }