.....
parent
f9e4108705
commit
da61ba4641
|
@ -19,7 +19,8 @@ public class Console {
|
|||
|
||||
public static char[] readCharArray() {
|
||||
try {
|
||||
return reader.readLine().toCharArray();
|
||||
String input = reader.readLine();
|
||||
return input.toCharArray();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null; // oder eine geeignete Fehlerbehandlung
|
||||
|
@ -28,7 +29,7 @@ public class Console {
|
|||
|
||||
public static boolean readBoolean() {
|
||||
try {
|
||||
String input = reader.readLine().toLowerCase();
|
||||
String input = reader.readLine().toLowerCase().trim();
|
||||
return input.equals("true") || input.equals("t") || input.equals("yes") || input.equals("y");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -4,11 +4,32 @@ import static org.junit.Assert.assertArrayEquals;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import org.junit.Before;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class ConsoleTest {
|
||||
|
||||
private final InputStream originalSystemIn = System.in;
|
||||
private final PrintStream originalSystemOut = System.out;
|
||||
private ByteArrayOutputStream systemOutContent;
|
||||
|
||||
@Before
|
||||
public void setUpStreams() {
|
||||
systemOutContent = new ByteArrayOutputStream();
|
||||
System.setOut(new PrintStream(systemOutContent));
|
||||
}
|
||||
|
||||
@After
|
||||
public void restoreStreams() {
|
||||
System.setIn(originalSystemIn);
|
||||
System.setOut(originalSystemOut);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadString() {
|
||||
String input = "Test String";
|
||||
|
|
Loading…
Reference in New Issue