master
lorenzo 2024-04-08 12:29:39 +02:00
parent 67fda3e35c
commit f9e4108705
2 changed files with 41 additions and 0 deletions

View File

@ -6,5 +6,6 @@
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -0,0 +1,40 @@
package inputOutput;
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.Test;
import java.io.ByteArrayInputStream;
public class ConsoleTest {
@Test
public void testReadString() {
String input = "Test String";
System.setIn(new ByteArrayInputStream(input.getBytes()));
assertEquals(input, Console.readString());
}
@Test
public void testReadCharArray() {
String input = "Test Char Array";
System.setIn(new ByteArrayInputStream(input.getBytes()));
char[] expected = input.toCharArray();
assertArrayEquals(expected, Console.readCharArray());
}
@Test
public void testReadBooleanTrue() {
String input = "true";
System.setIn(new ByteArrayInputStream(input.getBytes()));
assertTrue(Console.readBoolean());
}
@Test
public void testReadBooleanFalse() {
String input = "false";
System.setIn(new ByteArrayInputStream(input.getBytes()));
assertFalse(Console.readBoolean());
}
}