Search in sources :

Example 11 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)

Example 12 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)

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