Mass removal of all Tabs (Style Warnings)
[aaf/authz.git] / misc / env / src / test / java / org / onap / aaf / misc / env / util / JU_IndentPrintWriterTest.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.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
27 \r
28 import java.io.IOException;\r
29 import java.io.OutputStream;\r
30 import java.io.Writer;\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_IndentPrintWriterTest {\r
37 \r
38     @Mock\r
39     private OutputStream stream;\r
40 \r
41     @Mock\r
42     private Writer writer;\r
43 \r
44     @Before\r
45     public void setUp() throws Exception {\r
46         stream = mock(OutputStream.class);\r
47         writer = mock(Writer.class);\r
48     }\r
49 \r
50     @Test\r
51     public void testWriteInt() throws IOException {\r
52         IndentPrintWriter indentWriter = new IndentPrintWriter(writer);\r
53 \r
54         indentWriter.write(123);\r
55 \r
56         verify(writer).write(123);\r
57 \r
58         assertEquals(indentWriter.getIndent(), 0);\r
59     }\r
60 \r
61     @Test\r
62     public void testWriteIntWithNewLineCharacter() throws IOException {\r
63         IndentPrintWriter indentWriter = new IndentPrintWriter(writer);\r
64 \r
65         indentWriter.setIndent(12);\r
66 \r
67         indentWriter.println();\r
68 \r
69         indentWriter.write("123", 1, 2);\r
70 \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
75     }\r
76 \r
77     @Test\r
78     public void testWriteString() throws IOException {\r
79         IndentPrintWriter indentWriter = new IndentPrintWriter(writer);\r
80 \r
81         indentWriter.inc();\r
82 \r
83         indentWriter.write("123");\r
84 \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
89     }\r
90 \r
91     @Test\r
92     public void testSetIndent() throws IOException {\r
93         IndentPrintWriter indentWriter = new IndentPrintWriter(stream);\r
94 \r
95         indentWriter.setIndent(12);\r
96         indentWriter.dec();\r
97 \r
98         assertEquals(indentWriter.getIndent(), 11);\r
99     }\r
100 \r
101     @Test\r
102     public void testToCol() throws IOException {\r
103         IndentPrintWriter indentWriter = new IndentPrintWriter(writer);\r
104 \r
105         indentWriter.toCol(5);\r
106         char[] chars = { 'a', 'b', 'c' };\r
107         indentWriter.write(chars, 1, 2);\r
108 \r
109         verify(writer, times(5)).write(' ');\r
110         verify(writer).write('c');\r
111         verify(writer).write('b');\r
112     }\r
113 }