lundi 23 janvier 2017

How to test this file-writing, 3lines function?

This is my method in some service class. It's public so it should be tested. I simply do not know WHAT should i test. I'd mock Writer and spyOn function call, but with this implementation it's impossible (isn't it?)

I'm using mockito and junit

For now, i can only make function to throw and assert that exception

Any help? Thanks in advance

@Override
public void initIndexFile(File emptyIndexFile) {
    try {
        Writer writer = new FileWriter(emptyIndexFile);
        writer.write("[]");
        writer.close();
    } catch (IOException e) {
        throw new IndexFileInitializationException("Error initialization index file " + emptyIndexFile.getPath());
    }
}

Aucun commentaire:

Enregistrer un commentaire