@@ -0,0 +1,2915 @@
+/*%0A * Copyright 2016-2018 Talsma ICT%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *         http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage nl.talsmasoftware.context.functions;%0A%0Aimport nl.talsmasoftware.context.Context;%0Aimport nl.talsmasoftware.context.ContextManagers;%0Aimport nl.talsmasoftware.context.ContextSnapshot;%0Aimport nl.talsmasoftware.context.DummyContextManager;%0Aimport org.junit.After;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport java.util.Optional;%0Aimport java.util.concurrent.ExecutionException;%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.Future;%0Aimport java.util.concurrent.TimeUnit;%0Aimport java.util.function.BooleanSupplier;%0A%0Aimport static org.hamcrest.MatcherAssert.assertThat;%0Aimport static org.hamcrest.Matchers.is;%0A%0A/**%0A * @author Sjoerd Talsma%0A */%0Apublic class BooleanSupplierWithContextTest %7B%0A%0A    private ExecutorService unawareThreadpool;%0A%0A    @Before%0A    @After%0A    public void clearDummyContext() %7B%0A        DummyContextManager.clear();%0A    %7D%0A%0A    @Before%0A    @SuppressWarnings(%22unchecked%22)%0A    public void setUp() %7B%0A        unawareThreadpool = Executors.newCachedThreadPool();%0A    %7D%0A%0A    @After%0A    public void tearDown() throws InterruptedException %7B%0A        unawareThreadpool.shutdown();%0A        unawareThreadpool.awaitTermination(5, TimeUnit.SECONDS);%0A    %7D%0A%0A    @Test%0A    public void testGetAsBooleanWithSnapshotConsumer() throws ExecutionException, InterruptedException %7B%0A        DummyContextManager.setCurrentValue(%22true%22);%0A        final ContextSnapshot%5B%5D snapshotHolder = new ContextSnapshot%5B1%5D;%0A%0A        BooleanSupplier supplier = new BooleanSupplierWithContext(ContextManagers.createContextSnapshot(), () -%3E %7B%0A            try %7B%0A                return Boolean.parseBoolean(DummyContextManager.currentValue().get());%0A            %7D finally %7B%0A                DummyContextManager.setCurrentValue(%22false%22);%0A            %7D%0A        %7D, s -%3E snapshotHolder%5B0%5D = s);%0A%0A        Future%3CBoolean%3E future = unawareThreadpool.submit(supplier::getAsBoolean);%0A        assertThat(future.get(), is(true));%0A%0A        assertThat(DummyContextManager.currentValue(), is(Optional.of(%22true%22)));%0A        try (Context%3CVoid%3E reactivation = snapshotHolder%5B0%5D.reactivate()) %7B%0A            assertThat(DummyContextManager.currentValue(), is(Optional.of(%22false%22)));%0A        %7D%0A        assertThat(DummyContextManager.currentValue(), is(Optional.of(%22true%22)));%0A    %7D%0A%0A%7D%0A

Add unit test for `BooleanSupplierWithContext`