This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javac -d bin src/boss/ScoreCollection.java | |
javac -cp lib\junit-4.13.jar -d bin test/boss/ScoreCollectionTest.java | |
javac -cp lib\junit-4.13.jar;bin -d bin test/boss/TestRunner.java | |
java -cp bin;lib/junit-4.13.jar;lib/hamcrest-core-1.3.jar boss.TestRunner | |
Result: | |
test(boss.ScoreCollectionTest): Not yet implemented | |
false | |
For version 2: | |
javac -cp bin;lib\junit-4.13.jar;lib\hamcrest-core-1.3.jar -d bin test/boss/ScoreCollectionTest.java | |
java -cp bin;lib/junit-4.13.jar;lib/hamcrest-core-1.3.jar boss.TestRunner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package boss; | |
@FunctionalInterface | |
public interface Scoreable { | |
int getScore(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package boss; | |
import java.util.*; | |
public class ScoreCollection { | |
private List<Scoreable> scores = new ArrayList<>(); | |
public void add(Scoreable scoreable) { | |
scores.add(scoreable); | |
} | |
public int arithmeticMean() { | |
int total = scores.stream().mapToInt(Scoreable::getScore).sum(); | |
return total / scores.size(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package boss; | |
import static org.junit.Assert.*; | |
import org.junit.*; | |
public class ScoreCollectionTest { | |
@Test | |
public void test() { | |
fail("Not yet implemented"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package boss; | |
import static org.junit.Assert.*; | |
import static org.hamcrest.core.IsEqual.equalTo; | |
import static org.hamcrest.MatcherAssert.assertThat; | |
import org.junit.*; | |
public class ScoreCollectionTest { | |
@Test | |
public void answersArithmeticMeanOfTwoNumbers() { | |
ScoreCollection coll = new ScoreCollection(); | |
coll.add(() -> 5); | |
coll.add(() -> 7); | |
int actualResult = coll.arithmeticMean(); | |
assertThat(actualResult, equalTo(6)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package boss; | |
import org.junit.runner.JUnitCore; | |
import org.junit.runner.Result; | |
import org.junit.runner.notification.Failure; | |
public class TestRunner { | |
public static void main(String[] args) { | |
Result result = JUnitCore.runClasses(ScoreCollectionTest.class); | |
for (Failure failure : result.getFailures()) { | |
System.out.println(failure.toString()); | |
} | |
System.out.println(result.wasSuccessful()); | |
} | |
} |