@Test public void testWriteSession$completed$find(@Mocked final WriteSession nativeSession) throws Exception { new Expectations() {{ delegate.createSession();result=nativeSession; }}; ApplicationContext sut = createContext(); WriteSession session = sut.createSession(); session.saveChanges(); try { session.find(ResourceSnapshot.class,this.resourceName,CustomResourceHandler.class); fail("Session should not find resources after being closed"); } catch (Exception e) { assertThat(Throwables.getRootCause(e),instanceOf(IllegalStateException.class)); } finally { session.close(); } new Verifications() {{ nativeSession.find(ResourceSnapshot.class,resourceName,CustomResourceHandler.class);maxTimes=0; nativeSession.saveChanges();maxTimes=1;minTimes=1; nativeSession.close();maxTimes=1;minTimes=1; }}; }
public synchronized WriteSession createSession() throws ApplicationContextException { if(this.threadSession.containsKey(Thread.currentThread().getId())) { throw failure("Thread already has an active session"); } if(this.delegate.isOffline()) { throw failure("The Application Engine is off-line"); } WriteSession nativeSession=this.delegate.createSession(); if(nativeSession==null) { throw failure("Could not create native write session"); } setUpWriteSessionCleaner(); return trackSession( new ContextWriteSessionState( nativeSession, new CleanerContextWriteSessionStateListener())); }
ApplicationContext { public synchronized WriteSession createSession() throws ApplicationContextException { if(this.threadSession.containsKey(Thread.currentThread().getId())) { throw failure("Thread already has an active session"); } if(this.delegate.isOffline()) { throw failure("The Application Engine is off-line"); } WriteSession nativeSession=this.delegate.createSession(); if(nativeSession==null) { throw failure("Could not create native write session"); } setUpWriteSessionCleaner(); return trackSession( new ContextWriteSessionState( nativeSession, new CleanerContextWriteSessionStateListener())); } }
ApplicationContext { public synchronized WriteSession createSession() throws ApplicationContextException { if(this.threadSession.containsKey(Thread.currentThread().getId())) { throw failure("Thread already has an active session"); } if(this.delegate.isOffline()) { throw failure("The Application Engine is off-line"); } WriteSession nativeSession=this.delegate.createSession(); if(nativeSession==null) { throw failure("Could not create native write session"); } setUpWriteSessionCleaner(); return trackSession( new ContextWriteSessionState( nativeSession, new CleanerContextWriteSessionStateListener())); } private  ApplicationContext(); }
ApplicationContext { public synchronized WriteSession createSession() throws ApplicationContextException { if(this.threadSession.containsKey(Thread.currentThread().getId())) { throw failure("Thread already has an active session"); } if(this.delegate.isOffline()) { throw failure("The Application Engine is off-line"); } WriteSession nativeSession=this.delegate.createSession(); if(nativeSession==null) { throw failure("Could not create native write session"); } setUpWriteSessionCleaner(); return trackSession( new ContextWriteSessionState( nativeSession, new CleanerContextWriteSessionStateListener())); } private  ApplicationContext(); synchronized WriteSession createSession(); @Override synchronized String toString(); static ApplicationContext getInstance(); }
ApplicationContext { public synchronized WriteSession createSession() throws ApplicationContextException { if(this.threadSession.containsKey(Thread.currentThread().getId())) { throw failure("Thread already has an active session"); } if(this.delegate.isOffline()) { throw failure("The Application Engine is off-line"); } WriteSession nativeSession=this.delegate.createSession(); if(nativeSession==null) { throw failure("Could not create native write session"); } setUpWriteSessionCleaner(); return trackSession( new ContextWriteSessionState( nativeSession, new CleanerContextWriteSessionStateListener())); } private  ApplicationContext(); synchronized WriteSession createSession(); @Override synchronized String toString(); static ApplicationContext getInstance();  }