--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env.util;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.times;\r
+import static org.mockito.Mockito.verify;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.io.Writer;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.Mock;\r
+\r
+public class JU_IndentPrintWriterTest {\r
+\r
+ @Mock\r
+ private OutputStream stream;\r
+\r
+ @Mock\r
+ private Writer writer;\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ stream = mock(OutputStream.class);\r
+ writer = mock(Writer.class);\r
+ }\r
+\r
+ @Test\r
+ public void testWriteInt() throws IOException {\r
+ IndentPrintWriter indentWriter = new IndentPrintWriter(writer);\r
+\r
+ indentWriter.write(123);\r
+\r
+ verify(writer).write(123);\r
+\r
+ assertEquals(indentWriter.getIndent(), 0);\r
+ }\r
+\r
+ @Test\r
+ public void testWriteIntWithNewLineCharacter() throws IOException {\r
+ IndentPrintWriter indentWriter = new IndentPrintWriter(writer);\r
+\r
+ indentWriter.setIndent(12);\r
+\r
+ indentWriter.println();\r
+\r
+ indentWriter.write("123", 1, 2);\r
+\r
+ verify(writer).write('\n');\r
+ verify(writer).write('2');\r
+ verify(writer).write('3');\r
+ assertEquals(indentWriter.getIndent(), 12);\r
+ }\r
+\r
+ @Test\r
+ public void testWriteString() throws IOException {\r
+ IndentPrintWriter indentWriter = new IndentPrintWriter(writer);\r
+\r
+ indentWriter.inc();\r
+\r
+ indentWriter.write("123");\r
+\r
+ verify(writer).write('1');\r
+ verify(writer).write('2');\r
+ verify(writer).write('3');\r
+ assertEquals(indentWriter.getIndent(), 1);\r
+ }\r
+\r
+ @Test\r
+ public void testSetIndent() throws IOException {\r
+ IndentPrintWriter indentWriter = new IndentPrintWriter(stream);\r
+\r
+ indentWriter.setIndent(12);\r
+ indentWriter.dec();\r
+\r
+ assertEquals(indentWriter.getIndent(), 11);\r
+ }\r
+\r
+ @Test\r
+ public void testToCol() throws IOException {\r
+ IndentPrintWriter indentWriter = new IndentPrintWriter(writer);\r
+\r
+ indentWriter.toCol(5);\r
+ char[] chars = { 'a', 'b', 'c' };\r
+ indentWriter.write(chars, 1, 2);\r
+\r
+ verify(writer, times(5)).write(' ');\r
+ verify(writer).write('c');\r
+ verify(writer).write('b');\r
+ }\r
+}
\ No newline at end of file