Search in sources :

Example 6 with PropertiesFileException

use of com.tvd12.properties.file.exception.PropertiesFileException in project properties-file by tvd12.

the class BaseFileWriter method write.

/* (non-Javadoc)
     * @see com.tvd12.properties.file.writer.FileWriter#write(java.util.Properties, java.io.File)
     */
@Override
public void write(Properties properties, File file) {
    try (ByteArrayOutputStream out = write(properties)) {
        if (!file.exists()) {
            file.createNewFile();
        }
        byte[] bytes = encode(out);
        writeBytes0(file, bytes);
    } catch (IOException e) {
        throw new PropertiesFileException("Can not write properties to file", e);
    }
}
Also used : PropertiesFileException(com.tvd12.properties.file.exception.PropertiesFileException)

Example 7 with PropertiesFileException

use of com.tvd12.properties.file.exception.PropertiesFileException in project properties-file by tvd12.

the class PropertiesFileReaderTest method loadInputStreamTest.

@SuppressWarnings("unchecked")
@Test(expectedExceptions = { PropertiesFileException.class })
public void loadInputStreamTest() throws PropertiesFileException, IOException {
    InputStream stream = mock(InputStream.class);
    when(stream.read()).thenThrow(IOException.class);
    new BaseFileReader().loadInputStream(stream);
}
Also used : BaseFileReader(com.tvd12.properties.file.reader.BaseFileReader) InputStream(java.io.InputStream) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 8 with PropertiesFileException

use of com.tvd12.properties.file.exception.PropertiesFileException 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 9 with PropertiesFileException

use of com.tvd12.properties.file.exception.PropertiesFileException in project properties-file by tvd12.

the class PropertiesFileReaderTest method testWithValidData2.

@Test
public void testWithValidData2() throws PropertiesFileException {
    File file = new File(getClass().getClassLoader().getResource("classes.properties").getFile());
    assertNotNull(new BaseFileReader().read(Lists.newArrayList(file, file)));
    assertNotNull(new BaseFileReader().read(Lists.newArrayList(file, file)));
}
Also used : BaseFileReader(com.tvd12.properties.file.reader.BaseFileReader) File(java.io.File) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 10 with PropertiesFileException

use of com.tvd12.properties.file.exception.PropertiesFileException 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)

Aggregations

Test (org.testng.annotations.Test)8 Properties (java.util.Properties)6 BaseFileReader (com.tvd12.properties.file.reader.BaseFileReader)4 BaseFileWriter (com.tvd12.properties.file.writer.BaseFileWriter)4 BaseTest (com.tvd12.test.base.BaseTest)4 PropertiesFileException (com.tvd12.properties.file.exception.PropertiesFileException)3 File (java.io.File)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1