aboutsummaryrefslogtreecommitdiffstats
path: root/tools/tools-common/src/test/java/org
diff options
context:
space:
mode:
authorRossC <ross.carter@est.tech>2020-05-07 13:25:34 +0100
committerRossC <ross.carter@est.tech>2020-05-08 14:57:56 +0100
commitea317372413753320db681efb9a1e469c3776f42 (patch)
tree33fd9dcc743783146057b2c4f45c051c140ce077 /tools/tools-common/src/test/java/org
parent5b0b7fac53c587307832119657a31b64926797a3 (diff)
Unit tests for various classes
Issue-ID: POLICY-1916 Change-Id: Ie7cafa16ce12ca542a4e76307caddb36b7753990 Signed-off-by: RossC <ross.carter@est.tech>
Diffstat (limited to 'tools/tools-common/src/test/java/org')
-rw-r--r--tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/OutputFileTest.java83
1 files changed, 83 insertions, 0 deletions
diff --git a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/OutputFileTest.java b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/OutputFileTest.java
new file mode 100644
index 000000000..36c64e517
--- /dev/null
+++ b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/OutputFileTest.java
@@ -0,0 +1,83 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (c) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.apex.tools.common;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.nio.file.FileSystems;
+import java.nio.file.Path;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class OutputFileTest {
+
+ final String testFileName = "testing.txt";
+ final Path fp = FileSystems.getDefault().getPath(testFileName);
+ File file = fp.toFile();
+
+ @Before
+ public void setUp() {
+ if (file.exists()){
+ file.delete();
+ }
+ }
+
+ @Test
+ public void testToWriter() {
+ OutputFile testFile = new OutputFile(testFileName,false);
+ testFile.validate();
+ file.setReadable(false);
+ file.setWritable(false);
+ assertNull(testFile.toWriter());
+ file.setWritable(true);
+ assertNotNull(testFile.toWriter());
+ }
+
+ @Test
+ public void testValidate() {
+ OutputFile testFile = new OutputFile(testFileName,true);
+ assertNull(testFile.validate());
+ file.setReadable(false);
+ file.setWritable(false);
+ assertNotNull(testFile.validate());
+ OutputFile testFile2 = new OutputFile(testFileName);
+ assertNotNull(testFile2.validate());
+ assertEquals("file already exists",testFile2.validate());
+ }
+
+ @Test
+ public void testToOutputStream() {
+ OutputFile testFile = new OutputFile(testFileName,true);
+ assertNotNull(testFile.toOutputStream());
+ file.setReadable(false);
+ file.setWritable(false);
+ assertNull(testFile.toOutputStream());
+ }
+
+ @After
+ public void testDown() {
+ if (file.exists()){
+ file.delete();
+ }
+ }
+}