Skip to content

Commit 81c79b8

Browse files
committed
reorganized classes, pkgs
1 parent 7e0803d commit 81c79b8

3 files changed

Lines changed: 98 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.sandwich.koan.exampleclasses;
2+
3+
4+
public class ClassUnderTest {
5+
Collaborator c;
6+
public ClassUnderTest(){
7+
// default is to pass a broken Collaborator, test should pass one
8+
// that doesn't throw exception
9+
this(new Collaborator(){
10+
public void doBusinessStuff() {
11+
throw new AssertionError("Default collaborator's behavior is complicating testing.");
12+
}
13+
});
14+
}
15+
public ClassUnderTest(Collaborator c){
16+
this.c = c;
17+
}
18+
public boolean doSomething(){
19+
c.doBusinessStuff();
20+
return true;
21+
}
22+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.sandwich.koan.exampleclasses;
2+
3+
4+
public interface Collaborator {
5+
6+
public void doBusinessStuff();
7+
8+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.sandwich.util;
2+
3+
import java.util.Map.Entry;
4+
5+
/**
6+
* Why on earth this wasn't around when JDK5 was released is just as bad as
7+
* string.isEmpty()'s absence jeesh!
8+
*
9+
* @param <K>
10+
* @param <V>
11+
*/
12+
public class SimpleEntry<K,V> implements Entry<K,V>{
13+
14+
private K k;
15+
private V v;
16+
17+
public SimpleEntry(K k, V v){
18+
this.k = k;
19+
this.v = v;
20+
}
21+
22+
public K getKey() {
23+
return k;
24+
}
25+
26+
public V getValue() {
27+
return v;
28+
}
29+
30+
public V setValue(V value) {
31+
V tmp = v;
32+
v = value;
33+
return tmp;
34+
}
35+
36+
@Override
37+
public int hashCode() {
38+
final int prime = 31;
39+
int result = 1;
40+
result = prime * result + ((k == null) ? 0 : k.hashCode());
41+
result = prime * result + ((v == null) ? 0 : v.hashCode());
42+
return result;
43+
}
44+
45+
@Override
46+
public boolean equals(Object obj) {
47+
if (this == obj)
48+
return true;
49+
if (obj == null)
50+
return false;
51+
if(!Entry.class.isAssignableFrom(SimpleEntry.class)){
52+
return false;
53+
}
54+
Entry<?,?> other = (Entry<?,?>) obj;
55+
if (k == null) {
56+
if (other.getKey() != null)
57+
return false;
58+
} else if (!k.equals(other.getKey()))
59+
return false;
60+
if (v == null) {
61+
if (other.getValue() != null)
62+
return false;
63+
} else if (!v.equals(other.getValue()))
64+
return false;
65+
return true;
66+
}
67+
68+
}

0 commit comments

Comments
 (0)