|
@@ -5,6 +5,8 @@ import org.junit.Before;
|
5
|
5
|
import org.junit.Test;
|
6
|
6
|
|
7
|
7
|
import java.util.ArrayList;
|
|
8
|
+import java.util.HashMap;
|
|
9
|
+import java.util.Map;
|
8
|
10
|
|
9
|
11
|
import static org.junit.Assert.*;
|
10
|
12
|
|
|
@@ -59,4 +61,76 @@ public class ItemParserTest {
|
59
|
61
|
Integer actual = itemParser.findKeyValuePairsInRawItemData(rawSingleItemIrregularSeperatorSample).size();
|
60
|
62
|
assertEquals(expected, actual);
|
61
|
63
|
}
|
|
64
|
+ @Test
|
|
65
|
+ public void findNameTest(){
|
|
66
|
+ String expected = "milk";
|
|
67
|
+ String actual = itemParser.findName(rawSingleItem);
|
|
68
|
+ Assert.assertEquals(expected,actual);
|
|
69
|
+ }
|
|
70
|
+ @Test
|
|
71
|
+ public void findPriceTest(){
|
|
72
|
+ String expected = "3.23";
|
|
73
|
+ String actual = itemParser.findPrice(rawSingleItem);
|
|
74
|
+ Assert.assertEquals(expected,actual);
|
|
75
|
+ }
|
|
76
|
+ @Test
|
|
77
|
+ public void findTypeTest(){
|
|
78
|
+ String expected = "food";
|
|
79
|
+ String actual = itemParser.findType(rawBrokenSingleItem);
|
|
80
|
+ Assert.assertEquals(expected,actual);
|
|
81
|
+ }
|
|
82
|
+ @Test
|
|
83
|
+ public void findExpirationDate(){
|
|
84
|
+ String expected = "1/11/2016";
|
|
85
|
+ String actual= itemParser.findExpirationDate(rawSingleItemIrregularSeperatorSample);
|
|
86
|
+ Assert.assertEquals(expected,actual);
|
|
87
|
+ }
|
|
88
|
+ @Test
|
|
89
|
+ public void buildMapTest1 ()throws Exception{
|
|
90
|
+ Map<String,ArrayList<Item>>testMap= new HashMap<String, ArrayList<Item>>();
|
|
91
|
+ testMap = itemParser.buildMap();
|
|
92
|
+ boolean actual = testMap.containsKey("milk");
|
|
93
|
+ Assert.assertTrue(actual);
|
|
94
|
+ }
|
|
95
|
+ @Test
|
|
96
|
+ public void buildMapTest2() throws Exception{
|
|
97
|
+ Map<String,ArrayList<Item>>testMap= new HashMap<String, ArrayList<Item>>();
|
|
98
|
+ testMap = itemParser.buildMap();
|
|
99
|
+ int expected = 4;
|
|
100
|
+ int actual = testMap.get("apples").size();
|
|
101
|
+ Assert.assertEquals(expected,actual);
|
|
102
|
+
|
|
103
|
+ }
|
|
104
|
+ @Test
|
|
105
|
+ public void getOccurencesOfItemsTest() throws ItemParseException {
|
|
106
|
+ ArrayList<Item>test = new ArrayList<Item>();
|
|
107
|
+
|
|
108
|
+ Item item1 = itemParser.parseStringIntoItem(rawSingleItem);
|
|
109
|
+ String rawItem2 =("naME:BreaD;price:1.23;type:Food;expiration:1/02/2016##");
|
|
110
|
+ Item item2 = itemParser.parseStringIntoItem(rawItem2);
|
|
111
|
+ test.add(item1);
|
|
112
|
+ test.add(item2);
|
|
113
|
+ int expected = 2;
|
|
114
|
+ int actual = itemParser.getOccurencesOfItems(test);
|
|
115
|
+ Assert.assertEquals(expected,actual);
|
|
116
|
+
|
|
117
|
+ }
|
|
118
|
+ @Test
|
|
119
|
+ public void getOccurencesOfPricesTest() throws ItemParseException {
|
|
120
|
+
|
|
121
|
+ ArrayList<Item>test = new ArrayList<Item>();
|
|
122
|
+
|
|
123
|
+ Item item1 = itemParser.parseStringIntoItem(rawSingleItem);
|
|
124
|
+ String rawItem2 =("naME:BreaD;price:1.23;type:Food;expiration:1/02/2016##");
|
|
125
|
+ String rawItem3 = "naMe:Bread;price:1.23;type:Food^expiration:1/11/2016##";
|
|
126
|
+ Item item2 = itemParser.parseStringIntoItem(rawItem2);
|
|
127
|
+ Item item3 = itemParser.parseStringIntoItem(rawItem3);
|
|
128
|
+ test.add(item1);
|
|
129
|
+ test.add(item2);
|
|
130
|
+ test.add(item3);
|
|
131
|
+ int expected =2;
|
|
132
|
+ int actual = itemParser.getOccurencesOfPrices(test,1.23);
|
|
133
|
+ Assert.assertEquals(expected,actual);
|
|
134
|
+ }
|
|
135
|
+
|
62
|
136
|
}
|