Skip to content

Commit

Permalink
Improving test
Browse files Browse the repository at this point in the history
  • Loading branch information
yesamer committed Sep 19, 2024
1 parent 0294ac2 commit cb298d0
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,38 @@
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());
service.stop();
}

{
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();
Expand Down

0 comments on commit cb298d0

Please sign in to comment.