### Question:
StandardRevisableEntityService implements RevisableEntityService { @Override public <T extends RevisableEntity> T create(final T requestEntity, final String creatorIdentity, final Supplier<T> createEntity) { if (requestEntity == null) { throw new IllegalArgumentException("Request entity is required"); } if (requestEntity.getRevision() == null || requestEntity.getRevision().getVersion() == null) { throw new IllegalArgumentException("Revision info is required"); } if (requestEntity.getRevision().getVersion() != 0) { throw new IllegalArgumentException("A revision version of 0 must be specified when creating a new entity"); } return createOrUpdate(requestEntity, creatorIdentity, createEntity); } StandardRevisableEntityService(final RevisionManager revisionManager); @Override T create(final T requestEntity, final String creatorIdentity, final Supplier<T> createEntity); @Override T get(final Supplier<T> getEntity); @Override List<T> getEntities(final Supplier<List<T>> getEntities); @Override T update(final T requestEntity, final String updaterIdentity, final Supplier<T> updateEntity); @Override T delete(final String entityIdentifier, final RevisionInfo revisionInfo, final Supplier<T> deleteEntity); @Override void populateRevisions(final Collection<?> entities);  }### Answer:
@Test public void testCreate() { final String clientId = "client1"; final RevisionInfo requestRevision = new RevisionInfo(clientId, 0L); final String userIdentity = "user1"; final String entityId = "1"; final RevisableEntity requestEntity = new TestEntity(entityId, requestRevision); final RevisableEntity createdEntity = entityService.create( requestEntity, userIdentity, () -> new TestEntity(entityId, null)); assertNotNull(createdEntity); assertEquals(requestEntity.getIdentifier(), createdEntity.getIdentifier()); final RevisionInfo createdRevision = createdEntity.getRevision(); assertNotNull(createdRevision); assertEquals(requestRevision.getVersion().longValue() + 1, createdRevision.getVersion().longValue()); assertEquals(clientId, createdRevision.getClientId()); assertEquals(userIdentity, createdRevision.getLastModifier()); }
@Test(expected = IllegalArgumentException.class) public void testCreateWhenMissingRevision() { final RevisableEntity requestEntity = new TestEntity("1", null); entityService.create(requestEntity, "user1", () -> requestEntity); }
@Test(expected = IllegalArgumentException.class) public void testCreateWhenNonZeroRevision() { final RevisionInfo requestRevision = new RevisionInfo(null, 99L); final RevisableEntity requestEntity = new TestEntity("1", requestRevision); entityService.create(requestEntity, "user1", () -> requestEntity); }
@Test(expected = IllegalArgumentException.class) public void testCreateWhenTaskThrowsException() { final RevisionInfo requestRevision = new RevisionInfo("client1", 0L); final RevisableEntity requestEntity = new TestEntity("1", requestRevision); entityService.create(requestEntity, "user1", () -> { throw new IllegalArgumentException(""); }); }