Skip to content

Commit e6fb98e

Browse files
committed
forgot a few files
1 parent b30b520 commit e6fb98e

4 files changed

Lines changed: 198 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.sandwich.koan.cmdline;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collections;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
import com.sandwich.koan.constant.ArgumentType;
9+
10+
public class CommandLineArgumentRunner implements Runnable {
11+
12+
private final Map<ArgumentType, CommandLineArgument> commandLineArguments;
13+
14+
public CommandLineArgumentRunner(){
15+
this(new CommandLineArgumentBuilder());
16+
}
17+
18+
public CommandLineArgumentRunner(Map<ArgumentType, CommandLineArgument> commandLineArguments) {
19+
this.commandLineArguments = Collections.unmodifiableMap(commandLineArguments);
20+
}
21+
22+
public void run() {
23+
List<CommandLineArgument> sortedArguments = new ArrayList<CommandLineArgument>(commandLineArguments.values());
24+
Collections.sort(sortedArguments);
25+
for(CommandLineArgument argument : sortedArguments){
26+
argument.run();
27+
}
28+
}
29+
30+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.sandwich.koan.result;
2+
3+
public class KoanBatchResult {
4+
5+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.sandwich.koan.result;
2+
3+
import com.sandwich.koan.KoanMethod;
4+
5+
public class KoanMethodResult {
6+
7+
public final static KoanMethodResult PASSED = new KoanMethodResult(null,"PASSED","PASSED");
8+
9+
private final String message;
10+
private final String lineNumber;
11+
private final KoanMethod failingMethod;
12+
13+
public KoanMethodResult(KoanMethod failingMethod, String message, String lineNumber){
14+
this.message = message;
15+
this.failingMethod = failingMethod;
16+
this.lineNumber = lineNumber;
17+
}
18+
19+
public static KoanMethodResult getPassing() {
20+
return PASSED;
21+
}
22+
23+
public String getMessage() {
24+
return message;
25+
}
26+
27+
public String getLineNumber() {
28+
return lineNumber;
29+
}
30+
31+
public KoanMethod getFailingMethod() {
32+
return failingMethod;
33+
}
34+
35+
public boolean isPassed(){
36+
return this == PASSED;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return "KoanMethodResult [message=" + message + ", lineNumber="
42+
+ lineNumber + ", failingMethod=" + failingMethod + "]";
43+
}
44+
45+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package com.sandwich.koan.result;
2+
3+
import java.util.Collections;
4+
import java.util.List;
5+
6+
import com.sandwich.koan.KoanMethod;
7+
import com.sandwich.util.Builder;
8+
9+
public class KoanSuiteResult {
10+
11+
private final KoanResultModel state;
12+
13+
static class KoanResultModel {
14+
String level;
15+
int numberPassing = -1;
16+
int totalNumberOfKoanMethods = -1;
17+
List<String> passingCases;
18+
List<String> remainingCases;
19+
KoanMethodResult methodResult = KoanMethodResult.PASSED;
20+
@Override
21+
public String toString() {
22+
return "KoanResult [level=" + level + ", numberPassing="
23+
+ numberPassing + ", totalNumberOfKoanMethods="
24+
+ totalNumberOfKoanMethods
25+
+ ", passingCases=" + passingCases + ", remainingCases="
26+
+ remainingCases + ", failingMethod=" + methodResult.getFailingMethod()
27+
+ ", message=" + methodResult.getMessage() + ", lineNumber=" + methodResult.getLineNumber() + "]";
28+
}
29+
}
30+
31+
KoanSuiteResult(KoanResultModel state) {
32+
this.state = state;
33+
}
34+
35+
public static class KoanResultBuilder implements Builder<KoanSuiteResult>{
36+
37+
private final KoanResultModel state = new KoanResultModel();
38+
39+
public KoanResultBuilder level(String level){
40+
state.level = level; return this;
41+
}
42+
public KoanResultBuilder numberPassing(int numberPassing){
43+
state.numberPassing = numberPassing; return this;
44+
}
45+
public KoanResultBuilder totalNumberOfKoanMethods(int totalNumberOfKoanMethods){
46+
state.totalNumberOfKoanMethods = totalNumberOfKoanMethods; return this;
47+
}
48+
@SuppressWarnings("unchecked") // immutable and empty - its safe
49+
public KoanResultBuilder passingCases(List<String> passingCases){
50+
state.passingCases = passingCases == null ?
51+
Collections.EMPTY_LIST : passingCases;
52+
return this;
53+
}
54+
@SuppressWarnings("unchecked") // immutable and empty - its safe
55+
public KoanResultBuilder remainingCases(List<String> remainingCases){
56+
state.remainingCases = remainingCases == null ?
57+
Collections.EMPTY_LIST : remainingCases;
58+
return this;
59+
}
60+
public KoanResultBuilder methodResult(KoanMethodResult methodResult){
61+
state.methodResult = methodResult == null ? KoanMethodResult.PASSED : methodResult; return this;
62+
}
63+
public KoanSuiteResult build() {
64+
return new KoanSuiteResult(state);
65+
}
66+
}
67+
68+
public int getNumberPassing() {
69+
return state.numberPassing;
70+
}
71+
72+
public int getTotalNumberOfKoans(){
73+
return state.totalNumberOfKoanMethods;
74+
}
75+
76+
public String getFailingCase() {
77+
return state.remainingCases.isEmpty() ? null : state.remainingCases.get(0);
78+
}
79+
80+
public KoanMethod getFailingMethod() {
81+
return state.methodResult.getFailingMethod();
82+
}
83+
84+
public String getMessage() {
85+
return state.methodResult.getMessage();
86+
}
87+
88+
public List<String> getPassingSuites() {
89+
return state.passingCases;
90+
}
91+
92+
public List<String> getRemainingSuites() {
93+
return state.remainingCases;
94+
}
95+
96+
public String getLineNumber(){
97+
return state.methodResult.getLineNumber();
98+
}
99+
100+
public boolean isAllKoansSuccessful() {
101+
return state.methodResult == KoanMethodResult.PASSED;
102+
}
103+
104+
public String getLevel() {
105+
return state.level;
106+
}
107+
108+
@Override
109+
public String toString() {
110+
return state.toString();
111+
}
112+
113+
public boolean displayIncompleteException() {
114+
return getFailingMethod() == null || getFailingMethod().displayIncompleteException();
115+
}
116+
117+
118+
}

0 commit comments

Comments
 (0)