### Question:
BookContainerHandler extends InMemoryContainerHandler { @Override public ResourceSnapshot create(ContainerSnapshot container, DataSet representation, WriteSession session) { NameProvider nameProvider = nameProvider(container.name()); Name<?> nextName = nameProvider.nextMemberName(); try { bookHandler().add(nextName,representation); ResourceSnapshot newMember = container.addMember(nextName); session.saveChanges(); return newMember; } catch (Exception e) { bookHandler().remove(nextName); throw new ApplicationRuntimeException("Could not create member",e); } } BookContainerHandler(); void setBookHandler(BookHandler handler); BookHandler bookHandler(); @Override ResourceSnapshot create(ContainerSnapshot container, DataSet representation, WriteSession session); static final String INSERTED_CONTENT_RELATION; static final String ID; }### Answer:
@SuppressWarnings("unchecked") @Test public void testCreate$happyPath() throws Exception { BookContainerHandler containerHandler = new BookContainerHandler(); BookHandler resourceHandler=new BookHandler(); final Name<String> containerName = name("container"); final NameProvider provider = NameProvider.create(containerName); final Name<String> memberName = name("resource"); provider.addMemberName(memberName); containerHandler.addNameProvider(provider.owner(),provider); containerHandler.setBookHandler(resourceHandler); final DataSet data = DataSets.createDataSet(memberName); new Expectations() {{ snapshot.name();result=containerName; memberSnapshot.name();result=memberName; }}; containerHandler.create(snapshot, data, session); assertThat(provider.pendingMemberNames(),not((contains(memberName)))); assertThat(resourceHandler.get(memberSnapshot),sameInstance(data)); }