blob: 2a1d5e392cbda37000fa66efc9f918dde19c6e51 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
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<Integer> i = () -> {
invok.incrementAndGet();
return invok.get();
};
final Thunk<Integer> 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<Integer> i = () -> {
invok.incrementAndGet();
return null;
};
final Thunk<Integer> thunk = new Thunk<>(i);
Assertions.assertNull(thunk.get());
Assertions.assertNull(thunk.get());
Assertions.assertNull(thunk.get());
Assertions.assertEquals(1, invok.get());
}
}
|