From f41dacc1f13dea937c6d03042692c414956daa77 Mon Sep 17 00:00:00 2001 From: Nick Stolbov Date: Thu, 27 Jan 2022 19:54:00 +0100 Subject: [PATCH] Added clearConsole() method to Cli class with test(always true because it uses external processes) --- src/main/java/Application/Cli.java | 19 +++++++++++++++++++ src/test/java/Application/CliTest.java | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/src/main/java/Application/Cli.java b/src/main/java/Application/Cli.java index b786871..2b93962 100644 --- a/src/main/java/Application/Cli.java +++ b/src/main/java/Application/Cli.java @@ -23,4 +23,23 @@ public class Cli { public Scanner getScanner(){ return this.scanner; } + + public void clearConsole(){ + try{ + String operatingSystem = System.getProperty("os.name");//Check the current operating system + + if(operatingSystem.contains("Windows")){ + ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "cls"); + Process startProcess = pb.inheritIO().start(); + startProcess.waitFor(); + } else { + ProcessBuilder pb = new ProcessBuilder("clear"); + Process startProcess = pb.inheritIO().start(); + + startProcess.waitFor(); + } + }catch(Exception e){ + this.getPrintStream().println(e); + } + } } diff --git a/src/test/java/Application/CliTest.java b/src/test/java/Application/CliTest.java index bc81251..fbc4306 100644 --- a/src/test/java/Application/CliTest.java +++ b/src/test/java/Application/CliTest.java @@ -10,6 +10,7 @@ import java.io.InputStream; import java.io.PrintStream; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; class CliTest { @@ -45,4 +46,10 @@ class CliTest { void getScanner() { assertEquals(cli.getScanner().next(), "Test"); } + + //Cannot test because it uses external processes + @Test + void clearConsole() { + assertTrue(true); + } } \ No newline at end of file