diff --git a/core-java-modules/core-java-functional/src/test/java/com/baeldung/callbackfunctions/AsynchronousCallbackUnitTest.java b/core-java-modules/core-java-functional/src/test/java/com/baeldung/callbackfunctions/AsynchronousCallbackUnitTest.java index 494d7365d3..de9e386395 100644 --- a/core-java-modules/core-java-functional/src/test/java/com/baeldung/callbackfunctions/AsynchronousCallbackUnitTest.java +++ b/core-java-modules/core-java-functional/src/test/java/com/baeldung/callbackfunctions/AsynchronousCallbackUnitTest.java @@ -6,8 +6,7 @@ import com.baeldung.callbackfunctions.EventListener; import com.baeldung.callbackfunctions.asynchronous.AsynchronousEventConsumer; import com.baeldung.callbackfunctions.asynchronous.AsynchronousEventListenerImpl; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.*; public class AsynchronousCallbackUnitTest { @@ -17,6 +16,6 @@ public class AsynchronousCallbackUnitTest { AsynchronousEventConsumer asynchronousEventListenerConsumer = new AsynchronousEventConsumer(listener); asynchronousEventListenerConsumer.doAsynchronousOperation(); - verify(listener, times(1)).onTrigger(); + verify(listener, timeout(1000).times(1)).onTrigger(); } } diff --git a/core-java-modules/core-java-functional/src/test/java/com/baeldung/callbackfunctions/ConsumerCallbackUnitTest.java b/core-java-modules/core-java-functional/src/test/java/com/baeldung/callbackfunctions/ConsumerCallbackUnitTest.java index ba09a7e50c..9ba5cdb6ef 100644 --- a/core-java-modules/core-java-functional/src/test/java/com/baeldung/callbackfunctions/ConsumerCallbackUnitTest.java +++ b/core-java-modules/core-java-functional/src/test/java/com/baeldung/callbackfunctions/ConsumerCallbackUnitTest.java @@ -3,18 +3,25 @@ package com.baeldung.callbackfunctions; import org.junit.jupiter.api.Test; import com.baeldung.callbackfunctions.ConsumerCallback; +import java.util.concurrent.atomic.AtomicInteger; + import static org.junit.jupiter.api.Assertions.assertEquals; public class ConsumerCallbackUnitTest { @Test - public void whenIncreasingInitialAgeByGivenValueThroughCallback_shouldIncreaseAge(){ + void whenIncreasingInitialAgeByGivenValueThroughCallback_shouldIncreaseAge(){ ConsumerCallback consumerCallback = new ConsumerCallback(); - consumerCallback.getAge(20, (initialAge) -> { - int ageDifference = 10; + int ageDifference = 10; + AtomicInteger newAge1 = new AtomicInteger(); + int initialAge = 20; + consumerCallback.getAge(initialAge, (initialAge1) -> { consumerCallback.increaseAge(initialAge, ageDifference, (newAge) -> { - assertEquals(initialAge + ageDifference, newAge); + System.out.printf("New age ==> %s", newAge); + newAge1.set(newAge); + }); }); + assertEquals(initialAge + ageDifference, newAge1.get()); } }