VenRequestCountService { @Transactional public Long getAndIncrease(String venId) { VenRequestCount findOneAndLock = dao.findOneAndLock(venId); long count = 0L; if (findOneAndLock == null) { findOneAndLock = new VenRequestCount(venId); } else { count = findOneAndLock.getRequestCount(); } findOneAndLock.setRequestCount(count + 1); dao.save(findOneAndLock); return count; }  @Transactional Long getAndIncrease(String venId);  }
@Test public void getAndIncreaseTest() { String venId = "ven1"; Long andIncrease = venRequestCountService.getAndIncrease(venId); assertEquals(new Long(0), andIncrease); andIncrease = venRequestCountService.getAndIncrease(venId); assertEquals(new Long(1), andIncrease); andIncrease = venRequestCountService.getAndIncrease(venId); assertEquals(new Long(2), andIncrease); }