@Test
public void runWithContexts_must_temporarily_associate_local_contexts()
throws InterruptedException
{
fixture.addGlobalContext(globalContext1);
fixture.addGlobalContext(globalContext2);
fixture.addGlobalContext(globalContext3);
assertThat(fixture.getContexts(), is(Arrays.asList(globalContext1, globalContext2, globalContext3)));
final String result = fixture.runWithContexts(Arrays.asList(localContext1, localContext2, localContext3),
new Task<String, RuntimeException>()
{
@Override @Nonnull
public String run()
{
assertThat(fixture.getContexts(), is(Arrays.asList(globalContext1, globalContext2, globalContext3,
localContext3, localContext2, localContext1)));
return "result";
}
});
assertThat(fixture.getContexts(), is(Arrays.asList(globalContext1, globalContext2, globalContext3)));
assertThat(result, is("result"));
}
}