ContextImpl implements Context { @Override public ExternalContext getExternalContext() { Preconditions.checkState(this.externalContextOptional.isPresent(), "No external context exists"); return this.externalContextOptional.get(); } ContextImpl(JobContext jobContext, ContainerContext containerContext, TaskContext taskContext,
      Optional<ApplicationContainerContext> applicationContainerContextOptional,
      Optional<ApplicationTaskContext> applicationTaskContextOptional,
      Optional<ExternalContext> externalContextOptional); @Override JobContext getJobContext(); @Override ContainerContext getContainerContext(); @Override TaskContext getTaskContext(); @Override ApplicationContainerContext getApplicationContainerContext(); @Override ApplicationTaskContext getApplicationTaskContext(); @Override ExternalContext getExternalContext(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testGetExternalContext() { ExternalContext externalContext = mock(ExternalContext.class); Context context = buildWithExternalContext(externalContext); assertEquals(externalContext, context.getExternalContext()); }
@Test(expected = IllegalStateException.class) public void testGetMissingExternalContext() { Context context = buildWithExternalContext(null); context.getExternalContext(); }