master
lorenzo 2024-04-08 12:40:45 +02:00
parent f9e4108705
commit da61ba4641
2 changed files with 25 additions and 3 deletions

View File

@ -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();

View File

@ -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";