### Question:
BuildSessionImpl implements BuildSession { @Override public synchronized void executeOnce( @NonNull String actionGroup, @NonNull String actionName, @NonNull Runnable action) { Preconditions.checkState(buildState == BuildState.STARTED); String actionId = actionGroup + ":" + actionName; if (!executedActions.contains(actionId)) { executedActions.add(actionId); action.run(); } }  @NonNull static BuildSession getSingleton(); @Override synchronized void initialize(@NonNull Gradle gradle); @Override synchronized void executeOnce(
            @NonNull String actionGroup, @NonNull String actionName, @NonNull Runnable action); @Override synchronized void executeOnceWhenBuildFinished(
            @NonNull String actionGroup, @NonNull String actionName, @NonNull Runnable action); @Override @SuppressWarnings("GuardedBy") String toString();  }### Answer:
@Test public void testExecuteOnce() { BuildSession singleton = BuildSessionImpl.createBuildSessionSingleton(fakePluginVersion); Gradle gradle = mock(Gradle.class); singleton.initialize(gradle); ArgumentCaptor<BuildListener> captor = ArgumentCaptor.forClass(BuildListener.class); verify(gradle).addBuildListener(captor.capture()); BuildListener buildListener = captor.getValue(); AtomicInteger counter = new AtomicInteger(0); Runnable increaseCounter = counter::incrementAndGet; singleton.executeOnce( BuildSessionImplTest.class.getName(), "increaseCounter", increaseCounter); assertThat(counter.get()).isEqualTo(1); singleton.executeOnce( BuildSessionImplTest.class.getName(), "increaseCounter", increaseCounter); assertThat(counter.get()).isEqualTo(1); singleton.executeOnce( BuildSessionImplTest.class.getName(), "alsoIncreaseCounter", increaseCounter); assertThat(counter.get()).isEqualTo(2); singleton.executeOnce( BuildSessionImplTest.class.getName(), "increaseCounter", () -> counter.getAndAdd(4)); assertThat(counter.get()).isEqualTo(2); singleton.executeOnce( BuildSessionImplTest.class.getName(), "increaseCounterBy4", () -> counter.getAndAdd(8)); assertThat(counter.get()).isEqualTo(10); buildListener.buildFinished(new BuildResult(null, null)); assertThat(counter.get()).isEqualTo(10); singleton.initialize(gradle); singleton.executeOnce( BuildSessionImplTest.class.getName(), "increaseCounter", increaseCounter); assertThat(counter.get()).isEqualTo(11); buildListener.buildFinished(new BuildResult(null, null)); assertThat(counter.get()).isEqualTo(11); }