I am trying to assertEquals an 2 arraylists. I am getting an error in the console even though the lists are identical Any ideas what's going wrong here? Any help would be appreciated..
EXTRACTING DATA FROM DB AND PUTTING IT INTO A MAP
public Map<String, List<Products>> Req1() throws SQLException {
BaseQuery bq = new BaseQuery("root", "georgespc");
List<String> columns = new ArrayList<String>();
columns.add("productCode");
columns.add("productName");
columns.add("productLine"); // 2
columns.add("productScale");
columns.add("productVendor");
columns.add("productDescription");
columns.add("quantityInStock");
columns.add("buyPrice");
columns.add("MSRP");
ArrayList<ArrayList<Object>> tableOfProducts = bq.select(columns, "products");
List<String> productLines = new ArrayList<String>();
Map<String, List<Products>> lineWithProducts = new HashMap<String, List<Products>>();
for (int i = 0; i < tableOfProducts.size(); i++) {
if (!productLines.contains(tableOfProducts.get(i).get(2))) {
productLines.add(tableOfProducts.get(i).get(2).toString());
lineWithProducts.put(tableOfProducts.get(i).get(2).toString(), new ArrayList<Products>());
}
}
for (int i = 0; i < tableOfProducts.size(); i++) {
String ID = tableOfProducts.get(i).get(0).toString();
String name = tableOfProducts.get(i).get(1).toString();
String line = tableOfProducts.get(i).get(2).toString();
String scale = tableOfProducts.get(i).get(3).toString();
String vendor = tableOfProducts.get(i).get(4).toString();
String desc = tableOfProducts.get(i).get(5).toString();
Integer quantity = (Integer) tableOfProducts.get(i).get(6);
BigDecimal price = (BigDecimal) tableOfProducts.get(i).get(7);
BigDecimal msrp = (BigDecimal) tableOfProducts.get(i).get(8);
Products p = new Products(ID, name, line, scale, vendor, desc, quantity, price, msrp);
if (!lineWithProducts.get(line).contains(p)) {
lineWithProducts.get(line).add(p);
}
}
return lineWithProducts;
}
TEST CLASS
@Test
public void test() throws SQLException {
Map<String, List<Products>> lineWithProducts = new HashMap<String, List<Products>>();
BaseQuery bq = new BaseQuery("root", "georgespc");
SetH_req1 requirements = new SetH_req1();
ResultSet rs = bq.query("select productline from productLines");
ResultSetMetaData rsmd = rs.getMetaData();
while (rs.next()) {
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
String columnValue = rs.getString(i);
lineWithProducts.put(columnValue, new ArrayList<Products>());
}
}
rs = bq.query(
"select productCode, productName, productline, productScale, productVendor, productDescription, quantityInStock, buyPrice, MSRP "
+ "from products where productline='motorcycles'");
rsmd = rs.getMetaData();
System.out.println("\n\n\n\n");
String line = null;
while (rs.next()) {
Products p = null;
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
String ID = rs.getString(1);
String name = rs.getString(2);
line = rs.getString(3);
String scale = rs.getString(4);
String vendor = rs.getString(5);
String desc = rs.getString(6);
Integer quantity = rs.getInt(7);
BigDecimal price = rs.getBigDecimal(8);
BigDecimal msrp = rs.getBigDecimal(9);
p = new Products(ID, name, line, scale, vendor, desc, quantity, price, msrp);
}
if (!lineWithProducts.get(line).contains(p)) {
lineWithProducts.get(line).add(p);
}
}
assertEquals(requirements.Req1().get(line).get(1), lineWithProducts.get(line).get(1));
ERROR
java.lang.AssertionError: expected: com.com1028.assignment.Products<
ID=S10_2016, name=1996 Moto Guzzi 1100i, productType=Motorcycles, productScale=1:10, vendor=Highway 66 Mini Classics, description=Official Moto Guzzi logos and insignias, saddle bags located on side of motorcycle, detailed engine, working steering, working suspension, two leather seats, luggage rack, dual exhaust pipes, small saddle bag located on handle bars, two-tone paint with chrome accents, superior die-cast detail , rotating wheels , working kick stand, diecast metal with plastic parts and baked enamel finish., stock=6625, price=68.99, MRSP=118.94
but was: com.com1028.assignment.Products<
ID=S10_2016, name=1996 Moto Guzzi 1100i, productType=Motorcycles, productScale=1:10, vendor=Highway 66 Mini Classics, description=Official Moto Guzzi logos and insignias, saddle bags located on side of motorcycle, detailed engine, working steering, working suspension, two leather seats, luggage rack, dual exhaust pipes, small saddle bag located on handle bars, two-tone paint with chrome accents, superior die-cast detail , rotating wheels , working kick stand, diecast metal with plastic parts and baked enamel finish., stock=6625, price=68.99, MRSP=118.94
>
Aucun commentaire:
Enregistrer un commentaire