* Hexagonal architecture in Java

* BAEL-4403

* Revert "Hexagonal architecture in Java"

This reverts commit 7ba4c9dcbd99ca418c070a73bd9ab9f6c956d185.

* Updated code to use only Console

* Added System.out

* Created seaprate method for each functionality

* Added Unit Test Case for ConsoleAndOut class

Co-authored-by: Tarun Jain <tarunalways@gmail.com>
This commit is contained in:
TJ 2020-07-26 09:29:54 +05:30 committed by GitHub
parent cd4f74779a
commit 94555a4510
2 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,31 @@
package com.baeldung.consoleout;
import java.io.Console;
public class ConsoleAndOut {
public static void main(String[] args) {
try {
printConsoleObject();
readPasswordFromConsole();
} catch (Exception ex) {
// Eating NullPointerExcpetion which will occur when this
// program will be run from mediums other than console
}
printSysOut();
}
static void printConsoleObject() {
Console console = System.console();
console.writer().print(console);
}
static void readPasswordFromConsole() {
Console console = System.console();
char[] password = console.readPassword("Enter password: ");
console.printf(String.valueOf(password));
}
static void printSysOut() {
System.out.println(System.out);
}
}

View File

@ -0,0 +1,27 @@
package com.baeldung.consoleout;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
class ConsoleAndOutUnitTest {
@Test
void whenRetreivingConsole_thenPrintConsoleObject() {
assertThrows(NullPointerException.class, () -> {
ConsoleAndOut.printConsoleObject();
});
}
@Test
void whenReadingPassword_thenReadPassword() {
assertThrows(NullPointerException.class, () -> {
ConsoleAndOut.readPasswordFromConsole();
});
}
@Test
void whenRetrievingSysOut_thenPrintSysOutObject() {
ConsoleAndOut.printSysOut();
}
}