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    *      http://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  
23  import org.apache.commons.io.build.AbstractOrigin.OutputStreamOrigin;
24  import org.apache.commons.io.output.ByteArrayOutputStream;
25  import org.junit.jupiter.api.BeforeEach;
26  import org.junit.jupiter.api.Test;
27  
28  /**
29   * Tests {@link OutputStreamOrigin}.
30   *
31   * A OutputStreamOrigin can convert into some of the other aspects.
32   */
33  public class OutputStreamOriginTest extends AbstractOriginTest<OutputStream, OutputStreamOrigin> {
34  
35      @SuppressWarnings("resource")
36      @BeforeEach
37      public void beforeEach() {
38          setOriginRo(new OutputStreamOrigin(new ByteArrayOutputStream()));
39          setOriginRw(new OutputStreamOrigin(new ByteArrayOutputStream()));
40      }
41  
42      @Override
43      @Test
44      public void testGetByteArray() {
45          // Cannot convert a OutputStream to a byte[].
46          assertThrows(UnsupportedOperationException.class, super::testGetByteArray);
47      }
48  
49      @Override
50      @Test
51      public void testGetByteArrayAt_0_0() {
52          // Cannot convert a OutputStream to a byte[].
53          assertThrows(UnsupportedOperationException.class, super::testGetByteArrayAt_0_0);
54      }
55  
56      @Override
57      @Test
58      public void testGetByteArrayAt_0_1() {
59          // Cannot convert a OutputStream to a byte[].
60          assertThrows(UnsupportedOperationException.class, super::testGetByteArrayAt_0_1);
61      }
62  
63      @Override
64      @Test
65      public void testGetByteArrayAt_1_1() {
66          // Cannot convert a OutputStream to a byte[].
67          assertThrows(UnsupportedOperationException.class, super::testGetByteArrayAt_1_1);
68      }
69  
70      @Override
71      @Test
72      public void testGetCharSequence() {
73          // Cannot convert a OutputStream to a CharSequence.
74          assertThrows(UnsupportedOperationException.class, super::testGetCharSequence);
75      }
76  
77      @Override
78      @Test
79      public void testGetFile() {
80          // Cannot convert a OutputStream to a File.
81          assertThrows(UnsupportedOperationException.class, super::testGetFile);
82      }
83  
84      @Override
85      @Test
86      public void testGetInputStream() {
87          // Cannot convert a OutputStream to an InputStream.
88          assertThrows(UnsupportedOperationException.class, super::testGetInputStream);
89      }
90  
91      @Override
92      @Test
93      public void testGetPath() {
94          // Cannot convert a OutputStream to a Path.
95          assertThrows(UnsupportedOperationException.class, super::testGetPath);
96      }
97  
98      @Override
99      @Test
100     public void testGetReader() {
101         // Cannot convert a OutputStream to a Reader.
102         assertThrows(UnsupportedOperationException.class, super::testGetReader);
103     }
104 
105     @Override
106     @Test
107     public void testSize() {
108         // Cannot convert a Writer to a size.
109         assertThrows(UnsupportedOperationException.class, super::testSize);
110     }
111 
112 }