-
-
Notifications
You must be signed in to change notification settings - Fork 484
Expand file tree
/
Copy pathUtilsTest.java
More file actions
48 lines (38 loc) · 1.27 KB
/
UtilsTest.java
File metadata and controls
48 lines (38 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package data;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import java.io.*;
public class UtilsTest {
@Test
public void testGetString_ValidInput() {
String input = "Hello World";
InputStream in = new ByteArrayInputStream(input.getBytes());
System.setIn(in);
String result = Utils.getString("Enter a string: ");
assertEquals("Hello World", result);
}
@Test
public void testGetInt_ValidInput() {
String input = "123";
InputStream in = new ByteArrayInputStream(input.getBytes());
System.setIn(in);
int result = Utils.getInt("Enter a number: ");
assertEquals(123, result);
}
@Test
public void testGetBoolean_TrueInput() {
String input = "true";
InputStream in = new ByteArrayInputStream(input.getBytes());
System.setIn(in);
boolean result = Utils.getBoolean("Enter true or false: ");
assertTrue(result);
}
@Test
public void testGetBoolean_FalseInput() {
String input = "false";
InputStream in = new ByteArrayInputStream(input.getBytes());
System.setIn(in);
boolean result = Utils.getBoolean("Enter true or false: ");
assertFalse(result);
}
}