mirror of
https://github.com/ysoftdevs/Theatrical-Players-Refactoring-Kata.git
synced 2026-03-25 10:52:53 +01:00
updated java version so it matches javascript version of tests
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
# Video store kata
|
||||
|
||||
Based on the book 'Refactoring' by Martin Fowler. More information on this book can be found on https://martinfowler.com/books/refactoring.html
|
||||
|
||||
Imagine a company of theatrical players who go out to various events performing plays. Typically, a customer will request a few plays and the company charges
|
||||
them based on the size of the audience and the kind of play they perform. There are currently two kinds of plays that the company performs: tragedies and comedies. As well as providing a bill for the performance, the company gives its customers “volume credits” which they can use for discounts on future performances—think of it as a customer loyalty mechanism.
|
||||
|
||||
Plays.json
|
||||
```json
|
||||
{
|
||||
"hamlet": {"name": "Hamlet", "type": "tragedy"},
|
||||
"as-like": {"name": "As You Like It", "type": "comedy"},
|
||||
"othello": {"name": "Othello", "type": "tragedy"}
|
||||
}
|
||||
```
|
||||
|
||||
Invoices.json
|
||||
```json
|
||||
[
|
||||
{
|
||||
"customer": "BigCo",
|
||||
"performances": [
|
||||
{
|
||||
"playID": "hamlet",
|
||||
"audience": 55
|
||||
},
|
||||
{
|
||||
"playID": "as-like",
|
||||
"audience": 35
|
||||
},
|
||||
{
|
||||
"playID": "othello",
|
||||
"audience": 40
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
```
|
||||
@@ -2,7 +2,7 @@ apply plugin: 'java'
|
||||
|
||||
group 'kata'
|
||||
version '1.0-SNAPSHOT'
|
||||
sourceCompatibility = 12
|
||||
sourceCompatibility = 11
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -17,5 +17,5 @@ test {
|
||||
|
||||
dependencies {
|
||||
testCompile 'org.junit.jupiter:junit-jupiter:5.5.1'
|
||||
testCompile 'org.assertj:assertj-core:3.13.2'
|
||||
testCompile 'com.approvaltests:approvaltests:3.2.0'
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#Thu Aug 08 12:26:45 CEST 2019
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -36,7 +36,7 @@ public class StatementPrinter {
|
||||
// add volume credits
|
||||
volumeCredits += Math.max(perf.audience - 30, 0);
|
||||
// add extra credit for every ten comedy attendees
|
||||
if ("comedy" == play.type) volumeCredits += Math.floor(perf.audience / 5);
|
||||
if ("comedy".equals(play.type)) volumeCredits += Math.floor(perf.audience / 5);
|
||||
|
||||
// print line for this order
|
||||
result += String.format(" %s: %s (%s seats)\n", play.name, frmt.format(thisAmount / 100), perf.audience);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
Statement for BigCo
|
||||
Hamlet: $650.00 (55 seats)
|
||||
As You Like It: $580.00 (35 seats)
|
||||
Othello: $500.00 (40 seats)
|
||||
Amount owed is $1,730.00
|
||||
You earned 47 credits
|
||||
@@ -1,30 +1,44 @@
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.approvaltests.Approvals.verify;
|
||||
|
||||
public class StatementPrinterTests {
|
||||
|
||||
@Test
|
||||
void printsStatements() {
|
||||
Map<String, Play> plays = Map.of("hamlet", new Play("Hamlet", "tragedy"),
|
||||
void exampleStatement() {
|
||||
Map<String, Play> plays = Map.of(
|
||||
"hamlet", new Play("Hamlet", "tragedy"),
|
||||
"as-like", new Play("As You Like It", "comedy"),
|
||||
"othello", new Play("Othello", "tragedy"));
|
||||
|
||||
Invoice invoice = new Invoice("BigCo", List.of(new Performance("hamlet", 55),
|
||||
Invoice invoice = new Invoice("BigCo", List.of(
|
||||
new Performance("hamlet", 55),
|
||||
new Performance("as-like", 35),
|
||||
new Performance("othello", 40)));
|
||||
|
||||
StatementPrinter statementPrinter = new StatementPrinter();
|
||||
var result = statementPrinter.print(invoice, plays);
|
||||
|
||||
assertThat(result).isEqualTo("Statement for BigCo\n" +
|
||||
" Hamlet: $650.00 (55 seats)\n" +
|
||||
" As You Like It: $580.00 (35 seats)\n" +
|
||||
" Othello: $500.00 (40 seats)\n" +
|
||||
"Amount owed is $1,730.00\n" +
|
||||
"You earned 47 credits\n");
|
||||
verify(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void statementWithNewPlayTypes() {
|
||||
Map<String, Play> plays = Map.of(
|
||||
"henry-v", new Play("Henry V", "history"),
|
||||
"as-like", new Play("As You Like It", "pastoral"));
|
||||
|
||||
Invoice invoice = new Invoice("BigCo", List.of(
|
||||
new Performance("henry-v", 53),
|
||||
new Performance("as-like", 55)));
|
||||
|
||||
StatementPrinter statementPrinter = new StatementPrinter();
|
||||
Assertions.assertThrows(Error.class, () -> {
|
||||
statementPrinter.print(invoice, plays);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user