Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jbrains/WorldsBestIntroToTdd-Tallinn-February2012
base: ab78dd9bbb
...
head fork: jbrains/WorldsBestIntroToTdd-Tallinn-February2012
compare: d23d55ccb0
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 23 additions and 7 deletions.
  1. +23 −7 test/source/ca/jbrains/pos/test/SellOneItemTest.java
View
30 test/source/ca/jbrains/pos/test/SellOneItemTest.java
@@ -18,8 +18,16 @@ public String getText() {
return text;
}
- public void setText(String text) {
- this.text = text;
+ public void displayProductNotFoundMessage(String barcode) {
+ this.text = "Product not found for " + barcode;
+ }
+
+ public void displayPrice(String price) {
+ this.text = price;
+ }
+
+ public void displayScannedEmptyBarcodeMessage() {
+ this.text = "Scanning error: empty barcode";
}
}
@@ -33,12 +41,20 @@ public Sale(Display display, Map<String, String> pricesByBarcode) {
}
public void onBarcode(String barcode) {
- if ("".equals(barcode))
- display.setText("Scanning error: empty barcode");
- else if (pricesByBarcode.containsKey(barcode))
- display.setText(pricesByBarcode.get(barcode));
+ if ("".equals(barcode)) {
+ display.displayScannedEmptyBarcodeMessage();
+ return;
+ }
+
+ String price = findPrice(barcode);
+ if (price == null)
+ display.displayProductNotFoundMessage(barcode);
else
- display.setText("Product not found for " + barcode);
+ display.displayPrice(price);
+ }
+
+ private String findPrice(String barcode) {
+ return pricesByBarcode.get(barcode);
}
}

No commit comments for this range

Something went wrong with that request. Please try again.