File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed
approvaltests-util-tests/src/test/java/org/lambda/utils
approvaltests-util/src/main/java/org/lambda/utils Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change 11package org .lambda .utils ;
22
3+ import com .spun .util .NumberUtils ;
34import org .junit .jupiter .api .Test ;
45
56import static org .junit .jupiter .api .Assertions .assertEquals ;
@@ -18,7 +19,13 @@ public void testOnce() {
1819 }
1920
2021 private void increment () {
21- Once .run (() -> OnceTest .count ++);
22+ var fieldThatForcesLambdaToHaveMultipleInstances = NumberUtils .doRandomPercentage (50 );
23+ Once .run (() -> {
24+ if (fieldThatForcesLambdaToHaveMultipleInstances )
25+ OnceTest .count ++;
26+ else
27+ OnceTest .count ++;
28+ });
2229 }
2330
2431 @ Test
Original file line number Diff line number Diff line change 66import java .util .*;
77
88public class Once {
9- private static final Set <Action0 > actions = Collections .synchronizedSet (new HashSet <>());
9+ private static final Set <Class > actions = Collections .synchronizedSet (new HashSet <>());
1010 private static final Map <Class , Object > functions = Collections .synchronizedMap (new HashMap <>());
1111 public static void run (Action0 runnable ) {
12- if (!actions .contains (runnable )) {
13- actions .add (runnable );
12+ if (!actions .contains (runnable . getClass () )) {
13+ actions .add (runnable . getClass () );
1414 runnable .call ();
1515 }
1616 }
You can’t perform that action at this time.
0 commit comments