CollectionInitializerService implements
      ICollectionInitializerService { @Override @Transactional @RetryTransaction(2) public void generateInstanceId() { List<ServerInfoEntity> entities = serverInfoDao.findAll(); String newInstanceId = CommonUtil.getUUID(); if (entities != null && entities.size() == 1) { ServerInfoEntity entity = entities.get(0); String instanceId = entity.getInstanceId(); if (CommonUtil.isBlank(instanceId)) { entity.setInstanceId(newInstanceId); serverInfoDao.update(entity); logger.debug("Instance id of server info updated."); } } else { ServerInfoEntity entity = new ServerInfoEntity(); entity.setInstanceId(newInstanceId); serverInfoDao.insert(entity); logger.debug("Instance id of server info inserted."); } }  @Override @Transactional @RetryTransaction(2) void setDeployTime(Date date); @Override @Transactional(readOnly = true) Date getDeployTime(); @Override @Transactional @RetryTransaction(2) void generateInstanceId(); @Override @Transactional(readOnly = true) String getInstanceId(); IServerInfoDAO getServerInfoDao(); @Autowired void setServerInfoDao(IServerInfoDAO serverInfoDao);  }
@Test(groups = { "TestCollectionInitializerService" }) public void testGenerateInstanceId() { serverInfoDao = new MockUp<IServerInfoDAO>() { @Mock List<ServerInfoEntity> findAll() { List<ServerInfoEntity> serverInfos = new ArrayList<ServerInfoEntity>(); ServerInfoEntity serverInfo = new ServerInfoEntity(); serverInfo.setDeployTime(Timestamp.valueOf(DEPLOY_TIME)); serverInfos.add(serverInfo); return serverInfos; } @Mock(invocations = 1) void update(ServerInfoEntity serverInfo) { logger.info("mock update server info"); } }.getMockInstance(); collectionInitializerService.setServerInfoDao(serverInfoDao); collectionInitializerService.generateInstanceId(); }