Browse Source

Merge 5231662b77850a6940ea554c2d50f0ad8e39b7ab into 23c2c01bf07b924ac9b860fa2771bf6ceb246ad5

Luis J. Romero 6 years ago
parent
commit
2ce2a27254
No account linked to committer's email

+ 12
- 0
pom.xml View File

@@ -7,6 +7,18 @@
7 7
     <groupId>io.zipcoder</groupId>
8 8
     <artifactId>PainfullAfternoon</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <build>
11
+        <plugins>
12
+            <plugin>
13
+                <groupId>org.apache.maven.plugins</groupId>
14
+                <artifactId>maven-compiler-plugin</artifactId>
15
+                <configuration>
16
+                    <source>1.7</source>
17
+                    <target>1.7</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
10 22
 
11 23
     <dependencies>
12 24
         <dependency>

+ 6
- 0
src/main/java/io/zipcoder/Item.java View File

@@ -45,4 +45,10 @@ public class Item {
45 45
     public String toString(){
46 46
         return "name:" + name + " price:" + price + " type:" + type + " expiration:" + expiration;
47 47
     }
48
+
49
+    public static void main(String[] args) {
50
+        Item item = new Item("milk", 3.23, "food", "1/25/2016");
51
+        String itemAsString = item.toString();
52
+        System.out.println(itemAsString);
53
+    }
48 54
 }

+ 54
- 0
src/main/java/io/zipcoder/ItemParseException.java View File

@@ -1,4 +1,58 @@
1 1
 package io.zipcoder;
2 2
 
3
+import java.util.ArrayList;
4
+import java.util.List;
5
+import java.util.logging.Logger;
6
+
3 7
 public class ItemParseException extends Exception {
8
+
9
+    private int errorCount;
10
+    private List<String> errors;
11
+    private static final Logger logger = Logger.getGlobal();
12
+
13
+    public ItemParseException() {
14
+        this.errorCount = 0;
15
+        errors = new ArrayList<>();
16
+    }
17
+
18
+    public ItemParseException(String emptyFieldName) {
19
+        logger.info("This field name is empty: " + "\"" + emptyFieldName + "\"");
20
+    }
21
+
22
+    public void logErrorCount(String emptyFieldName, String rawItem) {
23
+        errors.add("Field " + "\"" + emptyFieldName + "\"" + " is empty in " + rawItem);
24
+        errorCount++;
25
+    }
26
+
27
+    public int getErrorCount() {
28
+        return errorCount;
29
+    }
30
+
31
+    public List<String> getErrors() {
32
+        return errors;
33
+    }
34
+
35
+    public String errorCountAsString() {
36
+        String s = String.format("%-13s", "Errors");
37
+        StringBuilder sb = new StringBuilder();
38
+        sb.append(s);
39
+        sb.append("\t\t" + "seen: " + errorCount + " times");
40
+        return sb.toString();
41
+    }
42
+
43
+    public String errorsAsString() {
44
+        StringBuilder sb = new StringBuilder();
45
+        sb.append("Error count: " + errorCount + "\n");
46
+        sb.append("Errors:\n");
47
+
48
+        int errorNumber = 1;
49
+        for (String error : errors) {
50
+            sb.append("Error " + errorNumber + ": " + error + "\n");
51
+            errorNumber++;
52
+        }
53
+        sb.deleteCharAt(sb.length() - 1);
54
+
55
+        return sb.toString();
56
+    }
57
+
4 58
 }

+ 227
- 11
src/main/java/io/zipcoder/ItemParser.java View File

@@ -1,31 +1,247 @@
1 1
 package io.zipcoder;
2 2
 
3
-import java.util.ArrayList;
4
-import java.util.Arrays;
3
+import apple.laf.JRSUIUtils;
4
+
5
+import java.rmi.activation.ActivationGroup_Stub;
6
+import java.util.*;
7
+import java.util.regex.Pattern;
8
+import java.util.regex.Matcher;
9
+import java.util.Map.Entry;
5 10
 
6 11
 public class ItemParser {
7 12
 
13
+    private ItemParseException ipe;
14
+    private List<String> itemStrings;
15
+    private List<Item> items;
16
+    private TreeMap<String, ArrayList<Item>> itemOrganizer;
17
+
18
+    public ItemParser() {
19
+        this.ipe = new ItemParseException();
20
+        this.itemStrings = new ArrayList<>();
21
+        this.items = new ArrayList<>();
22
+        this.itemOrganizer = new TreeMap<>();
23
+    }
24
+
25
+    public ItemParseException getIpe() {
26
+        return ipe;
27
+    }
8 28
 
9
-    public ArrayList<String> parseRawDataIntoStringArray(String rawData){
29
+    public ArrayList<String> parseRawDataIntoItemStringArray(String rawData){
10 30
         String stringPattern = "##";
11
-        ArrayList<String> response = splitStringWithRegexPattern(stringPattern , rawData);
31
+        ArrayList<String> response = splitStringWithRegexPattern(rawData, stringPattern);
32
+        itemStrings = response;
12 33
         return response;
13 34
     }
14 35
 
15
-    public Item parseStringIntoItem(String rawItem) throws ItemParseException{
16
-        return null;
36
+    public List<String> getItemStrings() {
37
+        return itemStrings;
38
+    }
39
+
40
+    public void createItems() throws ItemParseException {
41
+        for (String itemString : itemStrings) {
42
+            Item item = parseStringIntoItem(itemString);
43
+            items.add(item);
44
+        }
45
+    }
46
+
47
+    public List<Item> getItems() {
48
+        return items;
49
+    }
50
+
51
+    public String itemsAsString() {
52
+        StringBuilder sb = new StringBuilder();
53
+        int count = 1;
54
+        for (Item item : items) {
55
+            sb.append(count + " " + item.toString() + "\n");
56
+            count++;
57
+        }
58
+        sb.deleteCharAt(sb.length() - 1);
59
+        return sb.toString();
60
+    }
61
+
62
+    public ArrayList<Item> getItemsOfSameName(String name) {
63
+        ArrayList<Item> itemsOfSameName = new ArrayList<>();
64
+        for (Item item : items) {
65
+            if (item.getName().equals(name)) {
66
+                itemsOfSameName.add(item);
67
+            }
68
+        }
69
+        return itemsOfSameName;
70
+    }
71
+
72
+    public void addNameAndItemsOfSameNameToItemOrganizer() {
73
+        for (Item item : items) {
74
+            String itemName = item.getName();
75
+            if (itemOrganizer.get(itemName) == null) {
76
+                itemOrganizer.put(itemName, getItemsOfSameName(itemName));
77
+            }
78
+        }
79
+    }
80
+
81
+    public TreeMap<String, ArrayList<Item>> getItemOrganizer() {
82
+        return itemOrganizer;
83
+    }
84
+
85
+    public String itemOrganizerAsString() {
86
+        StringBuilder sb = new StringBuilder();
87
+        for (Entry entry : itemOrganizer.entrySet()) {
88
+            sb.append("name: " + entry.getKey() + " " + "nameCount: " + itemOrganizer.get(entry.getKey()).size() + "\n"
89
+            + entry.getValue() + "\n");
90
+        }
91
+        sb.deleteCharAt(sb.length() - 1);
92
+        return sb.toString();
93
+    }
94
+
95
+    public String itemNameAndCountAsString(String name) {
96
+        String timeOrTimes = "times";
97
+        StringBuilder sb = new StringBuilder();
98
+        for (String keyName : itemOrganizer.keySet()) {
99
+            if (itemOrganizer.get(keyName).size() == 1) {
100
+                timeOrTimes = "time";
101
+            }
102
+            if (keyName.equals(name)) {
103
+                int numberOfEmptyPriceFields = countNumberOfEmptyPriceFields(name);
104
+                int actualCount = itemOrganizer.get(name).size() - numberOfEmptyPriceFields;
105
+                String s = String.format("%-5s%8s", "name:", capitalizeFirstLetterOnly(name));
106
+                sb.append(s);
107
+                sb.append("\t\tseen: " + actualCount + " " + timeOrTimes);
108
+            }
109
+        }
110
+        return sb.toString();
111
+    }
112
+
113
+    public int countNumberOfEmptyPriceFields(String name) {
114
+        int count = 0;
115
+        for (String keyName : itemOrganizer.keySet()) {
116
+            if (keyName.equals(name)) {
117
+                for (Item item : itemOrganizer.get(keyName)) {
118
+                    if (item.getPrice() == 0) {
119
+                        count++;
120
+                    }
121
+                }
122
+            }
123
+        }
124
+        return count;
125
+    }
126
+
127
+    public String capitalizeFirstLetterOnly(String word) {
128
+        StringBuilder sb = new StringBuilder();
129
+        String firstLetterOfWord = word.substring(0,1);
130
+        sb.append(firstLetterOfWord.toUpperCase() + word.substring(1, word.length()));
131
+        return sb.toString();
132
+    }
133
+
134
+    public Map<Double, Integer> getPricesAndTheirCount(String name) {
135
+        Map<Double, Integer> pricesAndTheirCount = new TreeMap<>(Collections.reverseOrder());
136
+        for (String nameKey : itemOrganizer.keySet()) {
137
+            if (nameKey.equals(name)) {
138
+                for (int i = 0; i < itemOrganizer.get(nameKey).size(); i++) {
139
+                    double price = itemOrganizer.get(nameKey).get(i).getPrice();
140
+                    if (pricesAndTheirCount.get(price) == null) {
141
+                        pricesAndTheirCount.put(price, 1);
142
+                    } else {
143
+                        pricesAndTheirCount.put(price, pricesAndTheirCount.get(price) + 1);
144
+                    }
145
+                }
146
+            }
147
+        }
148
+        return pricesAndTheirCount;
149
+    }
150
+
151
+    public String pricesAndTheirCountAsString(Map<Double, Integer> pricesAndTheirCount) {
152
+
153
+        int count = 0;
154
+        StringBuilder sb = new StringBuilder();
155
+        sb.append("=============\t\t=============\n");
156
+        for (Double price : pricesAndTheirCount.keySet()) {
157
+            String timeOrTimes = "times";
158
+            if (pricesAndTheirCount.get(price) == 1) {
159
+                timeOrTimes = "time";
160
+            }
161
+            if (price != 0) {
162
+                sb.append("Price:   " + price + "\t\tseen: " + pricesAndTheirCount.get(price) + " " + timeOrTimes + "\n");
163
+                sb.append("-------------\t\t-------------\n");
164
+            }
165
+            count++;
166
+        }
167
+        if (count > 1) {
168
+            sb.delete(sb.length() - 29, sb.length());
169
+        }
170
+//        sb.deleteCharAt(sb.length() - 1);
171
+        return sb.toString();
172
+    }
173
+
174
+    public String getReportAsString() {
175
+        StringBuilder sb = new StringBuilder();
176
+        for (String name : itemOrganizer.keySet()) {
177
+            if (! name.equals("EMPTY")) {
178
+                sb.append(itemNameAndCountAsString(name) + "\n");
179
+                sb.append(pricesAndTheirCountAsString(getPricesAndTheirCount(name)) + "\n");
180
+            }
181
+        }
182
+        sb.append(getIpe().errorCountAsString());
183
+        return sb.toString();
184
+    }
185
+
186
+    public Item parseStringIntoItem(String rawItem) throws ItemParseException {
187
+
188
+        String emptyFieldName = "";
189
+        List<String> keyValuePairsArrayList = findKeyValuePairsInRawItemData(rawItem);
190
+
191
+        String upToAndIncludingColonString = "\\w+:";
192
+        Pattern upToAndIncludingColonPattern = Pattern.compile(upToAndIncludingColonString);
193
+
194
+        Matcher nameMatcher = upToAndIncludingColonPattern.matcher(keyValuePairsArrayList.get(0));
195
+        String name = nameMatcher.replaceAll("").toLowerCase();
196
+        String cookiesString = "(c|C)\\w+(s|S)";
197
+        Pattern cookiesPattern = Pattern.compile(cookiesString);
198
+        Matcher cookiesMatcher = cookiesPattern.matcher(name);
199
+        if (cookiesMatcher.find()) {
200
+            name = cookiesMatcher.replaceAll("cookies");
201
+        }
202
+        if (name.equals("")) {
203
+            name = "EMPTY";
204
+            emptyFieldName = "name";
205
+            ipe.logErrorCount(emptyFieldName, rawItem);
206
+        }
207
+
208
+        Matcher priceMatcher = upToAndIncludingColonPattern.matcher(keyValuePairsArrayList.get(1));
209
+        String priceString = priceMatcher.replaceAll("");
210
+        if (priceString.equals("")) {
211
+            priceString = "0.00";
212
+            emptyFieldName = "price";
213
+            ipe.logErrorCount(emptyFieldName, rawItem);
214
+        }
215
+        double price = Double.parseDouble(priceString);
216
+
217
+        Matcher typeMatcher = upToAndIncludingColonPattern.matcher(keyValuePairsArrayList.get(2));
218
+        String type = typeMatcher.replaceAll("").toLowerCase();
219
+        if (type.equals("")) {
220
+            type = "EMPTY";
221
+            emptyFieldName = "type";
222
+            ipe.logErrorCount(emptyFieldName, rawItem);
223
+        }
224
+
225
+        Matcher expirationMatcher = upToAndIncludingColonPattern.matcher(keyValuePairsArrayList.get(3));
226
+        String expiration = expirationMatcher.replaceAll("").toLowerCase();
227
+        if (expiration.equals("")) {
228
+            expiration = "EMPTY";
229
+            emptyFieldName = "expiration";
230
+            ipe.logErrorCount(emptyFieldName, rawItem);
231
+        }
232
+
233
+        Item item = new Item(name, price, type, expiration);
234
+        return item;
17 235
     }
18 236
 
19 237
     public ArrayList<String> findKeyValuePairsInRawItemData(String rawItem){
20
-        String stringPattern = "[;|^]";
21
-        ArrayList<String> response = splitStringWithRegexPattern(stringPattern , rawItem);
238
+        String stringPattern = "[^\\w:.\\/]";
239
+        ArrayList<String> response = splitStringWithRegexPattern(rawItem, stringPattern);
22 240
         return response;
23 241
     }
24 242
 
25
-    private ArrayList<String> splitStringWithRegexPattern(String stringPattern, String inputString){
243
+    private ArrayList<String> splitStringWithRegexPattern(String inputString, String stringPattern){
26 244
         return new ArrayList<String>(Arrays.asList(inputString.split(stringPattern)));
27 245
     }
28 246
 
29
-
30
-
31 247
 }

+ 20
- 1
src/main/java/io/zipcoder/Main.java View File

@@ -13,7 +13,26 @@ public class Main {
13 13
 
14 14
     public static void main(String[] args) throws Exception{
15 15
         String output = (new Main()).readRawDataToString();
16
-        System.out.println(output);
16
+//        System.out.println(output);
17 17
         // TODO: parse the data in output into items, and display to console.
18
+
19
+        ItemParser itemParser = new ItemParser();
20
+        itemParser.parseRawDataIntoItemStringArray(output);
21
+        itemParser.createItems();
22
+        itemParser.addNameAndItemsOfSameNameToItemOrganizer();
23
+
24
+        // Prints report in alphabetical order by name (the prices/counts match output.txt)
25
+        System.out.println(itemParser.getReportAsString());
26
+
27
+        // These commands (commented out) will print the same information in the order of output.txt
28
+//        System.out.println(itemParser.itemNameAndCountAsString("milk"));
29
+//        System.out.println(itemParser.pricesAndTheirCountAsString(itemParser.getPricesAndTheirCount("milk")));
30
+//        System.out.println(itemParser.itemNameAndCountAsString("bread"));
31
+//        System.out.println(itemParser.pricesAndTheirCountAsString(itemParser.getPricesAndTheirCount("bread")));
32
+//        System.out.println(itemParser.itemNameAndCountAsString("cookies"));
33
+//        System.out.println(itemParser.pricesAndTheirCountAsString(itemParser.getPricesAndTheirCount("cookies")));
34
+//        System.out.println(itemParser.itemNameAndCountAsString("apples"));
35
+//        System.out.println(itemParser.pricesAndTheirCountAsString(itemParser.getPricesAndTheirCount("apples")));
36
+//        System.out.println(itemParser.getIpe().errorCountAsString());
18 37
     }
19 38
 }

+ 1
- 0
src/main/resources/RawDataCopy.txt View File

@@ -0,0 +1 @@
1
+naMe:Milk;price:3.23;type:Food;expiration:1/25/2016##naME:BreaD;price:1.23;type:Food;expiration:1/02/2016##NAMe:BrEAD;price:1.23;type:Food;expiration:2/25/2016##naMe:MiLK;price:3.23;type:Food^expiration:1/11/2016##naMe:Cookies;price:2.25;type:Food%expiration:1/25/2016##naMe:CoOkieS;price:2.25;type:Food*expiration:1/25/2016##naMe:COokIes;price:2.25;type:Food;expiration:3/22/2016##naMe:COOkieS;price:2.25;type:Food;expiration:1/25/2016##NAME:MilK;price:3.23;type:Food;expiration:1/17/2016##naMe:MilK;price:1.23;type:Food!expiration:4/25/2016##naMe:apPles;price:0.25;type:Food;expiration:1/23/2016##naMe:apPles;price:0.23;type:Food;expiration:5/02/2016##NAMe:BrEAD;price:1.23;type:Food;expiration:1/25/2016##naMe:;price:3.23;type:Food;expiration:1/04/2016##naMe:Milk;price:3.23;type:Food;expiration:1/25/2016##naME:BreaD;price:1.23;type:Food@expiration:1/02/2016##NAMe:BrEAD;price:1.23;type:Food@expiration:2/25/2016##naMe:MiLK;priCe:;type:Food;expiration:1/11/2016##naMe:Cookies;price:2.25;type:Food;expiration:1/25/2016##naMe:Co0kieS;pRice:2.25;type:Food;expiration:1/25/2016##naMe:COokIes;price:2.25;type:Food;expiration:3/22/2016##naMe:COOkieS;Price:2.25;type:Food;expiration:1/25/2016##NAME:MilK;price:3.23;type:Food;expiration:1/17/2016##naMe:MilK;priCe:;type:Food;expiration:4/25/2016##naMe:apPles;prIce:0.25;type:Food;expiration:1/23/2016##naMe:apPles;pRice:0.23;type:Food;expiration:5/02/2016##NAMe:BrEAD;price:1.23;type:Food;expiration:1/25/2016##naMe:;price:3.23;type:Food^expiration:1/04/2016##

+ 27
- 0
src/test/java/io/zipcoder/ItemParseExceptionTest.java View File

@@ -0,0 +1,27 @@
1
+package io.zipcoder;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+public class ItemParseExceptionTest {
8
+
9
+    private ItemParser itemParser;
10
+    private String rawBrokenSingleItem = "naMe:;price:3.23;type:Food;expiration:1/25/2016##";
11
+
12
+    @Before
13
+    public void setUp() {
14
+        itemParser = new ItemParser();
15
+    }
16
+
17
+    @Test
18
+    public void logErrorCountTest() throws ItemParseException {
19
+        // Given
20
+        int expectedErrorCount = 1;
21
+        Item item = itemParser.parseStringIntoItem(rawBrokenSingleItem);
22
+        // When
23
+        int actualErrorCount = itemParser.getIpe().getErrorCount();
24
+        // Then
25
+        Assert.assertEquals(expectedErrorCount, actualErrorCount);
26
+    }
27
+}

+ 156
- 2
src/test/java/io/zipcoder/ItemParserTest.java View File

@@ -5,6 +5,7 @@ import org.junit.Before;
5 5
 import org.junit.Test;
6 6
 
7 7
 import java.util.ArrayList;
8
+import java.util.List;
8 9
 
9 10
 import static org.junit.Assert.*;
10 11
 
@@ -14,11 +15,23 @@ public class ItemParserTest {
14 15
 
15 16
     private String rawSingleItemIrregularSeperatorSample = "naMe:MiLK;price:3.23;type:Food^expiration:1/11/2016##";
16 17
 
17
-    private String rawBrokenSingleItem =    "naMe:Milk;price:3.23;type:Food;expiration:1/25/2016##";
18
+    // I "broke" the original String value (I removed "Milk"), because the original String value was good
19
+    private String rawBrokenSingleItem =    "naMe:;price:3.23;type:Food;expiration:1/25/2016##";
20
+    private String rawBrokenSingleItem2 =   "naMe:Milk;price:;type:Food;expiration:1/25/2016##";
18 21
 
19 22
     private String rawMultipleItems = "naMe:Milk;price:3.23;type:Food;expiration:1/25/2016##"
20 23
                                       +"naME:BreaD;price:1.23;type:Food;expiration:1/02/2016##"
21 24
                                       +"NAMe:BrEAD;price:1.23;type:Food;expiration:2/25/2016##";
25
+
26
+    private String rawMultipleItems2 = "naMe:Milk;price:3.23;type:Food;expiration:1/25/2016##"
27
+                                      +"naME:BreaD;price:3.23;type:Food;expiration:1/02/2016##"
28
+                                      +"NAMe:BrEAD;price:1.23;type:Food;expiration:2/25/2016##";
29
+
30
+    private String rawMultipleItems3 = "naMe:Milk;price:3.23;type:Food;expiration:1/25/2016##"
31
+                                      +"naME:BreaD;price:3.23;type:Food;expiration:1/02/2016##"
32
+                                      +"naME:BreaD;price:3.23;type:Food;expiration:1/02/2016##"
33
+                                      +"NAMe:BrEAD;price:1.23;type:Food;expiration:2/25/2016##";
34
+
22 35
     private ItemParser itemParser;
23 36
 
24 37
     @Before
@@ -27,9 +40,150 @@ public class ItemParserTest {
27 40
     }
28 41
 
29 42
     @Test
43
+    public void getItemStringsTest() {
44
+        // Given
45
+        int expectedItemStringsSize = 3;
46
+        itemParser.parseRawDataIntoItemStringArray(rawMultipleItems);
47
+        // When
48
+        int actualItemStringsSize = itemParser.getItemStrings().size();
49
+        // Then
50
+        Assert.assertEquals(expectedItemStringsSize, actualItemStringsSize);
51
+    }
52
+
53
+    @Test
54
+    public void createItemsTest() throws ItemParseException {
55
+        // Given
56
+        int expectedItemsSize = 3;
57
+        itemParser.parseRawDataIntoItemStringArray(rawMultipleItems);
58
+        itemParser.createItems();
59
+        // When
60
+        int actualItemsSize = itemParser.getItems().size();
61
+        // Then
62
+        Assert.assertEquals(expectedItemsSize, actualItemsSize);
63
+    }
64
+
65
+    @Test
66
+    public void itemsAsStringTest() throws ItemParseException {
67
+        // Given
68
+        String expectedDisplay = "1 name:milk price:3.23 type:food expiration:1/25/2016" + "\n"
69
+                               + "2 name:bread price:1.23 type:food expiration:1/02/2016" + "\n"
70
+                               + "3 name:bread price:1.23 type:food expiration:2/25/2016";
71
+        itemParser.parseRawDataIntoItemStringArray(rawMultipleItems);
72
+        itemParser.createItems();
73
+        // When
74
+        String actualDisplay = itemParser.itemsAsString();
75
+        // Then
76
+        Assert.assertEquals(expectedDisplay, actualDisplay);
77
+    }
78
+
79
+    @Test
80
+    public void getItemsOfSameNameTest() throws ItemParseException {
81
+        // Given
82
+        String expectedName = "milk";
83
+        itemParser.parseRawDataIntoItemStringArray(rawMultipleItems);
84
+        itemParser.createItems();
85
+        // When
86
+        ArrayList<Item> itemOfSameName = itemParser.getItemsOfSameName(expectedName);
87
+        String actualName = itemOfSameName.get(0).getName();
88
+        // Then
89
+        Assert.assertEquals(expectedName, actualName);
90
+    }
91
+
92
+    @Test
93
+    public void addNameAndItemsOfSameNameToItemOrganizerTest() throws ItemParseException {
94
+        // Given
95
+        String expectedName = "bread";
96
+        int expectedNameCount = 2;
97
+        itemParser.parseRawDataIntoItemStringArray(rawMultipleItems);
98
+        itemParser.createItems();
99
+        // When
100
+        itemParser.addNameAndItemsOfSameNameToItemOrganizer();
101
+        int actualNameCount = itemParser.getItemOrganizer().get(expectedName).size();
102
+        // Then
103
+        Assert.assertEquals(expectedNameCount, actualNameCount);
104
+    }
105
+
106
+    @Test
107
+    public void itemNameAndCountAsString() throws ItemParseException {
108
+        // Given
109
+        String nameForBread = "bread";
110
+        String expectedNameAndCount = "name:   Bread\t\tseen: 3 times";
111
+        itemParser.parseRawDataIntoItemStringArray(rawMultipleItems3);
112
+        itemParser.createItems();
113
+        // When
114
+        itemParser.addNameAndItemsOfSameNameToItemOrganizer();
115
+        String actualNameAndCount = itemParser.itemNameAndCountAsString(nameForBread);
116
+        // Then
117
+        Assert.assertEquals(expectedNameAndCount, actualNameAndCount);
118
+    }
119
+
120
+    @Test
121
+    public void countNumberOfEmptyPriceFieldsTest() throws ItemParseException {
122
+        // Given
123
+        String expectedName = "milk";
124
+        int expectedEmptyPrice = 1;
125
+        itemParser.parseRawDataIntoItemStringArray(rawBrokenSingleItem2);
126
+        itemParser.createItems();
127
+        // When
128
+        itemParser.addNameAndItemsOfSameNameToItemOrganizer();
129
+        int actualEmptyPrice = itemParser.countNumberOfEmptyPriceFields(expectedName);
130
+        // Then
131
+        Assert.assertEquals(expectedEmptyPrice, actualEmptyPrice);
132
+
133
+    }
134
+
135
+    @Test
136
+    public void capitalizeFirstLetterOnlyTest() {
137
+        // Given
138
+        String word = "word";
139
+        String expectedWord = "Word";
140
+        // When
141
+        String actualWord = itemParser.capitalizeFirstLetterOnly(word);
142
+        // Then
143
+        Assert.assertEquals(expectedWord, actualWord);
144
+    }
145
+
146
+    @Test
147
+    public void getPricesAndTheirCountTest() throws ItemParseException {
148
+        // Given
149
+        String nameForBread = "bread";
150
+        double expected323Price = 3.23;
151
+        double expected123Price = 1.23;
152
+        int expected323Count = 1;
153
+        int expected123Count = 1;
154
+        itemParser.parseRawDataIntoItemStringArray(rawMultipleItems2);
155
+        itemParser.createItems();
156
+        itemParser.addNameAndItemsOfSameNameToItemOrganizer();
157
+        // When
158
+        int actual323Count = itemParser.getPricesAndTheirCount(nameForBread).get(expected323Price);
159
+        int actual123Count = itemParser.getPricesAndTheirCount(nameForBread).get(expected123Price);
160
+        // Then
161
+        Assert.assertEquals(expected323Count, actual323Count);
162
+        Assert.assertEquals(expected123Count, actual123Count);
163
+    }
164
+
165
+    @Test
166
+    public void pricesAndTheirCountAsStringTest() throws ItemParseException {
167
+        // Given
168
+        String nameForBread = "bread";
169
+        itemParser.parseRawDataIntoItemStringArray(rawMultipleItems3);
170
+        itemParser.createItems();
171
+        itemParser.addNameAndItemsOfSameNameToItemOrganizer();
172
+        String expectedPricesAndTheirCount = "=============\t\t=============\n" +
173
+                                             "Price:   " + "3.23" + "\t\tseen: " + "2" + " " + "times" + "\n" +
174
+                                             "-------------\t\t-------------\n" +
175
+                                             "Price:   " + "1.23" + "\t\tseen: " + "1" + " " + "time" + "\n" +
176
+                                             "-------------\t\t-------------";
177
+        // When
178
+        String actualPATC = itemParser.pricesAndTheirCountAsString(itemParser.getPricesAndTheirCount(nameForBread));
179
+        // Then
180
+        Assert.assertEquals(expectedPricesAndTheirCount, actualPATC);
181
+    }
182
+
183
+    @Test
30 184
     public void parseRawDataIntoStringArrayTest(){
31 185
         Integer expectedArraySize = 3;
32
-        ArrayList<String> items = itemParser.parseRawDataIntoStringArray(rawMultipleItems);
186
+        ArrayList<String> items = itemParser.parseRawDataIntoItemStringArray(rawMultipleItems);
33 187
         Integer actualArraySize = items.size();
34 188
         assertEquals(expectedArraySize, actualArraySize);
35 189
     }