Repository navigation
Expand file tree
/
Copy pathConditionalExampleTest.java
More file actions
79 lines (64 loc) · 2.2 KB
/
Copy pathConditionalExampleTest.java
File metadata and controls
79 lines (64 loc) · 2.2 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.codescene;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ConditionalExampleTest {
private ConditionalExample example;
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private final PrintStream originalOut = System.out;
@BeforeEach
public void setUp() {
example = new ConditionalExample();
System.setOut(new PrintStream(outContent));
}
@Test
public void testCheckNumberPositiveEven() {
example.checkNumber(4);
assertEquals("The number is positive\nThe number is even\n", outContent.toString());
}
@Test
public void testCheckNumberNegativeOdd() {
example.checkNumber(-3);
assertEquals("The number is negative\nThe number is odd\n", outContent.toString());
}
@Test
public void testCheckNumberZero() {
example.checkNumber(0);
assertEquals("The number is even\n", outContent.toString());
}
@Test
public void testCategorizeStringLongWithNumbers() {
String result = example.categorizeString("Hello123");
assertEquals("Long and contains numbers", result);
}
@Test
public void testCategorizeStringShortOnlyLetters() {
String result = example.categorizeString("Hi");
assertEquals("Short and contains only letters", result);
}
@Test
public void testCategorizeStringEmptyString() {
String result = example.categorizeString("");
assertEquals("Short and contains only letters", result);
}
@Test
public void testCategorizeStringOnlyNumbers() {
String result = example.categorizeString("12345");
assertEquals("Short and contains numbers", result);
}
@Test
public void emptyStringsDoNotContainVowels() {
assertEquals(0, example.countVowels(""));
}
@Test
public void countsVowels() {
assertEquals(0, example.countVowels("qwrt"));
assertEquals(2, example.countVowels("aqewrt"));
}
@Test
public void tearDown() {
System.setOut(originalOut);
}
}