From f20b30d0b89dbd97b43364d841c23b763b31b14e Mon Sep 17 00:00:00 2001 From: Emily Bache Date: Tue, 13 Aug 2019 09:38:05 +0200 Subject: [PATCH] updated java version so it matches javascript version of tests --- java/README.md | 38 ------------------- java/build.gradle | 4 +- java/gradle/wrapper/gradle-wrapper.properties | 5 ++- java/src/main/java/StatementPrinter.java | 2 +- ...PrinterTests.exampleStatement.approved.txt | 6 +++ java/src/test/java/StatementPrinterTests.java | 34 ++++++++++++----- 6 files changed, 36 insertions(+), 53 deletions(-) delete mode 100644 java/README.md create mode 100644 java/src/test/java/StatementPrinterTests.exampleStatement.approved.txt diff --git a/java/README.md b/java/README.md deleted file mode 100644 index a33548b..0000000 --- a/java/README.md +++ /dev/null @@ -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 - } - ] - } -] -``` \ No newline at end of file diff --git a/java/build.gradle b/java/build.gradle index b91c990..2ab9497 100644 --- a/java/build.gradle +++ b/java/build.gradle @@ -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' } diff --git a/java/gradle/wrapper/gradle-wrapper.properties b/java/gradle/wrapper/gradle-wrapper.properties index 44e7c4d..0cec7e7 100644 --- a/java/gradle/wrapper/gradle-wrapper.properties +++ b/java/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/java/src/main/java/StatementPrinter.java b/java/src/main/java/StatementPrinter.java index 78419e9..d0c05a9 100644 --- a/java/src/main/java/StatementPrinter.java +++ b/java/src/main/java/StatementPrinter.java @@ -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); diff --git a/java/src/test/java/StatementPrinterTests.exampleStatement.approved.txt b/java/src/test/java/StatementPrinterTests.exampleStatement.approved.txt new file mode 100644 index 0000000..fa59f94 --- /dev/null +++ b/java/src/test/java/StatementPrinterTests.exampleStatement.approved.txt @@ -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 diff --git a/java/src/test/java/StatementPrinterTests.java b/java/src/test/java/StatementPrinterTests.java index c9d2790..71d6e14 100644 --- a/java/src/test/java/StatementPrinterTests.java +++ b/java/src/test/java/StatementPrinterTests.java @@ -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 plays = Map.of("hamlet", new Play("Hamlet", "tragedy"), + void exampleStatement() { + Map 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 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); + }); } }