@Test public void startsANewPickupOrder() { Customer customer = new Customer("Finn", "*****@*****.**", "+1(999)999-2187"); Order expectedResult = new Order(OrderType.FOR_PICKUP, customer); when(mockCustomerRepository.findOne(1L)).thenReturn(customer); Order result = orderService.startNewPickupOrder(1L); assertThat(result, is(equalTo(expectedResult))); verify(mockCustomerRepository).findOne(1L); verify(mockOrderRepository).save(expectedResult); }
@Test public void startsANewDeliveryOrder() { Customer customer = new Customer("Finn", "*****@*****.**", "+1(999)999-2187"); customer.setAddress(new Address("2187 Jakku Ave.", "Jakku", "CA", "92187")); Order expectedResult = new Order(OrderType.FOR_DELIVERY, customer); when(mockCustomerRepository.findOne(1L)).thenReturn(customer); Order result = orderService.startNewDeliveryOrder(1L); assertThat(result, is(equalTo(expectedResult))); verify(mockCustomerRepository).findOne(1L); verify(mockOrderRepository).save(expectedResult); }
@RequestMapping("/") public String loadCustomerForHome( Principal principal, ModelMap modelMap, HttpSession httpSession) { Long currentOrderId = (Long) httpSession.getAttribute("currentOrder"); if (currentOrderId != null) { return "redirect:/continueOrder"; } String email = principal.getName(); Customer currentCustomer = customerRepository.findByEmail(email); modelMap.addAttribute("currentCustomer", currentCustomer); modelMap.addAttribute("stores", storeRepository.findAll()); modelMap.addAttribute( "currentOrders", orderService.loadCurrentOrdersForCustomer(currentCustomer)); return "home"; }