forked from matyb/java-koans
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAboutMethodPreference.java
More file actions
51 lines (42 loc) · 1.2 KB
/
AboutMethodPreference.java
File metadata and controls
51 lines (42 loc) · 1.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
package beginner;
import com.sandwich.koan.Koan;
import static com.sandwich.koan.constant.KoanConstants.__;
import static com.sandwich.util.Assert.assertEquals;
public class AboutMethodPreference {
class A {
public String doStuff(int i) { return "int"; }
public String doStuff(Integer i) { return "Integer"; }
public String doStuff(Object i) { return "Object"; }
public String doStuff(int...i) { return "int vararg"; }
}
@Koan
public void methodPreferenceInt() {
assertEquals(new A().doStuff(1), __);
}
@Koan
public void methodPreferenceInteger() {
assertEquals(new A().doStuff(Integer.valueOf(1)), __);
}
@Koan
public void methodPreferenceLong() {
long l = 1;
assertEquals(new A().doStuff(l), __);
}
@Koan
public void methodPreferenceBoxedLong() {
Long l = Long.valueOf(1);
assertEquals(new A().doStuff(l), __);
}
@Koan
public void methodPreferenceDouble() {
Double l = Double.valueOf(1);
assertEquals(new A().doStuff(l), __);
}
@Koan
public void methodPreferenceMore() {
// What happens if you change 'Integer' to 'Double'
// Does this explain 'methodPreferenceDouble'?
// Think about why this happens?
assertEquals(new A().doStuff(1, Integer.valueOf(2)), __);
}
}