2 * ============LICENSE_START====================================================
\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
11 * http://www.apache.org/licenses/LICENSE-2.0
\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
21 package org.onap.aaf.misc.env.util;
\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
28 import java.io.IOException;
\r
29 import java.io.OutputStream;
\r
31 import org.junit.Before;
\r
32 import org.junit.Test;
\r
33 import org.mockito.Mock;
\r
35 public class JU_DoubleOutputStreamTest {
\r
38 private OutputStream stream1;
\r
41 private OutputStream stream2;
\r
43 private DoubleOutputStream doubleOutputStream;
\r
46 public void setup() {
\r
47 stream1 = mock(OutputStream.class);
\r
48 stream2 = mock(OutputStream.class);
\r
52 public void testWriteInt() throws IOException {
\r
53 doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);
\r
55 doubleOutputStream.write(123);
\r
57 verify(stream1, only()).write(123);
\r
58 verify(stream2, only()).write(123);
\r
62 public void testWriteByteArray() throws IOException {
\r
63 doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);
\r
65 byte[] bytes = { 1, 2, 3, 4 };
\r
67 doubleOutputStream.write(bytes);
\r
69 verify(stream1, only()).write(bytes);
\r
70 verify(stream2, only()).write(bytes);
\r
75 public void testWriteByteArrayWithOffset() throws IOException {
\r
76 doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);
\r
78 byte[] bytes = { 1, 2, 3, 4 };
\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
86 public void testFlush() throws IOException {
\r
87 doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);
\r
89 doubleOutputStream.flush();
\r
91 verify(stream1, only()).flush();
\r
92 verify(stream2, only()).flush();
\r
96 public void testClose() throws IOException {
\r
97 doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, false);
\r
99 doubleOutputStream.close();
\r
101 verify(stream1, only()).close();
\r
102 verify(stream2, never()).close();
\r