### Question:
CommodityService { public void initialise(User user) { TimingLogger timingLogger = new TimingLogger("TIMER", "initialise"); List<Category> categories = lmisServer.fetchCategories(user); timingLogger.addSplit("fetch all cats"); saveToDatabase(categories); timingLogger.addSplit("save all Cats"); categoryService.clearCache(); syncConstants(user); timingLogger.addSplit("sync constants"); timingLogger.addSplit("all"); Log.i("Inital sync:", "<========== syncing Commodity Action Values"); commodityActionService.syncCommodityActionValues(user); timingLogger.addSplit("actionValues"); categoryService.clearCache(); updateStockValues(all()); categoryService.clearCache(); createInitialStockItemSnapShots(all()); timingLogger.addSplit("updateStockValues"); List<CommodityAction> allocationId = commodityActionService.getAllocationIds(); if (allocationId != null && allocationId.size() > 0) { Log.e("AllocationId Found", allocationId.get(0).toString()); timingLogger.addSplit("sync allocations"); allocationService.syncAllocations(user); } else { Log.e("AllocationId", "Not found"); } categoryService.clearCache(); timingLogger.addSplit("clearCache"); timingLogger.addSplit("sync indicator values"); commodityActionService.syncIndicatorValues(user, all()); timingLogger.dumpToLog(); }  void initialise(User user); List<Commodity> all(); List<Commodity> sortedAll(); void saveToDatabase(final List<Category> categories); List<Commodity> getMost5HighlyDispensedCommodities(); void clearMostConsumedCommoditiesCache(); void addMostDispensedCommoditiesCache(Commodity dispensingCommodity); List<UtilizationItem> getMonthlyUtilizationItems(Commodity commodity, Date date); static final String MONTHLY_STOCK_COUNT_DAY; static final String ROUTINE_ORDER_ALERT_DAY; }### Answer:
@Test public void testShouldLoadAllCommodityCategories() throws Exception { commodityService.initialise(new User("test", "pass")); verifyAllCommodityCategories(); }
@Test public void testShouldPrepareDefaultCommodities() throws Exception { commodityService.initialise(new User("test", "pass")); verifyAllCommodityCategories(); }
@Test public void shouldSaveStockLevelsOnInitialise() throws Exception { setUpInjection(this, new AbstractModule() { @Override protected void configure() { bind(LmisServer.class).toInstance(mockLmisServer); bind(CommodityActionService.class).toInstance(commodityActionService); } }); spyedCommodityService = spy(commodityService); spyedCommodityService.initialise(new User("user", "user")); verify(commodityActionService).syncCommodityActionValues((User) any()); }
@Test public void shouldGetMonthlyStockCountDayAndSaveItToPreferences() throws Exception { commodityService.initialise(new User("test", "pass")); assertThat(sharedPreferences.getInt(CommodityService.MONTHLY_STOCK_COUNT_DAY, 0), is(MOCK_DAY)); }