4b8c9dce89dbcf14e24fdf33eea08942b2ad4d5b
[aaf/authz.git] / misc / env / src / test / java / org / onap / aaf / misc / env / util / JU_DoubleOutputStreamTest.java
1 /**\r
2  * ============LICENSE_START====================================================\r
3  * org.onap.aaf\r
4  * ===========================================================================\r
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
6  * ===========================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END====================================================\r
19  *\r
20  */\r
21 package org.onap.aaf.misc.env.util;\r
22 \r
23 import static org.mockito.Mockito.mock;\r
24 import static org.mockito.Mockito.never;\r
25 import static org.mockito.Mockito.only;\r
26 import static org.mockito.Mockito.verify;\r
27 \r
28 import java.io.IOException;\r
29 import java.io.OutputStream;\r
30 \r
31 import org.junit.Before;\r
32 import org.junit.Test;\r
33 import org.mockito.Mock;\r
34 \r
35 public class JU_DoubleOutputStreamTest {\r
36 \r
37         @Mock\r
38         private OutputStream stream1;\r
39 \r
40         @Mock\r
41         private OutputStream stream2;\r
42 \r
43         private DoubleOutputStream doubleOutputStream;\r
44 \r
45         @Before\r
46         public void setup() {\r
47                 stream1 = mock(OutputStream.class);\r
48                 stream2 = mock(OutputStream.class);\r
49         }\r
50 \r
51         @Test\r
52         public void testWriteInt() throws IOException {\r
53                 doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);\r
54 \r
55                 doubleOutputStream.write(123);\r
56 \r
57                 verify(stream1, only()).write(123);\r
58                 verify(stream2, only()).write(123);\r
59         }\r
60 \r
61         @Test\r
62         public void testWriteByteArray() throws IOException {\r
63                 doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);\r
64 \r
65                 byte[] bytes = { 1, 2, 3, 4 };\r
66 \r
67                 doubleOutputStream.write(bytes);\r
68 \r
69                 verify(stream1, only()).write(bytes);\r
70                 verify(stream2, only()).write(bytes);\r
71 \r
72         }\r
73 \r
74         @Test\r
75         public void testWriteByteArrayWithOffset() throws IOException {\r
76                 doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);\r
77 \r
78                 byte[] bytes = { 1, 2, 3, 4 };\r
79 \r
80                 doubleOutputStream.write(bytes, 1, 3);\r
81                 verify(stream1, only()).write(bytes, 1, 3);\r
82                 verify(stream2, only()).write(bytes, 1, 3);\r
83         }\r
84 \r
85         @Test\r
86         public void testFlush() throws IOException {\r
87                 doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);\r
88 \r
89                 doubleOutputStream.flush();\r
90 \r
91                 verify(stream1, only()).flush();\r
92                 verify(stream2, only()).flush();\r
93         }\r
94 \r
95         @Test\r
96         public void testClose() throws IOException {\r
97                 doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, false);\r
98 \r
99                 doubleOutputStream.close();\r
100 \r
101                 verify(stream1, only()).close();\r
102                 verify(stream2, never()).close();\r
103         }\r
104 }\r