@Test public void testCreateSession$offline(@Mocked final WriteSession nativeSession) throws Exception { new Expectations() {{ delegate.isOffline();result=true; }}; try { createContext().createSession(); fail("Should not create session when off-line"); } catch (ApplicationContextException e) { assertThat(e.getMessage(),notNullValue()); } }
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();  }