CashierOptionsServiceGpImpl implements ICashierOptionsService { public CashierOptions getOptions() { CashierOptions options = new CashierOptions(); setDefaultReceiptReportId(options); setRoundingOptions(options); if (StringUtils.isEmpty(options.getRoundingItemUuid())) { setRoundingOptionsForEmptyUuid(options); } setTimesheetOptions(options); return options; } @Autowired  CashierOptionsServiceGpImpl(AdministrationService adminService, IItemDataService itemService); CashierOptions getOptions();  }
@Test public void getOptions_shouldLoadCashierOptionsFromTheDatabase() throws Exception { when(adminService.getGlobalProperty(ModuleSettings.RECEIPT_REPORT_ID_PROPERTY)) .thenReturn("1"); when(adminService.getGlobalProperty(ModuleSettings.ROUNDING_MODE_PROPERTY)) .thenReturn(CashierOptions.RoundingMode.MID.toString()); when(adminService.getGlobalProperty(ModuleSettings.ROUND_TO_NEAREST_PROPERTY)) .thenReturn("5"); when(adminService.getGlobalProperty(ModuleSettings.ROUNDING_ITEM_ID)) .thenReturn("1"); when(adminService.getGlobalProperty(ModuleSettings.TIMESHEET_REQUIRED_PROPERTY)) .thenReturn("true"); Item item = new Item(); when(itemService.getById(1)) .thenReturn(item); CashierOptions options = optionsService.getOptions(); Assert.assertNotNull(options); Assert.assertEquals(1, options.getDefaultReceiptReportId()); Assert.assertEquals(CashierOptions.RoundingMode.MID, options.getRoundingMode()); Assert.assertEquals(5, (int)options.getRoundToNearest()); Assert.assertEquals(item.getUuid(), options.getRoundingItemUuid()); Assert.assertEquals(true, options.isTimesheetRequired()); }
@Test public void getOptions_shouldNotThrowExceptionIfNumericOptionsAreNull() throws Exception { when(adminService.getGlobalProperty(ModuleSettings.RECEIPT_REPORT_ID_PROPERTY)) .thenReturn(null); when(adminService.getGlobalProperty(ModuleSettings.ROUNDING_MODE_PROPERTY)) .thenReturn(null); when(adminService.getGlobalProperty(ModuleSettings.ROUND_TO_NEAREST_PROPERTY)) .thenReturn(null); when(adminService.getGlobalProperty(ModuleSettings.ROUNDING_ITEM_ID)) .thenReturn(null); when(adminService.getGlobalProperty(ModuleSettings.TIMESHEET_REQUIRED_PROPERTY)) .thenReturn(null); CashierOptions options = optionsService.getOptions(); Assert.assertNotNull(options); }
@Test public void getOptions_shouldDefaultToFalseIfTimesheetRequiredIsNotSpecified() throws Exception { when(adminService.getGlobalProperty(ModuleSettings.RECEIPT_REPORT_ID_PROPERTY)) .thenReturn(null); when(adminService.getGlobalProperty(ModuleSettings.ROUNDING_MODE_PROPERTY)) .thenReturn(null); when(adminService.getGlobalProperty(ModuleSettings.ROUND_TO_NEAREST_PROPERTY)) .thenReturn(null); when(adminService.getGlobalProperty(ModuleSettings.ROUNDING_ITEM_ID)) .thenReturn(null); when(adminService.getGlobalProperty(ModuleSettings.TIMESHEET_REQUIRED_PROPERTY)) .thenReturn(null); CashierOptions options = optionsService.getOptions(); Assert.assertNotNull(options); Assert.assertEquals(false, options.isTimesheetRequired()); }
@Test public void getOptions_shouldLogErrorIfRoundingItemIdCannotBeParsed() throws Exception { when(adminService.getGlobalProperty(ModuleSettings.RECEIPT_REPORT_ID_PROPERTY)) .thenReturn(null); when(adminService.getGlobalProperty(ModuleSettings.ROUNDING_MODE_PROPERTY)) .thenReturn(CashierOptions.RoundingMode.FLOOR.toString()); when(adminService.getGlobalProperty(ModuleSettings.ROUND_TO_NEAREST_PROPERTY)) .thenReturn("5"); when(adminService.getGlobalProperty(ModuleSettings.ROUNDING_ITEM_ID)) .thenReturn("HELP"); Logger logger = Logger.getLogger(CashierOptionsServiceGpImpl.class); ByteArrayOutputStream out = new ByteArrayOutputStream(); Layout layout = new SimpleLayout(); Appender appender = new WriterAppender(layout, out); logger.addAppender(appender); try { optionsService.getOptions(); String logMsg = out.toString(); assertNotNull(logMsg); assertFalse((logMsg.trim()).equals("")); } finally { logger.removeAppender(appender); } }
@Test public void getOptions_shouldLogErrorIfRoundingItemIsNullDespiteIdGiven() throws Exception { when(adminService.getGlobalProperty(ModuleSettings.RECEIPT_REPORT_ID_PROPERTY)) .thenReturn(null); when(adminService.getGlobalProperty(ModuleSettings.ROUNDING_MODE_PROPERTY)) .thenReturn(CashierOptions.RoundingMode.FLOOR.toString()); when(adminService.getGlobalProperty(ModuleSettings.ROUND_TO_NEAREST_PROPERTY)) .thenReturn("5"); when(adminService.getGlobalProperty(ModuleSettings.ROUNDING_ITEM_ID)) .thenReturn("273423"); when(adminService.getGlobalProperty(ModuleSettings.TIMESHEET_REQUIRED_PROPERTY)) .thenReturn(null); Logger logger = Logger.getLogger(CashierOptionsServiceGpImpl.class); ByteArrayOutputStream out = new ByteArrayOutputStream(); Layout layout = new SimpleLayout(); Appender appender = new WriterAppender(layout, out); logger.addAppender(appender); try { optionsService.getOptions(); String logMsg = out.toString(); assertNotNull(logMsg); assertFalse((logMsg.trim()).equals("")); } finally { logger.removeAppender(appender); } }