### Question:
VersionServiceImpl implements VersionService { @Override public Version lastVersion(Resource resource) { try { Resource versionableResource = resource.isResourceType(NameConstants.NT_PAGE) ? resource.getChild(NameConstants.NN_CONTENT) : resource; VersionManager versionManager = versionableResource.getResourceResolver().adaptTo(Session.class).getWorkspace().getVersionManager(); final Iterator<Version> allVersions = versionManager.getVersionHistory(versionableResource.getPath()).getAllVersions(); return Iterators.getLast(allVersions); } catch (RepositoryException e) { log.error("Error receiving last version of resource [ {} ]", resource.getName()); } return null; }  @Override Version lastVersion(Resource resource);  }### Answer:
@Test @SuppressWarnings("deprecation") public void lastVersion_oneVersion_returnVersion() throws Exception { Version lastVersion = underTest.lastVersion(context.resourceResolver().getResource("/oneVersion")); assertEquals(lastVersion.getUUID(), oneVersionVersion.getUUID()); }
@Test public void lastVersion_noElement_returnNull() throws Exception { Version lastVersion = underTest.lastVersion(context.resourceResolver().getResource("/noVersion")); assertNull(lastVersion); }
@Test @SuppressWarnings("deprecation") public void lastVersion_listOfVersion_returnLast() throws Exception { Version lastVersion = underTest.lastVersion(context.resourceResolver().getResource("/manyVersions")); assertEquals(lastVersion.getUUID(), manyVersionVersion.getUUID()); }