Permalink
Browse files

Moved lookup table into the tests to make it clearer why a given barc…

…ode maps to a given price.
  • Loading branch information...
1 parent c6405ed commit 541ff7e322687f7431366a2f669ddc046426a66a @jbrains committed May 23, 2012
Showing with 27 additions and 12 deletions.
  1. +27 −12 test/source/ca/jbrains/pos/test/SellOneItemTest.java
View
39 test/source/ca/jbrains/pos/test/SellOneItemTest.java
@@ -22,19 +22,14 @@ public void setText(String text) {
public static class Sale {
private Display display;
+ private Map<String, String> pricesByBarcode;
- public Sale(Display display) {
+ public Sale(Display display, Map<String,String> pricesByBarcode) {
this.display = display;
+ this.pricesByBarcode = pricesByBarcode;
}
public void onBarcode(String barcode) {
- Map<String, String> pricesByBarcode = new HashMap<String, String>() {
- {
- put("12345", "SEK 795");
- put("23456", "SEK 1250");
- }
- };
-
if ("".equals(barcode))
display.setText("Scanning error: empty barcode");
else if ("12345".equals(barcode) || "23456".equals(barcode))
@@ -47,7 +42,12 @@ else if ("12345".equals(barcode) || "23456".equals(barcode))
@Test
public void productFound() {
Display display = new Display();
- Sale sale = new Sale(display);
+ Sale sale = new Sale(display, new HashMap<String, String>() {
+ {
+ put("12345", "SEK 795");
+ put("23456", "SEK 1250");
+ }
+ });
sale.onBarcode("12345");
@@ -57,7 +57,12 @@ public void productFound() {
@Test
public void anotherProductFound() {
Display display = new Display();
- Sale sale = new Sale(display);
+ Sale sale = new Sale(display, new HashMap<String, String>() {
+ {
+ put("12345", "SEK 795");
+ put("23456", "SEK 1250");
+ }
+ });
sale.onBarcode("23456");
@@ -67,7 +72,12 @@ public void anotherProductFound() {
@Test
public void productNotFound() throws Exception {
Display display = new Display();
- Sale sale = new Sale(display);
+ Sale sale = new Sale(display, new HashMap<String, String>() {
+ {
+ put("12345", "SEK 795");
+ put("23456", "SEK 1250");
+ }
+ });
sale.onBarcode("99999");
@@ -77,7 +87,12 @@ public void productNotFound() throws Exception {
@Test
public void emptyBarcode() throws Exception {
Display display = new Display();
- Sale sale = new Sale(display);
+ Sale sale = new Sale(display, new HashMap<String, String>() {
+ {
+ put("12345", "SEK 795");
+ put("23456", "SEK 1250");
+ }
+ });
sale.onBarcode("");

0 comments on commit 541ff7e

Please sign in to comment.