CashierOptionsController { @RequestMapping(method = RequestMethod.GET) @ResponseBody public CashierOptions options() { CashierOptions options = cashierOptionsService.getOptions(); String roundingModeProperty = adminService.getGlobalProperty(ModuleSettings.ROUNDING_MODE_PROPERTY); String roundingItemId = adminService.getGlobalProperty(ModuleSettings.ROUNDING_ITEM_ID); if (StringUtils.isNotEmpty(roundingModeProperty)) { if (StringUtils.isEmpty(options.getRoundingItemUuid()) && StringUtils.isNotEmpty(roundingItemId)) { throw new APIException("Rounding item ID set in options but item not found. Make sure your user has the " + "required rights and the item has the set ID in the database"); } if (StringUtils.isEmpty(roundingItemId) && options.getRoundToNearest() != null && !options.getRoundToNearest().equals(BigDecimal.ZERO)) { throw new APIException("Rounding enabled (nearest " + options.getRoundToNearest().toString() + ") but no rounding item ID specified in options."); } } return options; } @Autowired  CashierOptionsController(AdministrationService adminService, ICashierOptionsService cashierOptionsService); @RequestMapping(method = RequestMethod.GET) @ResponseBody CashierOptions options();  }
@Test public void shouldThrowAPIExceptionIfIdSetAndItemNotFound() throws Exception { expectedEx.expect(APIException.class); expectedEx.expectMessage("Rounding item ID set in options"); options = new CashierOptions(); options.setRoundingItemUuid(null); when(cashierOptionsService.getOptions()).thenReturn(options); when(adminService.getGlobalProperty(ModuleSettings.ROUNDING_ITEM_ID)).thenReturn("12"); cashierOptionsController.options(); }
@Test public void shouldThrowAPIExceptionWhenRoundingIsEnabledButNoRoundingIdSet() throws Exception { expectedEx.expect(APIException.class); expectedEx.expectMessage("Rounding enabled "); options = new CashierOptions(); options.setRoundToNearest(10); when(cashierOptionsService.getOptions()).thenReturn(options); when(adminService.getGlobalProperty(ModuleSettings.ROUNDING_ITEM_ID)).thenReturn(null); cashierOptionsController.options(); }