package coffee.liz.lambda.eval; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; public class ThunkTest { @Test public void testThunkNonNull() { final AtomicInteger invok = new AtomicInteger(0); final Supplier i = () -> { invok.incrementAndGet(); return invok.get(); }; final Thunk thunk = new Thunk<>(i); Assertions.assertEquals(1, thunk.get()); Assertions.assertEquals(1, thunk.get()); Assertions.assertEquals(1, thunk.get()); Assertions.assertEquals(1, invok.get()); } @Test public void testThunkNull() { final AtomicInteger invok = new AtomicInteger(0); final Supplier i = () -> { invok.incrementAndGet(); return null; }; final Thunk thunk = new Thunk<>(i); Assertions.assertNull(thunk.get()); Assertions.assertNull(thunk.get()); Assertions.assertNull(thunk.get()); Assertions.assertEquals(1, invok.get()); } }