Skip to content

Commit bd2660e

Browse files
committed
reformatted the code
1 parent aea8e21 commit bd2660e

39 files changed

Lines changed: 2417 additions & 2328 deletions

‎koans/src/advanced/AboutMocks.java‎

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
11
package advanced;
22

33
import com.sandwich.koan.Koan;
4+
45
import static com.sandwich.util.Assert.fail;
56

67
public class AboutMocks {
7-
8-
static interface Collaborator {
9-
public void doBusinessStuff();
10-
}
11-
12-
static class ExplosiveCollaborator implements Collaborator {
13-
public void doBusinessStuff() {
14-
fail("Default collaborator's behavior is complicating testing.");
15-
}
16-
}
17-
18-
static class ClassUnderTest {
19-
Collaborator c;
20-
public ClassUnderTest(){
21-
// default is to pass a broken Collaborator, test should pass one
22-
// that doesn't throw exception
23-
this(new ExplosiveCollaborator());
24-
}
25-
public ClassUnderTest(Collaborator c){
26-
this.c = c;
27-
}
28-
public boolean doSomething(){
29-
c.doBusinessStuff();
30-
return true;
31-
}
32-
}
33-
34-
@Koan
35-
public void simpleAnonymousMock(){
36-
// HINT: pass a safe Collaborator implementation to constructor
37-
// new ClassUnderTest(new Collaborator(){... it should not be the
38-
// objective of this test to test that collaborator, so replace it
39-
new ClassUnderTest().doSomething();
40-
}
41-
8+
9+
static interface Collaborator {
10+
public void doBusinessStuff();
11+
}
12+
13+
static class ExplosiveCollaborator implements Collaborator {
14+
public void doBusinessStuff() {
15+
fail("Default collaborator's behavior is complicating testing.");
16+
}
17+
}
18+
19+
static class ClassUnderTest {
20+
Collaborator c;
21+
22+
public ClassUnderTest() {
23+
// default is to pass a broken Collaborator, test should pass one
24+
// that doesn't throw exception
25+
this(new ExplosiveCollaborator());
26+
}
27+
28+
public ClassUnderTest(Collaborator c) {
29+
this.c = c;
30+
}
31+
32+
public boolean doSomething() {
33+
c.doBusinessStuff();
34+
return true;
35+
}
36+
}
37+
38+
@Koan
39+
public void simpleAnonymousMock() {
40+
// HINT: pass a safe Collaborator implementation to constructor
41+
// new ClassUnderTest(new Collaborator(){... it should not be the
42+
// objective of this test to test that collaborator, so replace it
43+
new ClassUnderTest().doSomething();
44+
}
45+
4246
}
Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,76 @@
11
package beginner;
22

3-
import static com.sandwich.koan.constant.KoanConstants.__;
4-
import static com.sandwich.util.Assert.assertEquals;
3+
import com.sandwich.koan.Koan;
54

65
import java.util.Arrays;
76

8-
import com.sandwich.koan.Koan;
7+
import static com.sandwich.koan.constant.KoanConstants.__;
8+
import static com.sandwich.util.Assert.assertEquals;
99

1010
public class AboutArrays {
1111

12-
@Koan
13-
public void arraysDoNotConsiderElementsWhenEvaluatingEquality(){
14-
// arrays utilize default object equality (A == {1} B == {1}, though A
15-
// and B contain the same thing, the container is not the same
16-
// referenced array instance...
17-
assertEquals(new int[] {1}.equals(new int[] {1}), __);
18-
}
19-
20-
@Koan
21-
public void cloneEqualityIsNotRespected(){ //!
22-
int[] original = new int[] { 1 };
23-
assertEquals(original.equals(original.clone()), __);
24-
}
25-
26-
@Koan
27-
public void anArraysHashCodeMethodDoesNotConsiderElements(){
28-
int[] array0 = new int[]{0};
29-
int[] array1 = new int[]{0};
30-
assertEquals(Integer.valueOf(array0.hashCode()).equals(array1.hashCode()), __); // not equal!
31-
// TODO: ponder the consequences when arrays are used in Hash Collection implementations.
32-
}
33-
34-
@Koan
35-
public void arraysHelperClassEqualsMethodConsidersElementsWhenDeterminingEquality(){
36-
int[] array0 = new int[]{0};
37-
int[] array1 = new int[]{0};
38-
assertEquals(Arrays.equals(array0, array1), __); // whew - what most people assume
39-
// about equals in regard to arrays! (logical equality)
40-
}
12+
@Koan
13+
public void arraysDoNotConsiderElementsWhenEvaluatingEquality() {
14+
// arrays utilize default object equality (A == {1} B == {1}, though A
15+
// and B contain the same thing, the container is not the same
16+
// referenced array instance...
17+
assertEquals(new int[]{1}.equals(new int[]{1}), __);
18+
}
19+
20+
@Koan
21+
public void cloneEqualityIsNotRespected() { //!
22+
int[] original = new int[]{1};
23+
assertEquals(original.equals(original.clone()), __);
24+
}
25+
26+
@Koan
27+
public void anArraysHashCodeMethodDoesNotConsiderElements() {
28+
int[] array0 = new int[]{0};
29+
int[] array1 = new int[]{0};
30+
assertEquals(Integer.valueOf(array0.hashCode()).equals(array1.hashCode()), __); // not equal!
31+
// TODO: ponder the consequences when arrays are used in Hash Collection implementations.
32+
}
33+
34+
@Koan
35+
public void arraysHelperClassEqualsMethodConsidersElementsWhenDeterminingEquality() {
36+
int[] array0 = new int[]{0};
37+
int[] array1 = new int[]{0};
38+
assertEquals(Arrays.equals(array0, array1), __); // whew - what most people assume
39+
// about equals in regard to arrays! (logical equality)
40+
}
41+
42+
@Koan
43+
public void arraysHelperClassHashCodeMethodConsidersElementsWhenDeterminingHashCode() {
44+
int[] array0 = new int[]{0};
45+
int[] array1 = new int[]{0};
46+
// whew - what most people assume about hashCode in regard to arrays!
47+
assertEquals(Integer.valueOf(Arrays.hashCode(array0)).equals(Arrays.hashCode(array1)), __);
48+
}
49+
50+
@Koan
51+
public void arraysAreMutable() {
52+
final boolean[] oneBoolean = new boolean[]{false};
53+
oneBoolean[0] = true;
54+
assertEquals(oneBoolean[0], __);
55+
}
56+
57+
@Koan
58+
public void arraysAreIndexedAtZero() {
59+
int[] integers = new int[]{1, 2};
60+
assertEquals(integers[0], __);
61+
assertEquals(integers[1], __);
62+
}
63+
64+
@Koan
65+
public void arrayIndexOutOfBounds() {
66+
int[] array = new int[]{1};
67+
@SuppressWarnings("unused")
68+
int meh = array[1]; // remember 0 based indexes, 1 is the 2nd element (which doesn't exist)
69+
}
70+
71+
@Koan
72+
public void arrayLengthCanBeChecked() {
73+
assertEquals(new int[1].length, __);
74+
}
4175

42-
@Koan
43-
public void arraysHelperClassHashCodeMethodConsidersElementsWhenDeterminingHashCode(){
44-
int[] array0 = new int[]{0};
45-
int[] array1 = new int[]{0};
46-
// whew - what most people assume about hashCode in regard to arrays!
47-
assertEquals(Integer.valueOf(Arrays.hashCode(array0)).equals(Arrays.hashCode(array1)), __);
48-
}
49-
50-
@Koan
51-
public void arraysAreMutable(){
52-
final boolean[] oneBoolean = new boolean[]{false};
53-
oneBoolean[0] = true;
54-
assertEquals(oneBoolean[0], __);
55-
}
56-
57-
@Koan
58-
public void arraysAreIndexedAtZero(){
59-
int[] integers = new int[]{1,2};
60-
assertEquals(integers[0], __);
61-
assertEquals(integers[1], __);
62-
}
63-
64-
@Koan
65-
public void arrayIndexOutOfBounds(){
66-
int[] array = new int[]{1};
67-
@SuppressWarnings("unused")
68-
int meh = array[1]; // remember 0 based indexes, 1 is the 2nd element (which doesn't exist)
69-
}
70-
71-
@Koan
72-
public void arrayLengthCanBeChecked(){
73-
assertEquals(new int[1].length, __);
74-
}
75-
7676
}
Lines changed: 54 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,63 @@
11
package beginner;
22

33
// FYI - usually bad practice to import statically, but can make code cleaner
4-
import static com.sandwich.koan.constant.KoanConstants.__;
5-
import static com.sandwich.util.Assert.assertEquals;
6-
import static com.sandwich.util.Assert.assertFalse;
7-
import static com.sandwich.util.Assert.assertNotNull;
8-
import static com.sandwich.util.Assert.assertNotSame;
9-
import static com.sandwich.util.Assert.assertNull;
10-
import static com.sandwich.util.Assert.assertSame;
11-
import static com.sandwich.util.Assert.assertTrue;
124

135
import com.sandwich.koan.Koan;
146

15-
public class AboutAssertions {
16-
17-
@Koan
18-
public void assertBooleanTrue() {
19-
assertTrue(__); // should be true really
20-
}
21-
22-
@Koan
23-
public void assertBooleanFalse() {
24-
assertFalse(__);
25-
}
26-
27-
@Koan
28-
public void assertNullObject(){
29-
assertNull(__);
30-
}
31-
32-
@Koan
33-
public void assertNotNullObject(){
34-
assertNotNull(null); // anything other than null should pass here...
35-
}
36-
37-
@Koan
38-
public void assertEqualsUsingExpression(){
39-
assertTrue("Hello World!".equals(__));
40-
}
7+
import static com.sandwich.koan.constant.KoanConstants.__;
8+
import static com.sandwich.util.Assert.*;
419

42-
@Koan
43-
public void assertEqualsWithBetterFailureMessage(){
44-
assertEquals(1, __);
45-
}
10+
public class AboutAssertions {
4611

47-
@Koan
48-
public void assertEqualsWithDescriptiveMessage() {
49-
// Generally, when using an assertXXX methods, expectation is on the
50-
// left and it is best practice to use a String for the first arg
51-
// indication what has failed
52-
assertEquals("The answer to 'life the universe and everything' should be 42", 42, __);
53-
}
54-
55-
@Koan
56-
public void assertSameInstance(){
57-
Object same = new Integer(1);
58-
Object sameReference = __;
59-
assertSame(same, sameReference);
60-
}
61-
62-
@Koan
63-
public void assertNotSameInstance(){
64-
Integer same = new Integer(1);
65-
Integer sameReference = same;
66-
assertNotSame(same, sameReference);
67-
}
12+
@Koan
13+
public void assertBooleanTrue() {
14+
assertTrue(__); // should be true really
15+
}
16+
17+
@Koan
18+
public void assertBooleanFalse() {
19+
assertFalse(__);
20+
}
21+
22+
@Koan
23+
public void assertNullObject() {
24+
assertNull(__);
25+
}
26+
27+
@Koan
28+
public void assertNotNullObject() {
29+
assertNotNull(null); // anything other than null should pass here...
30+
}
31+
32+
@Koan
33+
public void assertEqualsUsingExpression() {
34+
assertTrue("Hello World!".equals(__));
35+
}
36+
37+
@Koan
38+
public void assertEqualsWithBetterFailureMessage() {
39+
assertEquals(1, __);
40+
}
41+
42+
@Koan
43+
public void assertEqualsWithDescriptiveMessage() {
44+
// Generally, when using an assertXXX methods, expectation is on the
45+
// left and it is best practice to use a String for the first arg
46+
// indication what has failed
47+
assertEquals("The answer to 'life the universe and everything' should be 42", 42, __);
48+
}
49+
50+
@Koan
51+
public void assertSameInstance() {
52+
Object same = new Integer(1);
53+
Object sameReference = __;
54+
assertSame(same, sameReference);
55+
}
56+
57+
@Koan
58+
public void assertNotSameInstance() {
59+
Integer same = new Integer(1);
60+
Integer sameReference = same;
61+
assertNotSame(same, sameReference);
62+
}
6863
}

0 commit comments

Comments
 (0)