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
22 package org.onap.aaf.misc.env.util;
\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
29 import java.io.IOException;
\r
30 import java.io.OutputStream;
\r
32 import org.junit.Before;
\r
33 import org.junit.Test;
\r
34 import org.mockito.Mock;
\r
36 public class JU_DoubleOutputStreamTest {
\r
39 private OutputStream stream1;
\r
42 private OutputStream stream2;
\r
44 private DoubleOutputStream doubleOutputStream;
\r
47 public void setup() {
\r
48 stream1 = mock(OutputStream.class);
\r
49 stream2 = mock(OutputStream.class);
\r
53 public void testWriteInt() throws IOException {
\r
54 doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);
\r
56 doubleOutputStream.write(123);
\r
58 verify(stream1, only()).write(123);
\r
59 verify(stream2, only()).write(123);
\r
63 public void testWriteByteArray() throws IOException {
\r
64 doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);
\r
66 byte[] bytes = { 1, 2, 3, 4 };
\r
68 doubleOutputStream.write(bytes);
\r
70 verify(stream1, only()).write(bytes);
\r
71 verify(stream2, only()).write(bytes);
\r
76 public void testWriteByteArrayWithOffset() throws IOException {
\r
77 doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);
\r
79 byte[] bytes = { 1, 2, 3, 4 };
\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
87 public void testFlush() throws IOException {
\r
88 doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);
\r
90 doubleOutputStream.flush();
\r
92 verify(stream1, only()).flush();
\r
93 verify(stream2, only()).flush();
\r
97 public void testClose() throws IOException {
\r
98 doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, false);
\r
100 doubleOutputStream.close();
\r
102 verify(stream1, only()).close();
\r
103 verify(stream2, never()).close();
\r