UserMgmtServerEao { @Transactional(propagation = Propagation.SUPPORTS) public UserMgmtServer findByName(String name, boolean safely) { UserMgmtServerEntity userMgmtServerEntity = userMgmtServerDao.findById(name); UserMgmtServer userMgmtServer = userMgmtServerEntity == null ? null : userMgmtServerEntity.copyTo(); if(!safely) { decryptPassword(userMgmtServer); } return userMgmtServer; }  void persist(UserMgmtServer usrMgmtServer); @Transactional(propagation = Propagation.SUPPORTS) UserMgmtServer findByName(String name, boolean safely); void delete(String name); void checkServerChanged(UserMgmtServer userMgtServer); void modify(UserMgmtServer usrMgmtServer);  }
@Test(groups = {"TestUserMgmtServerEao"}) public void testFindByName() { userMgmtServerDao = new MockUp<IBaseDAO<UserMgmtServerEntity>>() { @Mock(invocations = 2) public UserMgmtServerEntity findById(Serializable id) { UserMgmtServerEntity userMgmtServerEntity = prepareUserMgmtServerEntity(decodePassword); return userMgmtServerEntity; } }.getMockInstance(); TestUtils.setPrivateField(userMgmtServerEao, "userMgmtServerDao", userMgmtServerDao); UserMgmtServer userMgmtServer = userMgmtServerEao.findByName(name, false); assertUserMgmtServer(userMgmtServer, false); userMgmtServer = userMgmtServerEao.findByName(name, true); assertUserMgmtServer(userMgmtServer, true); }