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