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.junit.Assert.assertEquals;
\r
24 import static org.mockito.Mockito.mock;
\r
25 import static org.mockito.Mockito.times;
\r
26 import static org.mockito.Mockito.verify;
\r
28 import java.io.IOException;
\r
29 import java.io.OutputStream;
\r
30 import java.io.Writer;
\r
32 import org.junit.Before;
\r
33 import org.junit.Test;
\r
34 import org.mockito.Mock;
\r
36 public class JU_IndentPrintWriterTest {
\r
39 private OutputStream stream;
\r
42 private Writer writer;
\r
45 public void setUp() throws Exception {
\r
46 stream = mock(OutputStream.class);
\r
47 writer = mock(Writer.class);
\r
51 public void testWriteInt() throws IOException {
\r
52 IndentPrintWriter indentWriter = new IndentPrintWriter(writer);
\r
54 indentWriter.write(123);
\r
56 verify(writer).write(123);
\r
58 assertEquals(indentWriter.getIndent(), 0);
\r
62 public void testWriteIntWithNewLineCharacter() throws IOException {
\r
63 IndentPrintWriter indentWriter = new IndentPrintWriter(writer);
\r
65 indentWriter.setIndent(12);
\r
67 indentWriter.println();
\r
69 indentWriter.write("123", 1, 2);
\r
71 verify(writer).write('\n');
\r
72 verify(writer).write('2');
\r
73 verify(writer).write('3');
\r
74 assertEquals(indentWriter.getIndent(), 12);
\r
78 public void testWriteString() throws IOException {
\r
79 IndentPrintWriter indentWriter = new IndentPrintWriter(writer);
\r
83 indentWriter.write("123");
\r
85 verify(writer).write('1');
\r
86 verify(writer).write('2');
\r
87 verify(writer).write('3');
\r
88 assertEquals(indentWriter.getIndent(), 1);
\r
92 public void testSetIndent() throws IOException {
\r
93 IndentPrintWriter indentWriter = new IndentPrintWriter(stream);
\r
95 indentWriter.setIndent(12);
\r
98 assertEquals(indentWriter.getIndent(), 11);
\r
102 public void testToCol() throws IOException {
\r
103 IndentPrintWriter indentWriter = new IndentPrintWriter(writer);
\r
105 indentWriter.toCol(5);
\r
106 char[] chars = { 'a', 'b', 'c' };
\r
107 indentWriter.write(chars, 1, 2);
\r
109 verify(writer, times(5)).write(' ');
\r
110 verify(writer).write('c');
\r
111 verify(writer).write('b');
\r