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=========================================================
20 package org.onap.policy.apex.tools.common;
22 import static org.junit.Assert.*;
25 import java.nio.file.FileSystems;
26 import java.nio.file.Path;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
32 public class OutputFileTest {
34 final String testFileName = "testing.txt";
35 final Path fp = FileSystems.getDefault().getPath(testFileName);
36 File file = fp.toFile();
46 public void testToWriter() {
47 OutputFile testFile = new OutputFile(testFileName,false);
49 file.setReadable(false);
50 file.setWritable(false);
51 assertNull(testFile.toWriter());
52 file.setWritable(true);
53 assertNotNull(testFile.toWriter());
57 public void testValidate() {
58 OutputFile testFile = new OutputFile(testFileName,true);
59 assertNull(testFile.validate());
60 file.setReadable(false);
61 file.setWritable(false);
62 assertNotNull(testFile.validate());
63 OutputFile testFile2 = new OutputFile(testFileName);
64 assertNotNull(testFile2.validate());
65 assertEquals("file already exists",testFile2.validate());
69 public void testToOutputStream() {
70 OutputFile testFile = new OutputFile(testFileName,true);
71 assertNotNull(testFile.toOutputStream());
72 file.setReadable(false);
73 file.setWritable(false);
74 assertNull(testFile.toOutputStream());
78 public void testDown() {