I am experimenting with junit5 and pitest. My code under test looks like:
// [...]
InputStream istream = this.getClass().getResourceAsStream("/" + file.getName());
if (istream == null) // 1. negated condition -> suvived
{
istream = Files.newInputStream(this.files.get(varname).toPath(), StandardOpenOption.READ);
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(istream, StandardCharsets.UTF_8))) // 2. removed call to java/io/BufferedReader::close → SURVIVED // 3. removed call to java/lang/Throwable::addSuppressed → SURVIVED
{
// [...]
} // 4. removed call to java/io/BufferedReader::close → SURVIVED
Within this small block of code I have left 4 survived mutations I would like to kill. Killing could happen by adding/changing a test or also by refactoring the code.
My problem is now that the first mutation is an equivalent mutant - were I have no idea how to refactore it away. The other three mutations are implicit by the try-resource-statement.
So my question is how to refactor this 4 mutations away? Because I am sure they can not be killed by additional/changed tests.