2 * ============LICENSE_START=======================================================
3 * Copyright (c) 2020 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.tools.common;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
28 import java.nio.file.FileSystems;
29 import java.nio.file.Path;
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Test;
34 public class OutputFileTest {
36 final String testFileName = "testing.txt";
37 final Path fp = FileSystems.getDefault().getPath(testFileName);
38 File file = fp.toFile();
41 public void beforeSetUp() {
48 public void testToWriter() {
49 OutputFile testFile = new OutputFile(testFileName, false);
51 file.setReadable(false);
52 file.setWritable(false);
53 assertNull(testFile.toWriter());
54 file.setWritable(true);
55 assertNotNull(testFile.toWriter());
59 public void testValidate() {
60 OutputFile testFile = new OutputFile(testFileName, true);
61 assertNull(testFile.validate());
62 file.setReadable(false);
63 file.setWritable(false);
64 assertNotNull(testFile.validate());
65 OutputFile testFile2 = new OutputFile(testFileName);
66 assertNotNull(testFile2.validate());
67 assertEquals("file already exists", testFile2.validate());
71 public void testToOutputStream() {
72 OutputFile testFile = new OutputFile(testFileName, true);
73 assertNotNull(testFile.toOutputStream());
74 file.setReadable(false);
75 file.setWritable(false);
76 assertNull(testFile.toOutputStream());
80 public void testDown() {