Skip to content

Commit c068176

Browse files
committed
merge conflicts, moved util code into koans, corrected AboutCasting (one
koan was passing)
1 parent 2cf3e54 commit c068176

6 files changed

Lines changed: 58 additions & 78 deletions

File tree

‎koans-lib/src/com/sandwich/koan/runner/RunKoans.java‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@ KoanSuiteResult runKoans() {
5151
DynamicClassLoader loader = new DynamicClassLoader();
5252
Path pathToEnlightenment = getPathToEnlightenment();
5353
KoanSuiteCompilationListener compilationListener = new KoanSuiteCompilationListener();
54-
<<<<<<< HEAD
5554
int successfull = 0;
56-
for (Entry<String, Map<String, Map<String, KoanElementAttributes>>> packages : pathToEnlightement) {
57-
=======
5855
for (Entry<String, Map<String, Map<String, KoanElementAttributes>>> packages : pathToEnlightenment) {
59-
>>>>>>> 81d381746890bea20bccf589fa8e5ed63a9ec90b
6056
for (Entry<String, Map<String, KoanElementAttributes>> e : packages.getValue().entrySet()) {
6157
String name = e.getKey().substring(e.getKey().lastIndexOf('.')+1);
6258
if(failure == null){
@@ -85,13 +81,8 @@ KoanSuiteResult runKoans() {
8581
}
8682
}
8783
return new KoanResultBuilder() .level(level)
88-
<<<<<<< HEAD
8984
.numberPassing(successfull)
90-
.totalNumberOfKoanMethods(pathToEnlightement.getTotalNumberOfKoans())
91-
=======
92-
.numberPassing((int)successfull.getCount())
9385
.totalNumberOfKoanMethods(pathToEnlightenment.getTotalNumberOfKoans())
94-
>>>>>>> 81d381746890bea20bccf589fa8e5ed63a9ec90b
9586
.methodResult(failure)
9687
.passingCases(passingSuites).remainingCases(failingSuites).build();
9788
}

‎koans-lib/src/com/sandwich/util/TypeUtils.java‎

Lines changed: 0 additions & 51 deletions
This file was deleted.

‎koans/lib/koans.jar‎

-582 Bytes
Binary file not shown.

‎koans/src/beginner/AboutCasting.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,8 @@ public void upCastAndPolymorphism() {
9797
@Koan
9898
public void classCasting() {
9999
try {
100-
Object o = new Child(); // were downcasting way to far here - would it be possible
101-
// to even compile this koan had we done what was safe, and
102-
// held the reference as Sleepable?
103-
((Sleepable) o).sleep();
100+
Object o = new Object();
101+
((Sleepable) o).sleep(); // would this even compile without the cast?
104102
} catch (ClassCastException x) {
105103
fail("Object does not implement Sleepable, maybe one of the people classes do?");
106104
}
Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
package beginner;
22

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

56
import java.text.MessageFormat;
7+
import java.util.ArrayList;
8+
import java.util.List;
69

7-
import static com.sandwich.koan.constant.KoanConstants.*;
8-
import static com.sandwich.util.Assert.*;
9-
import static com.sandwich.util.TypeUtils.*;
10+
import com.sandwich.koan.Koan;
1011

1112
public class AboutObjects {
1213

13-
@Koan()
14+
@Koan
1415
public void newObjectInstancesCanBeCreatedDirectly() {
1516
assertEquals(new Object() instanceof Object, __);
1617
}
1718

18-
@Koan()
19+
@Koan
1920
public void allClassesInheritFromObject() {
2021
class Foo {}
2122

22-
Class[] ancestors = ancestors(new Foo());
23+
Class<?>[] ancestors = getAncestors(new Foo());
2324
assertEquals(ancestors[0], __);
2425
assertEquals(ancestors[1], __);
2526
}
2627

27-
@Koan()
28+
@Koan
2829
public void objectToString() {
2930
Object object = new Object();
3031
// TODO: Why is it best practice to ALWAYS override toString?
3132
String expectedToString = MessageFormat.format("{0}@{1}", Object.class.getName(), Integer.toHexString(object.hashCode()));
3233
assertEquals(expectedToString, __); // hint: object.toString()
3334
}
3435

35-
@Koan()
36+
@Koan
3637
public void toStringConcatenates(){
3738
final String string = "ha";
3839
Object object = new Object(){
@@ -43,10 +44,20 @@ public void toStringConcatenates(){
4344
assertEquals(string + object, __);
4445
}
4546

46-
@Koan()
47+
@Koan
4748
public void toStringIsTestedForNullWhenInvokedImplicitly(){
4849
String string = "string";
4950
assertEquals(string+null, __);
5051
}
5152

53+
private Class<?>[] getAncestors(Object object) {
54+
List<Class<?>> ancestors = new ArrayList<Class<?>>();
55+
Class<?> clazz = object.getClass();
56+
while(clazz != null) {
57+
ancestors.add(clazz);
58+
clazz = clazz.getSuperclass();
59+
}
60+
return ancestors.toArray(new Class[]{});
61+
}
62+
5263
}

‎koans/src/beginner/AboutPrimitives.java‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package beginner;
22

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

5-
import static com.sandwich.koan.constant.KoanConstants.*;
6-
import static com.sandwich.util.Assert.*;
7-
import static com.sandwich.util.TypeUtils.*;
6+
import com.sandwich.koan.Koan;
87

98
public class AboutPrimitives {
109

@@ -193,4 +192,36 @@ public void floatSize() {
193192
assertEquals(Float.SIZE, __);
194193
}
195194

195+
private Class<?> getType(int value) {
196+
return int.class;
197+
}
198+
199+
private Class<?> getType(long value) {
200+
return long.class;
201+
}
202+
203+
private Class<?> getType(float value) {
204+
return float.class;
205+
}
206+
207+
private Class<?> getType(double value) {
208+
return double.class;
209+
}
210+
211+
private Class<?> getType(byte value) {
212+
return byte.class;
213+
}
214+
215+
private Class<?> getType(char value) {
216+
return char.class;
217+
}
218+
219+
private Class<?> getType(short value) {
220+
return short.class;
221+
}
222+
223+
private Class<?> getType(Object value) {
224+
return value.getClass();
225+
}
226+
196227
}

0 commit comments

Comments
 (0)