Skip to content

Commit 3e2085a

Browse files
committed
Merge branch 'takaczapka-master'
2 parents b424cbe + 3e53303 commit 3e2085a

197 files changed

Lines changed: 3291 additions & 2942 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
11
<?xml version="1.0" encoding="ISO-8859-1"?>
22
<packages>
3-
<package pkg="beginner" name="Novice">
4-
<suite class="AboutKoans">
5-
<koan name="findAboutKoansFile" displayIncompleteKoanException="false" />
6-
<koan name="definitionOfKoanCompletion" displayIncompleteKoanException="false" />
7-
</suite>
8-
<suite class="AboutAssertions"/>
9-
<!-- TODO: AboutDataTypes... -->
10-
<suite class="AboutEquality"/>
11-
<suite class="AboutPrimitives" />
12-
<suite class="AboutStrings"/>
13-
<suite class="AboutObjects"/>
14-
<suite class="AboutLoops" />
15-
<suite class="AboutInheritance"/>
16-
<suite class="AboutCasting"/>
17-
<suite class="AboutConditionals"/>
18-
<suite class="AboutConstructors"/>
19-
<suite class="AboutEnums"/>
20-
<suite class="AboutExceptions"/>
21-
<suite class="AboutMethodPreference"/>
22-
<suite class="AboutOperators"/>
23-
<suite class="AboutArrays"/>
24-
<suite class="AboutVarArgs"/>
25-
</package>
26-
<package pkg="intermediate" name="Intermediate">
27-
<suite class="AboutAutoboxing"/>
28-
<suite class="AboutCollections"/>
29-
<suite class="AboutComparison"/>
30-
<suite class="AboutDates"/>
31-
<suite class="AboutEquality"/>
32-
<suite class="AboutFileIO"/>
33-
<suite class="AboutInnerClasses"/>
34-
<suite class="AboutLocale"/>
35-
<suite class="AboutRegularExpressions"/>
36-
<suite class="AboutSerialization"/>
37-
</package>
38-
<package pkg="advanced" name="Advanced">
39-
<suite class="AboutMocks"/>
40-
</package>
41-
<package pkg="java7" name="Java 7">
42-
<suite class="AboutJava7LiteralsEnhancements"/>
43-
<suite class="AboutStringsInSwitch"/>
44-
<suite class="AboutDiamondOperator"/>
45-
<suite class="AboutTryWithResources"/>
46-
<suite class="AboutRequireNotNull"/>
47-
</package>
48-
<package pkg="java8" name="Java 8">
49-
<suite class="AboutDefaultMethods"/>
50-
<suite class="AboutOptional"/>
51-
<suite class="AboutLocalTime"/>
52-
<suite class="AboutLambdas"/>
53-
<suite class="AboutStreams"/>
54-
<suite class="AboutMultipleInheritance"/>
55-
</package>
3+
<package pkg="beginner" name="Novice">
4+
<suite class="AboutKoans">
5+
<koan name="findAboutKoansFile" displayIncompleteKoanException="false" />
6+
<koan name="definitionOfKoanCompletion" displayIncompleteKoanException="false" />
7+
</suite>
8+
<suite class="AboutAssertions"/>
9+
<suite class="AboutEquality"/>
10+
<suite class="AboutStrings"/>
11+
<suite class="AboutArithmeticOperators"/>
12+
<suite class="AboutConditionals"/>
13+
<suite class="AboutLoops" />
14+
<suite class="AboutPrimitives" />
15+
<suite class="AboutObjects"/>
16+
<suite class="AboutInheritance"/>
17+
<suite class="AboutCasting"/>
18+
<suite class="AboutConstructors"/>
19+
<suite class="AboutEnums"/>
20+
<suite class="AboutExceptions"/>
21+
<suite class="AboutMethodPreference"/>
22+
<suite class="AboutBitwiseOperators"/>
23+
<suite class="AboutArrays"/>
24+
<suite class="AboutVarArgs"/>
25+
</package>
26+
<package pkg="intermediate" name="Intermediate">
27+
<suite class="AboutAutoboxing"/>
28+
<suite class="AboutCollections"/>
29+
<suite class="AboutComparison"/>
30+
<suite class="AboutDates"/>
31+
<suite class="AboutEquality"/>
32+
<suite class="AboutFileIO"/>
33+
<suite class="AboutInnerClasses"/>
34+
<suite class="AboutLocale"/>
35+
<suite class="AboutRegularExpressions"/>
36+
<suite class="AboutSerialization"/>
37+
</package>
38+
<package pkg="advanced" name="Advanced">
39+
<suite class="AboutMocks"/>
40+
</package>
41+
<package pkg="java7" name="Java 7">
42+
<suite class="AboutJava7LiteralsEnhancements"/>
43+
<suite class="AboutStringsInSwitch"/>
44+
<suite class="AboutDiamondOperator"/>
45+
<suite class="AboutTryWithResources"/>
46+
<suite class="AboutRequireNotNull"/>
47+
</package>
48+
<package pkg="java8" name="Java 8">
49+
<suite class="AboutDefaultMethods"/>
50+
<suite class="AboutOptional"/>
51+
<suite class="AboutLocalTime"/>
52+
<suite class="AboutLambdas"/>
53+
<suite class="AboutStreams"/>
54+
<suite class="AboutMultipleInheritance"/>
55+
</package>
5656
</packages>

‎koans/app/config/config.properties‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ debug=false
33
exit_character=Q
44
enable_encouragement=false
55
path_xml_filename=PathToEnlightenment.xml
6+
enable_expectation_result=false

‎koans/app/lib/koans.jar‎

32.3 KB
Binary file not shown.

‎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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package beginner;
2+
3+
import com.sandwich.koan.Koan;
4+
5+
import static com.sandwich.koan.constant.KoanConstants.__;
6+
import static com.sandwich.util.Assert.assertEquals;
7+
8+
public class AboutArithmeticOperators {
9+
10+
@Koan
11+
public void simpleOperations() {
12+
assertEquals(1, __);
13+
assertEquals(1 + 1, __);
14+
assertEquals(2 + 3 * 4, __);
15+
assertEquals((2 + 3) * 4, __);
16+
assertEquals(2 * 3 + 4, __);
17+
assertEquals(2 - 3 + 4, __);
18+
assertEquals(2 + 4 / 2, __);
19+
assertEquals((2 + 4) / 2, __);
20+
}
21+
22+
@Koan
23+
public void notSoSimpleOperations() {
24+
assertEquals(1 / 2, __);
25+
assertEquals(3 / 2, __);
26+
assertEquals(1 % 2, __);
27+
assertEquals(3 % 2, __);
28+
}
29+
30+
@Koan
31+
public void minusMinusVariableMinusMinus() {
32+
int i = 1;
33+
assertEquals(--i, __);
34+
assertEquals(i, __);
35+
assertEquals(i--, __);
36+
assertEquals(i, __);
37+
}
38+
39+
@Koan
40+
public void plusPlusVariablePlusPlus() {
41+
int i = 1;
42+
assertEquals(++i, __);
43+
assertEquals(i, __);
44+
assertEquals(i++, __);
45+
assertEquals(i, __);
46+
}
47+
48+
@Koan
49+
public void timesAndDivInPlace() {
50+
int i = 1;
51+
i *= 2;
52+
assertEquals(i, __);
53+
i /= 2;
54+
assertEquals(i, __);
55+
}
56+
57+
}
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
}

0 commit comments

Comments
 (0)