Browse Source

Added clearConsole() method to Cli class with test(always true because it uses external processes)

feature-cli
Nick Stolbov 3 years ago
parent
commit
f41dacc1f1
  1. 19
      src/main/java/Application/Cli.java
  2. 7
      src/test/java/Application/CliTest.java

19
src/main/java/Application/Cli.java

@ -23,4 +23,23 @@ public class Cli {
public Scanner getScanner(){ public Scanner getScanner(){
return this.scanner; 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);
}
}
} }

7
src/test/java/Application/CliTest.java

@ -10,6 +10,7 @@ import java.io.InputStream;
import java.io.PrintStream; import java.io.PrintStream;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
class CliTest { class CliTest {
@ -45,4 +46,10 @@ class CliTest {
void getScanner() { void getScanner() {
assertEquals(cli.getScanner().next(), "Test"); assertEquals(cli.getScanner().next(), "Test");
} }
//Cannot test because it uses external processes
@Test
void clearConsole() {
assertTrue(true);
}
} }
Loading…
Cancel
Save