From cb298d083e279360846a090679d32f81de53c4dd Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Thu, 19 Sep 2024 08:08:01 +0200 Subject: [PATCH] Improving test --- .../provider/InfinispanPingServiceTest.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/uberfire-extensions/uberfire-metadata/uberfire-metadata-backends/uberfire-metadata-backend-infinispan/src/test/java/org/uberfire/ext/metadata/backend/infinispan/provider/InfinispanPingServiceTest.java b/uberfire-extensions/uberfire-metadata/uberfire-metadata-backends/uberfire-metadata-backend-infinispan/src/test/java/org/uberfire/ext/metadata/backend/infinispan/provider/InfinispanPingServiceTest.java index d1d9d5c258..62c46d8493 100644 --- a/uberfire-extensions/uberfire-metadata/uberfire-metadata-backends/uberfire-metadata-backend-infinispan/src/test/java/org/uberfire/ext/metadata/backend/infinispan/provider/InfinispanPingServiceTest.java +++ b/uberfire-extensions/uberfire-metadata/uberfire-metadata-backends/uberfire-metadata-backend-infinispan/src/test/java/org/uberfire/ext/metadata/backend/infinispan/provider/InfinispanPingServiceTest.java @@ -25,27 +25,30 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import java.util.concurrent.ExecutionException; +import java.util.concurrent.CompletableFuture; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; @RunWith(MockitoJUnitRunner.class) public class InfinispanPingServiceTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private RemoteCacheImpl remoteCache; + private RemoteCacheImpl remoteCache; + + @Mock + PingResponse pingResponse; @Before - public void setUp() throws ExecutionException, InterruptedException { - when(((PingResponse) remoteCache.ping().toCompletableFuture().get()).isSuccess()).thenReturn(true); + public void setUp() { + when(pingResponse.isSuccess()).thenReturn(true); + when(remoteCache.ping().toCompletableFuture()).thenReturn(CompletableFuture.completedFuture(pingResponse)); } @Test - public void testPingSuccess() throws ExecutionException, InterruptedException { + public void testPingSuccess() { { InfinispanPingService service = spy(new InfinispanPingService(remoteCache)); assertTrue(service.ping()); @@ -53,7 +56,7 @@ public void testPingSuccess() throws ExecutionException, InterruptedException { } { - when(((PingResponse) remoteCache.ping().toCompletableFuture().get()).isSuccess()).thenReturn(false); + when(pingResponse.isSuccess()).thenReturn(false); InfinispanPingService service = spy(new InfinispanPingService(remoteCache)); assertFalse(service.ping()); service.stop();