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.OutputStream;
22  import java.nio.file.OpenOption;
23  import java.nio.file.StandardOpenOption;
24  
25  import org.apache.commons.io.build.AbstractOrigin.OutputStreamOrigin;
26  import org.apache.commons.io.output.ByteArrayOutputStream;
27  import org.junit.jupiter.api.Test;
28  import org.junit.jupiter.params.ParameterizedTest;
29  import org.junit.jupiter.params.provider.EnumSource;
30  
31  /**
32   * Tests {@link OutputStreamOrigin}.
33   *
34   * A OutputStreamOrigin can convert into some of the other aspects.
35   *
36   * @see OutputStream
37   */
38  class OutputStreamOriginTest extends AbstractOriginTest<OutputStream, OutputStreamOrigin> {
39  
40      @Override
41      protected OutputStreamOrigin newOriginRo() {
42          return new OutputStreamOrigin(new ByteArrayOutputStream());
43      }
44  
45      @Override
46      protected OutputStreamOrigin newOriginRw() {
47          return new OutputStreamOrigin(new ByteArrayOutputStream());
48      }
49  
50      @Override
51      @Test
52      void testGetByteArray() {
53          // Cannot convert a OutputStream to a byte[].
54          assertThrows(UnsupportedOperationException.class, super::testGetByteArray);
55      }
56  
57      @Override
58      @Test
59      void testGetByteArrayAt_0_0() {
60          // Cannot convert a OutputStream to a byte[].
61          assertThrows(UnsupportedOperationException.class, super::testGetByteArrayAt_0_0);
62      }
63  
64      @Override
65      @Test
66      void testGetByteArrayAt_0_1() {
67          // Cannot convert a OutputStream to a byte[].
68          assertThrows(UnsupportedOperationException.class, super::testGetByteArrayAt_0_1);
69      }
70  
71      @Override
72      @Test
73      void testGetByteArrayAt_1_1() {
74          // Cannot convert a OutputStream to a byte[].
75          assertThrows(UnsupportedOperationException.class, super::testGetByteArrayAt_1_1);
76      }
77  
78      @Override
79      @Test
80      void testGetCharSequence() {
81          // Cannot convert a OutputStream to a CharSequence.
82          assertThrows(UnsupportedOperationException.class, super::testGetCharSequence);
83      }
84  
85      @Override
86      @Test
87      void testGetFile() {
88          // Cannot convert a OutputStream to a File.
89          assertThrows(UnsupportedOperationException.class, super::testGetFile);
90      }
91  
92      @Override
93      @Test
94      void testGetInputStream() {
95          // Cannot convert a OutputStream to an InputStream.
96          assertThrows(UnsupportedOperationException.class, super::testGetInputStream);
97      }
98  
99      @Override
100     @Test
101     void testGetPath() {
102         // Cannot convert a OutputStream to a Path.
103         assertThrows(UnsupportedOperationException.class, super::testGetPath);
104     }
105 
106     @Override
107     @Test
108     void testGetRandomAccessFile() {
109         // Cannot convert a RandomAccessFile to a File.
110         assertThrows(UnsupportedOperationException.class, super::testGetRandomAccessFile);
111     }
112 
113     @Override
114     @ParameterizedTest
115     @EnumSource(StandardOpenOption.class)
116     void testGetRandomAccessFile(final OpenOption openOption) {
117         // Cannot convert a RandomAccessFile to a File.
118         assertThrows(UnsupportedOperationException.class, () -> super.testGetRandomAccessFile(openOption));
119     }
120 
121     @Override
122     @Test
123     void testGetReader() {
124         // Cannot convert a OutputStream to a Reader.
125         assertThrows(UnsupportedOperationException.class, super::testGetReader);
126     }
127 
128     @Override
129     @Test
130     void testSize() {
131         // Cannot convert a Writer to a size.
132         assertThrows(UnsupportedOperationException.class, super::testSize);
133     }
134 
135 }