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