forked from matyb/java-koans
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAboutEquality.java
More file actions
43 lines (35 loc) · 1.1 KB
/
AboutEquality.java
File metadata and controls
43 lines (35 loc) · 1.1 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
package beginner;
import com.sandwich.koan.Koan;
import static com.sandwich.koan.constant.KoanConstants.__;
import static com.sandwich.util.Assert.*;
public class AboutEquality {
@Koan
public void doubleEqualsTestsIfTwoObjectsAreTheSame(){
Object object = new Object();
Object sameObject = object;
assertEquals(object == sameObject, __);
assertEquals(object == new Object(), __);
}
@Koan
public void equalsMethodByDefaultTestsIfTwoObjectsAreTheSame(){
Object object = new Object();
assertEquals(object.equals(object), __);
assertEquals(object.equals(new Object()), __);
}
@Koan
public void equalsMethodCanBeChangedBySubclassesToTestsIfTwoObjectsAreEqual(){
Object object = new Integer(1);
assertEquals(object.equals(object), __);
assertEquals(object.equals(new Integer(1)), __);
// Note: This means that for the class 'Object' there is no difference between 'equal' and 'same'
}
@Koan
public void objectsNeverEqualNull(){
assertEquals(new Object().equals(null), __);
}
@Koan
public void objectsEqualThemselves(){
Object obj = new Object();
assertEquals(obj.equals(obj), __);
}
}