forked from matyb/java-koans
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAboutAssertions.java
More file actions
executable file
·68 lines (56 loc) · 1.71 KB
/
AboutAssertions.java
File metadata and controls
executable file
·68 lines (56 loc) · 1.71 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
package beginner;
// FYI - usually bad practice to import statically, but can make code cleaner
import static com.sandwich.koan.constant.KoanConstants.__;
import static com.sandwich.util.Assert.assertEquals;
import static com.sandwich.util.Assert.assertFalse;
import static com.sandwich.util.Assert.assertNotNull;
import static com.sandwich.util.Assert.assertNotSame;
import static com.sandwich.util.Assert.assertNull;
import static com.sandwich.util.Assert.assertSame;
import static com.sandwich.util.Assert.assertTrue;
import com.sandwich.koan.Koan;
public class AboutAssertions {
@Koan
public void assertBooleanTrue() {
assertTrue(__); // should be true really
}
@Koan
public void assertBooleanFalse() {
assertFalse(__);
}
@Koan
public void assertNullObject(){
assertNull(__);
}
@Koan
public void assertNotNullObject(){
assertNotNull(null); // anything other than null should pass here...
}
@Koan
public void assertEqualsUsingExpression(){
assertTrue("Hello World!".equals(__));
}
@Koan
public void assertEqualsWithBetterFailureMessage(){
assertEquals(1, __);
}
@Koan
public void assertEqualsWithDescriptiveMessage() {
// Generally, when using an assertXXX methods, expectation is on the
// left and it is best practice to use a String for the first arg
// indication what has failed
assertEquals("The answer to 'life the universe and everything' should be 42", 42, __);
}
@Koan
public void assertSameInstance(){
Object same = new Integer(1);
Object sameReference = __;
assertSame(same, sameReference);
}
@Koan
public void assertNotSameInstance(){
Integer same = new Integer(1);
Integer sameReference = same;
assertNotSame(same, sameReference);
}
}