47 lines
1.1 KiB
Java
47 lines
1.1 KiB
Java
|
package Uebung2_IO.loesung2;
|
||
|
|
||
|
import static org.junit.jupiter.api.Assertions.*;
|
||
|
|
||
|
import java.io.ByteArrayInputStream;
|
||
|
import java.io.IOException;
|
||
|
|
||
|
import org.junit.jupiter.api.Test;
|
||
|
|
||
|
public class ConsoleTest {
|
||
|
|
||
|
@Test
|
||
|
public void testReadString() throws IOException {
|
||
|
ByteArrayInputStream inputStream = new ByteArrayInputStream("Testeingabe".getBytes());
|
||
|
System.setIn(inputStream);
|
||
|
|
||
|
String result = Console.readString();
|
||
|
|
||
|
assertEquals("Testeingabe", result);
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void testReadCharArray() throws IOException {
|
||
|
|
||
|
ByteArrayInputStream inputStream = new ByteArrayInputStream("abc".getBytes());
|
||
|
System.setIn(inputStream);
|
||
|
|
||
|
char[] result = Console.readCharArray();
|
||
|
|
||
|
assertArrayEquals(new char[]{'a', 'b', 'c'}, result);
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void testReadBoolean() throws IOException {
|
||
|
|
||
|
ByteArrayInputStream inputStream = new ByteArrayInputStream("true".getBytes());
|
||
|
System.setIn(inputStream);
|
||
|
|
||
|
|
||
|
boolean result = Console.readBoolean();
|
||
|
|
||
|
|
||
|
assertTrue(result);
|
||
|
}
|
||
|
}
|
||
|
|