Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 44ec236

Browse files
committed
PR for CallExecutor does not know the type of a result #72
Avoid dependency on any mock for tests of a result type
1 parent f2a4c5e commit 44ec236

File tree

2 files changed

+26
-52
lines changed

2 files changed

+26
-52
lines changed

src/test/java/com/evanlennick/retry4j/AsyncCallExecutorTest_ListenersTest.java

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,24 @@
22

33
import com.evanlennick.retry4j.config.RetryConfig;
44
import com.evanlennick.retry4j.config.RetryConfigBuilder;
5-
import com.evanlennick.retry4j.listener.RetryListener;
6-
import org.mockito.Mock;
75
import org.mockito.MockitoAnnotations;
86
import org.testng.annotations.BeforeMethod;
97
import org.testng.annotations.Test;
108

119
import java.time.temporal.ChronoUnit;
12-
import java.util.concurrent.Callable;
10+
import java.util.ArrayList;
11+
import java.util.List;
1312
import java.util.concurrent.Executors;
1413

1514
import static org.assertj.core.api.Assertions.assertThat;
16-
import static org.mockito.Mockito.timeout;
17-
import static org.mockito.Mockito.verify;
18-
import static org.mockito.Mockito.when;
1915

2016
public class AsyncCallExecutorTest_ListenersTest {
21-
@Mock
22-
private DummyMock dummyMock;
2317
private AsyncCallExecutor<String> executor;
24-
private Callable<String> callable;
2518

2619
@BeforeMethod
2720
public void setup() {
2821
MockitoAnnotations.initMocks(this);
2922

30-
callable = () -> dummyMock.callableCallThis();
31-
3223
RetryConfig config = new RetryConfigBuilder()
3324
.retryOnAnyException()
3425
.withMaxNumberOfTries(5)
@@ -41,33 +32,17 @@ public void setup() {
4132

4233
@Test
4334
public void verifyOnListener_resultHasTypeOfCallExecutor() throws Exception {
44-
when(dummyMock.callableCallThis())
45-
.thenReturn("success!");
46-
47-
RetryListener<String> listener = status -> {
48-
dummyMock.listenersCallThis();
49-
assertThat(status.getResult()).isInstanceOf(String.class);
50-
};
35+
List<String> methodCalls = new ArrayList<>();
5136
executor
52-
.onSuccess(listener)
53-
.onCompletion(listener)
54-
.execute(callable).get();
55-
56-
// ensure both listeners are called
57-
verify(dummyMock, timeout(1000).times(2)).listenersCallThis();
58-
}
59-
60-
private class DummyMock {
61-
public String listenersCallThis() {
62-
return "this is to use to verify listeners call the mock";
63-
}
64-
65-
public String listenersCallThis(Exception e) {
66-
return "this is to verify exceptions in the after failed call listener";
67-
}
68-
69-
public String callableCallThis() {
70-
return "this is to use for mocking the executed callable";
71-
}
37+
.onSuccess(status -> {
38+
methodCalls.add("onSuccess");
39+
assertThat(status.getResult()).isInstanceOf(String.class);
40+
})
41+
.onCompletion(status -> {
42+
methodCalls.add("onCompletion");
43+
assertThat(status.getResult()).isInstanceOf(String.class);
44+
})
45+
.execute(() -> "").get();
46+
assertThat(methodCalls).contains("onSuccess", "onCompletion");
7247
}
7348
}

src/test/java/com/evanlennick/retry4j/CallExecutorTest_ListenersTest.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
import com.evanlennick.retry4j.config.RetryConfig;
44
import com.evanlennick.retry4j.config.RetryConfigBuilder;
5-
import com.evanlennick.retry4j.listener.RetryListener;
65
import org.mockito.Mock;
76
import org.mockito.MockitoAnnotations;
87
import org.testng.annotations.BeforeMethod;
98
import org.testng.annotations.Test;
109

1110
import java.time.temporal.ChronoUnit;
11+
import java.util.ArrayList;
12+
import java.util.List;
1213
import java.util.concurrent.Callable;
1314

1415
import static org.assertj.core.api.Assertions.assertThat;
@@ -197,20 +198,18 @@ public void verifyOnFailureListener_populatesException() {
197198

198199
@Test
199200
public void verifyOnListener_resultHasTypeOfCallExecutor() {
200-
when(dummyMock.callableCallThis())
201-
.thenReturn("success!");
202-
203-
RetryListener<String> listener = status -> {
204-
dummyMock.listenersCallThis();
205-
assertThat(status.getResult()).isInstanceOf(String.class);
206-
};
201+
List<String> methodCalls = new ArrayList<>();
207202
executor
208-
.onSuccess(listener)
209-
.onCompletion(listener)
210-
.execute(callable);
211-
212-
// ensure both listeners are called
213-
verify(dummyMock, timeout(1000).times(2)).listenersCallThis();
203+
.onSuccess(status -> {
204+
methodCalls.add("onSuccess");
205+
assertThat(status.getResult()).isInstanceOf(String.class);
206+
})
207+
.onCompletion(status -> {
208+
methodCalls.add("onCompletion");
209+
assertThat(status.getResult()).isInstanceOf(String.class);
210+
})
211+
.execute(() -> "");
212+
assertThat(methodCalls).contains("onSuccess", "onCompletion");
214213
}
215214

216215
private class DummyMock {

0 commit comments

Comments
 (0)