### Question:
AsyncSharedNetworksUpdateHandler { public void handleGradients(Gradients gradients) { globalCurrent.applyGradients(gradients); ++updateCount; if(target != null) { syncTargetNetwork(); } } AsyncSharedNetworksUpdateHandler(@NonNull ITrainableNeuralNet globalCurrent,
                                            @NonNull NeuralNetUpdaterConfiguration configuration);  AsyncSharedNetworksUpdateHandler(@NonNull ITrainableNeuralNet globalCurrent,
                                            @NonNull ITrainableNeuralNet target,
                                            @NonNull NeuralNetUpdaterConfiguration configuration); void handleGradients(Gradients gradients);  }### Answer:
@Test public void when_handleGradientsIsCalledWithoutTarget_expect_gradientsAppliedOnGlobalCurrent() { NeuralNetUpdaterConfiguration configuration = NeuralNetUpdaterConfiguration.builder() .build(); AsyncSharedNetworksUpdateHandler sut = new AsyncSharedNetworksUpdateHandler(globalCurrentMock, configuration); Gradients gradients = new Gradients(10); sut.handleGradients(gradients); verify(globalCurrentMock, times(1)).applyGradients(gradients); }
@Test public void when_handleGradientsIsCalledWithTarget_expect_gradientsAppliedOnGlobalCurrentAndTargetUpdated() { NeuralNetUpdaterConfiguration configuration = NeuralNetUpdaterConfiguration.builder() .targetUpdateFrequency(2) .build(); AsyncSharedNetworksUpdateHandler sut = new AsyncSharedNetworksUpdateHandler(globalCurrentMock, targetMock, configuration); Gradients gradients = new Gradients(10); sut.handleGradients(gradients); sut.handleGradients(gradients); verify(globalCurrentMock, times(2)).applyGradients(gradients); verify(targetMock, times(1)).copyFrom(globalCurrentMock); }