-
Notifications
You must be signed in to change notification settings - Fork 2
/
ExampleTest.java
115 lines (90 loc) · 3.55 KB
/
ExampleTest.java
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package io.github.jkomoroski.declarativejupiter;
import static java.util.function.Predicate.not;
import io.github.jkomoroski.declarativejupiter.testutils.DeclarativeJupiterUtilities;
import java.util.List;
import java.util.stream.IntStream;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class ExampleTest {
private Main application;
private DummyResource1 resource1;
private DummyResource2 resource2;
@BeforeAll
static void arrangeEnvironment() {
System.setProperty("key", "value");
}
@BeforeEach
void setup() {
resource1 = new DummyResource1();
resource1.init();
resource2 = new DummyResource2();
resource2.init();
application = new Main(resource1, resource2);
}
@AfterEach
void tearDown() {
application.exit();
resource1.close();
resource2.close();
}
@AfterAll
static void cleanUpEnvironment() {
System.clearProperty("key");
}
@Test
void testApplicationStartup() {
Assertions.assertDoesNotThrow(() -> application.run(), "Expected No Exception When Running...");
}
@Test
void testRequiredSystemProperty() {
Assertions.assertEquals("value", System.getProperty("key"), "Expected System Property key=value");
}
@Test
void testFirstHundredThousandFizzBuzzDoesNotThrow() {
final String[] args = IntStream.range(0, 100_000)
.mapToObj(String::valueOf)
.toArray(String[]::new);
Assertions.assertDoesNotThrow(() -> new Main(resource1, resource2, args).run());
}
@Test
void testFirstMillionFizzBuzzNumbersAreNotDivisibleByThreeOrFive() {
IntStream.range(0, 1_000_000)
.mapToObj(Main::toFizzBuzz)
.filter(DeclarativeJupiterUtilities::isDecimalNumber)
.map(Integer::parseInt)
.filter(i -> (i % 3 == 0) || (i % 5 == 0))
.findAny()
.ifPresent(m -> Assertions.fail("Expected none of first million to be divisible by 3 or 5. Found=" + m));
}
@Test
void testFirstMillionFizzBuzzWords() {
IntStream.range(0, 1_000_000)
.mapToObj(Main::toFizzBuzz)
.filter(not(DeclarativeJupiterUtilities::isDecimalNumber))
.filter(s -> !("Fizz".equals(s) || "Buzz".equals(s) || "FizzBuzz".equals(s)))
.findAny()
.ifPresent(m -> Assertions.fail("Expected none of first million to be Fizz or Buzz or FizzBuzz. Found=" + m));
}
@Test
void testApplicationHasRunningState() {
Assertions.assertTrue(application.isRunning(), "Application Should be running");
}
@Test
void testStaticMethods() {
Assertions.assertTrue(Main.isFizz(3));
Assertions.assertFalse(Main.isFizz(5));
Assertions.assertTrue(Main.isBuzz(5));
Assertions.assertFalse(Main.isBuzz(3));
Assertions.assertEquals(100, Main.defaultIntegerList().size());
List<Integer> integerList = List.of(1, 2, 3, 4, 5);
Assertions.assertEquals(integerList, Main.convertArgumentsToIntegerList("1", "2", "3", "4", "5"));
Assertions.assertEquals("Fizz", Main.toFizzBuzz(3));
Assertions.assertEquals("Buzz", Main.toFizzBuzz(5));
Assertions.assertEquals("FizzBuzz", Main.toFizzBuzz(15));
Assertions.assertEquals("1", Main.toFizzBuzz(1));
}
}