### Question:
CoreRuntimeDelegate extends RuntimeDelegate { @Override public WriteSession createSession() throws ApplicationContextException { try { WriteSessionService sessionService = sessionService(); WriteSession delegate = sessionService. createSession( WriteSessionConfiguration. builder(). build()); Transaction transaction=transactionManager().currentTransaction(); transaction.begin(); return new TransactionalWriteSession(transaction,delegate); } catch (Exception e) { throw new ApplicationContextException("Could not create session",e); } } CoreRuntimeDelegate(); @Override boolean isOffline(); @Override WriteSession createSession(); @Override ResourceSnapshotResolver createResourceResolver(URI canonicalBase, ReadSession session); @Override void registerShutdownListener(ShutdownListener listener);  }### Answer:
@Test public void testCreateSession$happyPath() throws Exception { new Expectations() {{ engine.unwrap(DefaultApplicationEngine.class);result=engine; engine.writeSessionService();result=sessionService; sessionService.createSession((WriteSessionConfiguration)any);result=session; engine.transactionManager();result=transactionManager; transactionManager.currentTransaction();result=transaction; }}; new MockUp<ApplicationEngine>() { @Mock public ApplicationEngine engine() throws ApplicationEngineException { return engine; } }; CoreRuntimeDelegate sut=new CoreRuntimeDelegate(); assertThat(sut.createSession(),notNullValue()); }
@Test public void testCreateSession$failure() throws Exception { new MockUp<ApplicationEngine>() { @Mock public ApplicationEngine engine() throws ApplicationEngineException { throw new ApplicationEngineException("FAILURE"); } }; CoreRuntimeDelegate sut=new CoreRuntimeDelegate(); try { sut.createSession(); fail("Should not be able to create session if the application engine fails"); } catch (ApplicationContextException e) { assertThat(e.getMessage(),equalTo("Could not create session")); } }