Increase coverage for Env module
[aaf/authz.git] / misc / env / src / test / java / org / onap / aaf / misc / env / JU_LogTargetTest.java
diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/JU_LogTargetTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/JU_LogTargetTest.java
new file mode 100644 (file)
index 0000000..474f646
--- /dev/null
@@ -0,0 +1,87 @@
+/**\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;\r
+\r
+import static org.junit.Assert.assertFalse;\r
+import static org.junit.Assert.assertTrue;\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.util.Date;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.Mock;\r
+\r
+public class JU_LogTargetTest {\r
+\r
+       @Mock\r
+       Throwable t;\r
+\r
+       @Before\r
+       public void setup() {\r
+               t = mock(Throwable.class);\r
+       }\r
+\r
+       @Test\r
+       public void testLogTargetNull() {\r
+               LogTarget nullTarget = LogTarget.NULL;\r
+\r
+               // Expect methods doing nothing as no implemenation provided.\r
+               nullTarget.log(new Throwable(), null, null);\r
+               nullTarget.log("String", null);\r
+               nullTarget.printf(null, null, null);\r
+\r
+               assertFalse(nullTarget.isLoggable());\r
+       }\r
+\r
+       @Test\r
+       public void testLogTargetSysOut() {\r
+               LogTarget outTarget = LogTarget.SYSOUT;\r
+\r
+               outTarget.printf("format", new Date());\r
+               outTarget.log("null", null, null);\r
+\r
+               outTarget.log(t);\r
+               outTarget.log(t, "First String Object");\r
+\r
+               assertTrue(outTarget.isLoggable());\r
+\r
+               verify(t, times(2)).printStackTrace(System.out);\r
+       }\r
+\r
+       @Test\r
+       public void testLogTargetSysErr() {\r
+               LogTarget errTarget = LogTarget.SYSERR;\r
+\r
+               errTarget.printf("format", new Date());\r
+               errTarget.log("null", "null");\r
+\r
+               errTarget.log(t);\r
+               errTarget.log(t, "First String Object");\r
+\r
+               assertTrue(errTarget.isLoggable());\r
+\r
+               verify(t, times(2)).printStackTrace(System.err);\r
+       }\r
+\r
+}\r