Skip to content

Commit 1164cff

Browse files
committed
merging pull request from hvolkmer (AboutCasting, AboutPrimitives - very nice) and making lesson optional in PathToEnlightenment.xml
1 parent 819527d commit 1164cff

10 files changed

Lines changed: 39 additions & 42 deletions

File tree

‎koans-lib/src/com/sandwich/koan/constant/KoanConstants.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ private KoanConstants(){}
1313

1414
public static final String __ = "REPLACE ME";
1515
public static final String PATH_XML_NAME = "PathToEnlightment.xml";
16-
// public static final String PATH_XML = "src/"; // TODO: Adapt so osx and windows dont need to
16+
// public static final String PATH_XML = "src/"; // TODO: Adapt so dev and deployed can use same path
1717
public static final String PATH_XML = "";
1818
public static final String PATH_XML_LOCATION = PATH_XML+PATH_XML_NAME;
1919

‎koans-lib/src/com/sandwich/koan/path/PathToEnlightenment.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static void stagePathToEnlightenment(Object koanSuite) {
123123
private static Map<String, KoanElementAttributes> createBogusLessonMap(
124124
Class<? extends Object> clazz) {
125125
Map<String, KoanElementAttributes> bogusLessonByKoanMap = new HashMap<String, KoanElementAttributes>();
126-
String fakeLesson = "for testing - no real lesson";
126+
String fakeLesson = "bogus lesson - not read from xml";
127127
for(Method m : clazz.getMethods()){
128128
bogusLessonByKoanMap.put(m.getName(), new KoanElementAttributes(fakeLesson, m.getName(), "true"));
129129
}

‎koans-lib/src/com/sandwich/koan/path/xmltransformation/XmlToPathTransformer.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ static Map<String, KoanElementAttributes> extractKoansAndRawLessons(
8888
if("Koan".equalsIgnoreCase(node.getNodeName())){
8989
NamedNodeMap attributes = node.getAttributes();
9090
String name = attributes.getNamedItem("name").getNodeValue();
91-
String rawLesson = attributes.getNamedItem("lesson").getNodeValue();
91+
Node lesson = attributes.getNamedItem("lesson");
92+
String rawLesson = lesson == null ? null : lesson.getNodeValue();
9293
Node displayKoanIncompleteExceptionNode = attributes.getNamedItem("displayIncompleteKoanException");
9394
String displayIncompleteKoanException = displayKoanIncompleteExceptionNode == null ?
9495
null : displayKoanIncompleteExceptionNode.getNodeValue();

‎koans-lib/src/com/sandwich/koan/path/xmltransformation/XmlVariableInjector.java‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ public class XmlVariableInjector {
1414

1515

1616
public XmlVariableInjector(String lesson, Method koanMethod){
17-
if(lesson == null){
18-
throw new IllegalArgumentException("lesson may not be null");
19-
}
2017
if(koanMethod == null){
2118
throw new IllegalArgumentException("koanMethod may not be null");
2219
}
@@ -28,7 +25,7 @@ public XmlVariableInjector(String lesson, Method koanMethod){
2825
}
2926

3027
public String injectLessonVariables() {
31-
if(lesson.length() == 0 ||
28+
if(lesson == null || lesson.length() == 0 ||
3229
lesson.indexOf(KoanConstants.XML_PARAMETER_START) < 0){
3330
return lesson;
3431
}

‎koans-lib/src/com/sandwich/koan/ui/ConsolePresenter.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ protected void displayOneOrMoreFailure(KoanSuiteResult result) {
106106
protected void printSuggestion(KoanSuiteResult result) {
107107
KoanMethod failedKoan = result.getFailingMethod();
108108
StringBuilder sb = buildLessonLine(failedKoan);
109-
sb.append(EOL).append(EOL);
110109
buildInvestigateLine(sb, result.getFailingCase().getSimpleName(),failedKoan.getMethod().getName());
111110
sb.append(EOL).append(EOL);
112111
buildLineClue(sb, result);
@@ -135,6 +134,10 @@ private StringBuilder buildLineClue(StringBuilder sb, KoanSuiteResult result) {
135134
}
136135

137136
private StringBuilder buildLessonLine(KoanMethod failedKoan) {
138-
return new StringBuilder(failedKoan.getLesson());
137+
String lesson = failedKoan.getLesson();
138+
if(lesson == null){
139+
return new StringBuilder(); // no lesson
140+
}
141+
return new StringBuilder(lesson).append(EOL).append(EOL);
139142
}
140143
}

‎koans/data/src/PathToEnlightment.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="ISO-8859-1"?>
22
<Packages>
3-
<Package pkg="beginner" name="Beginner">
3+
<Package pkg="beginner" name="Novice">
44
<!--
55
TODO: AboutKoans...
66
-->
@@ -94,4 +94,4 @@
9494
lesson="How can this pass without touching the ClassUnderTest?"/>
9595
</Suite>
9696
</Package>
97-
</Packages>
97+
</Packages>

‎koans/lib/koans.jar‎

-28.9 KB
Binary file not shown.

‎koans/src/PathToEnlightment.xml‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="ISO-8859-1"?>
22
<Packages>
3-
<Package pkg="beginner" name="Beginner">
3+
<Package pkg="beginner" name="Novice">
44
<!--
55
TODO: AboutKoans...
66
-->
@@ -55,6 +55,17 @@
5555
<Koan name="toStringIsTestedForNullWhenInvokedImplicitly"
5656
lesson="String concatenation implicitly invokes toString on Objects, unless they are null. Notice no NullPointerException is thrown."/>
5757
</Suite>
58+
<Suite class="AboutCasting">
59+
<Koan name="longPlusInt" />
60+
<Koan name="forceIntTypecast" />
61+
<Koan name="implicitTypecast" />
62+
<Koan name="downCastWithInerhitance" />
63+
<Koan name="downCastAndPolymophism" />
64+
<Koan name="upCastWithInheritance" />
65+
<Koan name="upCastAndPolymophism" />
66+
<Koan name="complicatedCast" />
67+
<Koan name="complicatedCastWithInterface" />
68+
</Suite>
5869
<Suite class="AboutArrays">
5970
<Koan name="arraysDoNotConsiderElementsWhenEvaluatingEquality"
6071
lesson="Arrays utilize reference equality, they do not consider elements when determining equality."/>
@@ -75,6 +86,15 @@
7586
<Koan name="arrayLengthCanBeChecked"
7687
lesson="It is often necessary to check the length of an array to ensure an index is valid. This is easy with the array's length property."/>
7788
</Suite>
89+
<Suite class="AboutPrimitives">
90+
<Koan name="byteSize" />
91+
<Koan name="shortSize" />
92+
<Koan name="integerSize" />
93+
<Koan name="longSize" />
94+
<Koan name="charSizeAndValue" />
95+
<Koan name="floatSize" />
96+
<Koan name="doubleSize" />
97+
</Suite>
7898
</Package>
7999
<Package pkg="intermediate" name="Intermediate">
80100
<Suite class="AboutAutoboxing">
@@ -94,4 +114,4 @@
94114
lesson="How can this pass without touching the ClassUnderTest?"/>
95115
</Suite>
96116
</Package>
97-
</Packages>
117+
</Packages>

‎koans/src/advanced/AboutMocks.java‎

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,10 @@
11
package advanced;
22

33
import com.sandwich.koan.Koan;
4+
import com.sandwich.koan.exampleclasses.ClassUnderTest;
45

56
public class AboutMocks {
67

7-
/*
8-
* Following two classes are used to demonstrate mocking
9-
*/
10-
static class ClassUnderTest {
11-
Collaborator c;
12-
ClassUnderTest(){
13-
// default is to pass a broken Collaborator, test should pass one
14-
// that doesn't throw exception
15-
this(new Collaborator(){
16-
@Override
17-
public void doBusinessStuff() {
18-
throw new AssertionError("Default collaborator's behavior is complicating testing.");
19-
}
20-
});
21-
}
22-
ClassUnderTest(Collaborator c){
23-
this.c = c;
24-
}
25-
public void doSomething(){
26-
c.doBusinessStuff();
27-
}
28-
}
29-
30-
static interface Collaborator {
31-
public void doBusinessStuff();
32-
}
33-
348
@Koan()
359
public void simpleAnonymousMock(){
3610
// HINT: pass different Collaborator implementation to constructor

‎koans/src/beginner/AboutCasting.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66
import com.sandwich.koan.Koan;
77

8+
@SuppressWarnings("unused")
89
public class AboutCasting {
9-
@Koan
10+
11+
@Koan
1012
public void longPlusInt() {
1113
int a = 6;
1214
long b = 10;
1315
Object c = a + b;
14-
assertEquals(16, c);
16+
assertEquals(c, __);
1517
assertEquals(c instanceof Integer, __);
1618
assertEquals(c instanceof Long, __);
1719
}

0 commit comments

Comments
 (0)