Search in sources :

Example 1 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 2 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)

Example 3 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 4 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 5 with BaseFileWriter

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

the class PropertiesFileWriterTest method writeToOuputStreamInvalidCase.

@Test(expectedExceptions = { PropertiesFileException.class })
public void writeToOuputStreamInvalidCase() throws PropertiesFileException, IOException {
    Properties properties = mock(Properties.class);
    doThrow(IOException.class).when(properties).store(any(OutputStream.class), any(String.class));
    new BaseFileWriter().write(properties);
}
Also used : BaseFileWriter(com.tvd12.properties.file.writer.BaseFileWriter) OutputStream(java.io.OutputStream) Properties(java.util.Properties) 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