-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathLoggerTest.java
More file actions
114 lines (95 loc) · 2.58 KB
/
LoggerTest.java
File metadata and controls
114 lines (95 loc) · 2.58 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
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
package com.acme.edu.iteration01;
import com.acme.edu.Logger;
import com.acme.edu.SysoutCaptureAndAssertionAbility;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.*;
public class LoggerTest implements SysoutCaptureAndAssertionAbility {
private final String sep = System.lineSeparator();
//region given
@Before
public void setUpSystemOut() throws IOException {
resetOut();
captureSysout();
}
@After
public void tearDown() {
resetOut();
}
//endregion
@Test
public void shouldLogInteger() throws IOException {
//region when
Logger.log(1);
Logger.log(0);
Logger.log(-1);
//endregion
//region then
assertSysoutContains("primitive: ");
assertSysoutEquals("primitive: 1" + sep +
"primitive: 0" + sep +
"primitive: -1" + sep);
//endregion
}
@Test
public void shouldLogByte() throws IOException {
//region when
Logger.log((byte) 1);
Logger.log((byte) 0);
Logger.log((byte) -1);
//endregion
//region then
assertSysoutContains("primitive: ");
assertSysoutContains("1");
assertSysoutContains("0");
assertSysoutContains("-1");
//endregion
}
@Test
public void shouldLogChar() throws IOException {
//region when
Logger.log('a');
Logger.log('b');
//endregion
//region then
assertSysoutContains("char: ");
assertSysoutContains("a");
assertSysoutContains("b");
//endregion
}
@Test
public void shouldLogString() throws IOException {
//region when
Logger.log("test string 1");
Logger.log("other str");
//endregion
//region then
assertSysoutContains("string: ");
assertSysoutContains("test string 1");
assertSysoutContains("other str");
//endregion
}
@Test
public void shouldLogBoolean() throws IOException {
//region when
Logger.log(true);
Logger.log(false);
//endregion
//region then
assertSysoutContains("primitive: ");
assertSysoutContains("true");
assertSysoutContains("false");
//endregion
}
@Test
public void shouldLogReference() throws IOException {
//region when
Logger.log(new Object());
//endregion
//region then
assertSysoutContains("reference: ");
assertSysoutContains("@");
//endregion
}
}