### Question:
AllocationService { public List<Allocation> all() { if (allAllocations == null) { allAllocations = dbUtil.withDao(Allocation.class, new DbUtil.Operation<Allocation, List<Allocation>>() { @Override public List<Allocation> operate(Dao<Allocation, String> dao) throws SQLException { return dao.queryForAll(); } }); } return allAllocations; } AllocationService(DbUtil dbUtil);  AllocationService(); List<String> getYetToBeReceivedAllocationIds(); List<String> getReceivedAllocationIds(); Allocation getAllocationByLmisId(final String allocationID); void update(Allocation allocation); void syncAllocations(User user); void createAllocation(Allocation allocation); List<Allocation> getYetToBeReceivedAllocations(); List<Allocation> all(); static void clearCache();  }### Answer:
@Test public void shouldGetAllocationsByRecieved() throws Exception { DbUtil dbUtil = mock(DbUtil.class); AllocationService allocationService1 = new AllocationService(dbUtil); allocationService1.all(); verify(dbUtil, atLeast(1)).withDao(eq(Allocation.class), any(DbUtil.Operation.class)); }
@Test public void shouldGetAndCacheAllocationsByRecieved() throws Exception { List<Allocation> returnedAllocations = new ArrayList<>(Arrays.asList(new Allocation("UG-2013", "20140901"))); DbUtil dbUtil = mock(DbUtil.class); AllocationService allocationService1 = new AllocationService(dbUtil); when(dbUtil.withDao(eq(Allocation.class), any(DbUtil.Operation.class))).thenReturn(returnedAllocations); allocationService1.all(); allocationService1.all(); verify(dbUtil, atMost(1)).withDao(eq(Allocation.class), any(DbUtil.Operation.class)); }