Skip to content

Commit

Permalink
refactor(samples): restore stdout to original state after test (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
suraj-qlogic authored and Shabirmean committed Nov 17, 2022
1 parent 30aafe7 commit 9968f42
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class CreateGlossaryTests {

private ByteArrayOutputStream bout;
private PrintStream out;
private PrintStream originalPrintStream;

private static void requireEnvVar(String varName) {
assertNotNull(
Expand All @@ -62,15 +63,17 @@ public static void checkRequirements() {
public void setUp() {
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
}

@After
public void tearDown() throws InterruptedException, ExecutionException, IOException {
// Delete the created glossary
DeleteGlossary.deleteGlossary(PROJECT_ID, GLOSSARY_ID);

System.setOut(null);
// restores print statements in the original method
System.out.flush();
System.setOut(originalPrintStream);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class DeleteGlossaryTests {

private ByteArrayOutputStream bout;
private PrintStream out;
private PrintStream originalPrintStream;

private static void requireEnvVar(String varName) {
assertNotNull(
Expand All @@ -71,12 +72,15 @@ public void setUp() throws InterruptedException, ExecutionException, IOException

bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
}

@After
public void tearDown() {
System.setOut(null);
// restores print statements in the original method
System.out.flush();
System.setOut(originalPrintStream);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class DetectLanguageTests {

private ByteArrayOutputStream bout;
private PrintStream out;
private PrintStream originalPrintStream;

private static void requireEnvVar(String varName) {
assertNotNull(
Expand All @@ -54,12 +55,15 @@ public static void checkRequirements() {
public void setUp() {
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
}

@After
public void tearDown() {
System.setOut(null);
// restores print statements in the original method
System.out.flush();
System.setOut(originalPrintStream);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class GetGlossaryTests {

private ByteArrayOutputStream bout;
private PrintStream out;
private PrintStream originalPrintStream;

private static void requireEnvVar(String varName) {
assertNotNull(
Expand All @@ -70,14 +71,17 @@ public void setUp() throws InterruptedException, ExecutionException, IOException

bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
}

@After
public void tearDown() throws InterruptedException, ExecutionException, IOException {
// Delete the created glossary
DeleteGlossary.deleteGlossary(PROJECT_ID, GLOSSARY_ID);
System.setOut(null);
// restores print statements in the original method
System.out.flush();
System.setOut(originalPrintStream);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class GetSupportedLanguagesForTargetTests {

private ByteArrayOutputStream bout;
private PrintStream out;
private PrintStream originalPrintStream;

private static void requireEnvVar(String varName) {
assertNotNull(
Expand All @@ -54,12 +55,15 @@ public static void checkRequirements() {
public void setUp() {
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
}

@After
public void tearDown() {
System.setOut(null);
// restores print statements in the original method
System.out.flush();
System.setOut(originalPrintStream);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class GetSupportedLanguagesTests {

private ByteArrayOutputStream bout;
private PrintStream out;
private PrintStream originalPrintStream;

private static void requireEnvVar(String varName) {
assertNotNull(
Expand All @@ -54,12 +55,15 @@ public static void checkRequirements() {
public void setUp() {
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
}

@After
public void tearDown() {
System.setOut(null);
// restores print statements in the original method
System.out.flush();
System.setOut(originalPrintStream);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class ListGlossariesTests {

private ByteArrayOutputStream bout;
private PrintStream out;
private PrintStream originalPrintStream;

private static void requireEnvVar(String varName) {
assertNotNull(
Expand All @@ -71,14 +72,17 @@ public void setUp() throws InterruptedException, ExecutionException, IOException

bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
}

@After
public void tearDown() throws InterruptedException, ExecutionException, IOException {
// Delete the created glossary
DeleteGlossary.deleteGlossary(PROJECT_ID, GLOSSARY_ID);
System.setOut(null);
// restores print statements in the original method
System.out.flush();
System.setOut(originalPrintStream);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,21 @@
public class QuickstartSampleIT {
private ByteArrayOutputStream bout;
private PrintStream out;
private PrintStream originalPrintStream;

@Before
public void setUp() {
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
}

@After
public void tearDown() {
System.setOut(null);
// restores print statements in the original method
System.out.flush();
System.setOut(originalPrintStream);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class TranslateTextTests {

private ByteArrayOutputStream bout;
private PrintStream out;
private PrintStream originalPrintStream;

private static void requireEnvVar(String varName) {
assertNotNull(
Expand All @@ -54,12 +55,15 @@ public static void checkRequirements() {
public void setUp() {
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
}

@After
public void tearDown() {
System.setOut(null);
// restores print statements in the original method
System.out.flush();
System.setOut(originalPrintStream);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class TranslateTextWithGlossaryAndModelTests {

private ByteArrayOutputStream bout;
private PrintStream out;
private PrintStream originalPrintStream;

private static void requireEnvVar(String varName) {
assertNotNull(
Expand All @@ -71,6 +72,7 @@ public void setUp() throws InterruptedException, ExecutionException, IOException

bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
}

Expand All @@ -79,7 +81,9 @@ public void tearDown() throws InterruptedException, ExecutionException, IOExcept
// Clean up
// Delete the created glossary
DeleteGlossary.deleteGlossary(PROJECT_ID, GLOSSARY_ID);
System.setOut(null);
// restores print statements in the original method
System.out.flush();
System.setOut(originalPrintStream);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class TranslateTextWithGlossaryTests {

private ByteArrayOutputStream bout;
private PrintStream out;
private PrintStream originalPrintStream;

private static void requireEnvVar(String varName) {
assertNotNull(
Expand All @@ -70,6 +71,7 @@ public void setUp() throws InterruptedException, ExecutionException, IOException

bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
}

Expand All @@ -78,7 +80,9 @@ public void tearDown() throws InterruptedException, ExecutionException, IOExcept
// Clean up
// Delete the created glossary
DeleteGlossary.deleteGlossary(PROJECT_ID, GLOSSARY_ID);
System.setOut(null);
// restores print statements in the original method
System.out.flush();
System.setOut(originalPrintStream);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class TranslateTextWithModelTests {

private ByteArrayOutputStream bout;
private PrintStream out;
private PrintStream originalPrintStream;

private static void requireEnvVar(String varName) {
assertNotNull(
Expand All @@ -55,12 +56,15 @@ public static void checkRequirements() {
public void setUp() {
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
}

@After
public void tearDown() {
System.setOut(null);
// restores print statements in the original method
System.out.flush();
System.setOut(originalPrintStream);
}

@Test
Expand Down

0 comments on commit 9968f42

Please sign in to comment.