Skip to content

Commit

Permalink
add example classes used in try with resources test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Coles committed Feb 15, 2021
1 parent 6410c68 commit 141244e
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pitest/src/test/java/twr/example1/TryExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package twr.example1;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
* @author Artem Khvastunov
*
* Tests use stored compiled binaries of this class. Source here for reference only.
*/
public class TryExample {

public static void main(String[] args) throws IOException {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
baos.flush();
}
}
}
20 changes: 20 additions & 0 deletions pitest/src/test/java/twr/example2/TryCatchExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package twr.example2;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
* @author Artem Khvastunov
*
* Tests use stored compiled binaries of this class. Source here for reference only.
*/
public class TryCatchExample {

public static void main(String[] args) {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
baos.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
21 changes: 21 additions & 0 deletions pitest/src/test/java/twr/example3/TryCatchFinallyExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package twr.example3;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
* @author Artem Khvastunov
* Tests use stored compiled binaries of this class. Source here for reference only.
*/
public class TryCatchFinallyExample {

public static void main(String[] args) {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
baos.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
System.out.println("Finally!");
}
}
}
19 changes: 19 additions & 0 deletions pitest/src/test/java/twr/example4/TryFinallyExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package twr.example4;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
* @author Artem Khvastunov
* Tests use stored compiled binaries of this class. Source here for reference only.
*/
public class TryFinallyExample {

public static void main(String[] args) throws IOException {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
baos.flush();
} finally {
System.out.println("Finally!");
}
}
}
19 changes: 19 additions & 0 deletions pitest/src/test/java/twr/example5/TryWithTwoCloseableExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package twr.example5;

import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
* @author Artem Khvastunov
* Tests use stored compiled binaries of this class. Source here for reference only.
*/
public class TryWithTwoCloseableExample {

public static void main(String[] args) throws IOException {
try (ByteArrayOutputStream baos /* 1 */ = new ByteArrayOutputStream(); // L22 // null /* 2 */ // L23
BufferedOutputStream bos /* 3 */ = new BufferedOutputStream(baos)) { // L14 // null /* 4 */ // L24
bos.flush(); // L3
} // L4
}
}
20 changes: 20 additions & 0 deletions pitest/src/test/java/twr/example6/TryWithNestedTryExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package twr.example6;

import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
* @author Artem Khvastunov
* Tests use stored compiled binaries of this class. Source here for reference only.
*/
public class TryWithNestedTryExample {

public static void main(String[] args) throws IOException {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
try (BufferedOutputStream bos = new BufferedOutputStream(baos)) {
bos.flush();
}
}
}
}
19 changes: 19 additions & 0 deletions pitest/src/test/java/twr/example7/TryWithInterfaceExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package twr.example7;

import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.Flushable;
import java.io.IOException;

/**
* @author Artem Khvastunov
* Tests use stored compiled binaries of this class. Source here for reference only.
*/
public class TryWithInterfaceExample {

public static void main(String[] args) throws IOException {
try (Closeable os = new ByteArrayOutputStream()) {
((Flushable) os).flush();
}
}
}

0 comments on commit 141244e

Please sign in to comment.