BakedItemList { public void readItemFile(String fileName) throws IOException { Scanner scan = new Scanner(new File(fileName)); listName = scan.nextLine(); String[] elements; char type; String typeS; while (scan.hasNext()) { String input = scan.nextLine(); elements = input.split(","); typeS = elements[0]; type = typeS.toUpperCase().charAt(0); String nameIn; String flavorIn; int quantityIn; double crustCostIn; int layersIn; int tiersIn; String[] ingredients = new String[50]; int j; String[] ingredientsTrim; switch (type) { case 'C': nameIn = elements[1]; flavorIn = elements[2]; quantityIn = Integer.parseInt(elements[3]); j = 0; for (int i = 0; i < elements.length - 4; i++) { ingredients[i] = elements[i + 4]; j++; } ingredientsTrim = Arrays.copyOf(ingredients, j); Cookie c = new Cookie(nameIn, flavorIn, quantityIn, ingredientsTrim); itemList[itemCount] = c; itemCount++; break; case 'P': nameIn = elements[1]; flavorIn = elements[2]; quantityIn = Integer.parseInt(elements[3]); crustCostIn = Double.parseDouble(elements[4]); j = 0; for (int i = 0; i < elements.length - 5; i++) { ingredients[i] = elements[i + 5]; j++; } ingredientsTrim = Arrays.copyOf(ingredients, j); Pie p = new Pie(nameIn, flavorIn, quantityIn, crustCostIn, ingredientsTrim); itemList[itemCount] = p; itemCount++; break; case 'K': nameIn = elements[1]; flavorIn = elements[2]; quantityIn = Integer.parseInt(elements[3]); layersIn = Integer.parseInt(elements[4]); j = 0; for (int i = 0; i < elements.length - 5; i++) { ingredients[i] = elements[i + 5]; j++; } ingredientsTrim = Arrays.copyOf(ingredients, j); Cake k = new Cake(nameIn, flavorIn, quantityIn, layersIn, ingredientsTrim); itemList[itemCount] = k; itemCount++; break; case 'W': nameIn = elements[1]; flavorIn = elements[2]; quantityIn = Integer.parseInt(elements[3]); layersIn = Integer.parseInt(elements[4]); tiersIn = Integer.parseInt(elements[5]); j = 0; for (int i = 0; i < elements.length - 6; i++) { ingredients[i] = elements[i + 6]; j++; } ingredientsTrim = Arrays.copyOf(ingredients, j); WeddingCake w = new WeddingCake(nameIn, flavorIn, quantityIn, layersIn, tiersIn, ingredientsTrim); itemList[itemCount] = w; itemCount++; break; default: excludedRecords[excludedCount] = input; excludedCount++; break; } } } BakedItemList(); String getListName(); void setListName(String listNamein); BakedItem[] getItemList(); void setItemList(BakedItem[] itemListin); int getItemCount(); void setItemCount(int itemCountin); String[] getExcludedRecords(); void setExcludedRecords(String[] excludedRecordsin); int getExcludedCount(); void setExcludedCount(int excludedCountin); static int getListCount(); static void resetListCount(); void readItemFile(String fileName); String generateReport(); String generateReportByClass(); String generateReportByPrice(); String generateReportByFlavor(); String generateExcludedRecordsReport();  }
@Test public void readItemFile() throws Exception { BakedItemList b = new BakedItemList(); b.readItemFile("baked_item_data.csv"); Assert.assertEquals("Auburn's Best Bakery", b.getListName()); Assert.assertEquals(6, b.getItemCount()); Assert.assertEquals(2, b.getExcludedCount()); }