### Question:
HibernateVersionDAO extends HibernatePersistentObjectDAO<Version> implements VersionDAO { @Override public boolean store(Version version) { boolean result = true; try { result = super.store(version); if (!result) return false; ContextProperties bean = new ContextProperties(); int maxVersions = bean.getInt("document.maxversions"); Folder workspace = folderDAO.findWorkspace(version.getFolderId()); if (workspace != null && workspace.getMaxVersions() != null && workspace.getMaxVersions() > 0) maxVersions = workspace.getMaxVersions(); if (maxVersions > 0) { List<Version> versions = findByDocId(version.getDocId()); if (versions.size() > maxVersions) { Collections.sort(versions, new Comparator<Version>() { public int compare(Version v1, Version v2) { return v2.compareTo(v1); } }); Set<String> filesToBeRetained = new HashSet<String>(); for (int i = 0; i < versions.size(); i++) { if (i < maxVersions) if (!filesToBeRetained.contains(versions.get(i).getFileVersion())) filesToBeRetained.add(versions.get(i).getFileVersion()); } for (int i = 0; i < versions.size(); i++) { if (i >= maxVersions) { Version deleteVersion = versions.get(i); initialize(deleteVersion); deleteVersion.setDeleted(1); store(deleteVersion); } } List<String> resources = storer.listResources(version.getDocId(), null); for (String resource : resources) { boolean toDelete = true; for (String fileVersionToRetain : filesToBeRetained) { if (resource.trim().equals(fileVersionToRetain.trim()) || resource.trim().startsWith(fileVersionToRetain.trim() + "-")) { toDelete = false; break; } } if (toDelete) { storer.delete(version.getDocId(), resource); } } } } } catch (Throwable e) { log.error(e.getMessage(), e); result = false; } return result; } private  HibernateVersionDAO(); @Override List<Version> findByDocId(long docId); @Override Version findByVersion(long docId, String version); @Override Version findByFileVersion(long docId, String fileVersion); @Override void initialize(Version version); @Override boolean store(Version version); @Override void updateDigest(Version version); void setStorer(Storer storer); @Override boolean delete(long versionId, int delCode); void setFolderDAO(FolderDAO folderDAO);  }### Answer:
@Test public void testStore() { Version version = new Version(); version.setDeleted(0); version.setComment("pippo"); version.setUserId(1); version.setUsername("matteo"); version.setDocId(1); Assert.assertTrue(dao.store(version)); Assert.assertNotNull(dao.findById(2)); Assert.assertNotNull(dao.findById(1)); Document doc = docDao.findById(1); docDao.initialize(doc); User user = new User(); user.setId(1); user.setUsername("admin"); user.setName("xx"); user.setFirstName("xx"); version = Version.create(doc, user, "", Version.EVENT_STORED, true); dao.store(version); }