Mass add newline package (Style Warnings)
[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 \r
22 package org.onap.aaf.misc.env.util;\r
23 \r
24 import static org.mockito.Mockito.mock;\r
25 import static org.mockito.Mockito.never;\r
26 import static org.mockito.Mockito.only;\r
27 import static org.mockito.Mockito.verify;\r
28 \r
29 import java.io.IOException;\r
30 import java.io.OutputStream;\r
31 \r
32 import org.junit.Before;\r
33 import org.junit.Test;\r
34 import org.mockito.Mock;\r
35 \r
36 public class JU_DoubleOutputStreamTest {\r
37 \r
38     @Mock\r
39     private OutputStream stream1;\r
40 \r
41     @Mock\r
42     private OutputStream stream2;\r
43 \r
44     private DoubleOutputStream doubleOutputStream;\r
45 \r
46     @Before\r
47     public void setup() {\r
48         stream1 = mock(OutputStream.class);\r
49         stream2 = mock(OutputStream.class);\r
50     }\r
51 \r
52     @Test\r
53     public void testWriteInt() throws IOException {\r
54         doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);\r
55 \r
56         doubleOutputStream.write(123);\r
57 \r
58         verify(stream1, only()).write(123);\r
59         verify(stream2, only()).write(123);\r
60     }\r
61 \r
62     @Test\r
63     public void testWriteByteArray() throws IOException {\r
64         doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);\r
65 \r
66         byte[] bytes = { 1, 2, 3, 4 };\r
67 \r
68         doubleOutputStream.write(bytes);\r
69 \r
70         verify(stream1, only()).write(bytes);\r
71         verify(stream2, only()).write(bytes);\r
72 \r
73     }\r
74 \r
75     @Test\r
76     public void testWriteByteArrayWithOffset() throws IOException {\r
77         doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);\r
78 \r
79         byte[] bytes = { 1, 2, 3, 4 };\r
80 \r
81         doubleOutputStream.write(bytes, 1, 3);\r
82         verify(stream1, only()).write(bytes, 1, 3);\r
83         verify(stream2, only()).write(bytes, 1, 3);\r
84     }\r
85 \r
86     @Test\r
87     public void testFlush() throws IOException {\r
88         doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);\r
89 \r
90         doubleOutputStream.flush();\r
91 \r
92         verify(stream1, only()).flush();\r
93         verify(stream2, only()).flush();\r
94     }\r
95 \r
96     @Test\r
97     public void testClose() throws IOException {\r
98         doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, false);\r
99 \r
100         doubleOutputStream.close();\r
101 \r
102         verify(stream1, only()).close();\r
103         verify(stream2, never()).close();\r
104     }\r
105 }\r