Search in sources :

Example 6 with BaseFileWriter

use of com.tvd12.properties.file.writer.BaseFileWriter in project properties-file by tvd12.

the class BaseFileWriterTest method test4.

@Test(expectedExceptions = { PropertiesFileException.class })
public void test4() {
    String filePath1 = "BaseFileWriterTestFile3.txt";
    final File file1 = new File(filePath1);
    if (file1.exists()) {
        file1.delete();
    }
    Properties properties = new Properties();
    properties.setProperty("a", "1");
    properties.setProperty("b", "2");
    BaseFileWriter fileWriter = new BaseFileWriter() {

        @Override
        protected FileOutputStream newFileOutputStream(File file) throws FileNotFoundException {
            return new FileOutputStream(file) {

                @Override
                public void close() throws IOException {
                    throw new IOException();
                }
            };
        }
    };
    fileWriter.write(properties, file1);
}
Also used : BaseFileWriter(com.tvd12.properties.file.writer.BaseFileWriter) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) Test(org.testng.annotations.Test)

Example 7 with BaseFileWriter

use of com.tvd12.properties.file.writer.BaseFileWriter in project properties-file by tvd12.

the class BaseFileWriterTest method test2.

@Test(expectedExceptions = { PropertiesFileException.class })
public void test2() {
    String filePath1 = "BaseFileWriterTestFile2.txt";
    File file1 = new File(filePath1) {

        private static final long serialVersionUID = -1227507502469046517L;

        @Override
        public boolean createNewFile() throws IOException {
            throw new IOException();
        }
    };
    if (file1.exists()) {
        file1.delete();
    }
    Properties properties = new Properties();
    properties.setProperty("a", "1");
    properties.setProperty("b", "2");
    BaseFileWriter fileWriter = new BaseFileWriter();
    fileWriter.write(properties, file1);
}
Also used : BaseFileWriter(com.tvd12.properties.file.writer.BaseFileWriter) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) Test(org.testng.annotations.Test)

Example 8 with BaseFileWriter

use of com.tvd12.properties.file.writer.BaseFileWriter in project properties-file by tvd12.

the class BaseFileWriterTest method test3.

@Test(expectedExceptions = { PropertiesFileException.class })
public void test3() {
    String filePath1 = "BaseFileWriterTestFile3.txt";
    final File file1 = new File(filePath1);
    if (file1.exists()) {
        file1.delete();
    }
    Properties properties = new Properties();
    properties.setProperty("a", "1");
    properties.setProperty("b", "2");
    BaseFileWriter fileWriter = new BaseFileWriter() {

        @Override
        protected FileOutputStream newFileOutputStream(File file) throws FileNotFoundException {
            return new FileOutputStream(file) {

                @Override
                public void write(byte[] b) throws IOException {
                    throw new IOException();
                }
            };
        }
    };
    fileWriter.write(properties, file1);
}
Also used : BaseFileWriter(com.tvd12.properties.file.writer.BaseFileWriter) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) Test(org.testng.annotations.Test)

Example 9 with BaseFileWriter

use of com.tvd12.properties.file.writer.BaseFileWriter in project properties-file by tvd12.

the class PropertiesFileWriterTest method test.

@Test
public void test() throws PropertiesFileException {
    Properties properties = new Properties();
    properties.setProperty("hello", "word");
    new BaseFileWriter().write(properties, "hello.output_test");
}
Also used : BaseFileWriter(com.tvd12.properties.file.writer.BaseFileWriter) Properties(java.util.Properties) Test(org.testng.annotations.Test)

Example 10 with BaseFileWriter

use of com.tvd12.properties.file.writer.BaseFileWriter in project properties-file by tvd12.

the class BaseFileWriterTest method test1.

@Test
public void test1() {
    String filePath1 = "BaseFileWriterTestFile1.txt";
    File file1 = new File(filePath1);
    if (file1.exists()) {
        file1.delete();
    }
    Properties properties = new Properties();
    properties.setProperty("a", "1");
    properties.setProperty("b", "2");
    BaseFileWriter fileWriter = new BaseFileWriter();
    fileWriter.write(properties, file1);
}
Also used : BaseFileWriter(com.tvd12.properties.file.writer.BaseFileWriter) Properties(java.util.Properties) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

BaseFileWriter (com.tvd12.properties.file.writer.BaseFileWriter)12 Properties (java.util.Properties)12 Test (org.testng.annotations.Test)12 File (java.io.File)8 IOException (java.io.IOException)6 FileOutputStream (java.io.FileOutputStream)4 OutputStream (java.io.OutputStream)2