|
3 | 3 | import static org.junit.Assert.*; |
4 | 4 | import static org.mockito.Mockito.*; |
5 | 5 |
|
| 6 | +import com.google.common.reflect.TypeToken; |
6 | 7 | import io.temporal.client.ActivityExecutionDescription; |
7 | 8 | import io.temporal.client.ActivityFailedException; |
8 | 9 | import io.temporal.client.ActivityHandle; |
9 | 10 | import io.temporal.client.UntypedActivityHandle; |
10 | 11 | import io.temporal.common.interceptors.ActivityClientCallsInterceptor; |
11 | 12 | import io.temporal.common.interceptors.ActivityClientCallsInterceptor.*; |
| 13 | +import java.lang.reflect.Type; |
| 14 | +import java.util.Collections; |
| 15 | +import java.util.List; |
12 | 16 | import java.util.concurrent.CompletableFuture; |
13 | 17 | import java.util.concurrent.TimeUnit; |
14 | 18 | import org.junit.Before; |
@@ -49,7 +53,7 @@ public void testGetResultAsync() throws Exception { |
49 | 53 | } |
50 | 54 |
|
51 | 55 | @Test |
52 | | - public void testDescribeNoOptions() { |
| 56 | + public void testDescribeNoToken() { |
53 | 57 | ActivityExecutionDescription desc = mock(ActivityExecutionDescription.class); |
54 | 58 | DescribeActivityOutput output = new DescribeActivityOutput(desc); |
55 | 59 | when(interceptor.describeActivity(any(DescribeActivityInput.class))).thenReturn(output); |
@@ -121,14 +125,18 @@ public void testFromUntypedWrapsHandle() throws ActivityFailedException { |
121 | 125 | @SuppressWarnings("unchecked") |
122 | 126 | public void testFromUntypedWithExplicitTypePassesTypeToInterceptor() |
123 | 127 | throws ActivityFailedException { |
124 | | - GetActivityResultOutput<String> output = mock(GetActivityResultOutput.class); |
125 | | - when(output.getResult()).thenReturn("generic-result"); |
| 128 | + // explicitType is a parameterized List<String> — distinct from List.class — so the verify |
| 129 | + // below can only pass if the implementation forwards the Type arg, not the Class arg. |
| 130 | + Type explicitType = new TypeToken<List<String>>() {}.getType(); |
| 131 | + GetActivityResultOutput<List<String>> output = mock(GetActivityResultOutput.class); |
| 132 | + when(output.getResult()).thenReturn(Collections.singletonList("item")); |
126 | 133 | when(interceptor.getActivityResult(any(GetActivityResultInput.class))).thenReturn(output); |
127 | 134 |
|
128 | | - java.lang.reflect.Type explicitType = String.class; |
129 | 135 | UntypedActivityHandle untyped = new ActivityHandleImpl("id", "run", interceptor); |
130 | | - ActivityHandle<String> typed = ActivityHandle.fromUntyped(untyped, String.class, explicitType); |
131 | | - assertEquals("generic-result", typed.getResult()); |
| 136 | + ActivityHandle<List<String>> typed = |
| 137 | + ActivityHandle.fromUntyped( |
| 138 | + untyped, (Class<List<String>>) (Class<?>) List.class, explicitType); |
| 139 | + typed.getResult(); |
132 | 140 | verify(interceptor).getActivityResult(argThat(i -> explicitType.equals(i.getResultType()))); |
133 | 141 | } |
134 | 142 |
|
@@ -199,7 +207,7 @@ public void testGetResultAsyncTimeoutSuccessPopulatesCache() throws Exception { |
199 | 207 |
|
200 | 208 | @Test |
201 | 209 | @SuppressWarnings("unchecked") |
202 | | - public void testGetResultAsyncWrapsActivityFailedExceptionInRuntimeException() throws Exception { |
| 210 | + public void testGetResultAsyncPropagatesActivityFailedExceptionAsCause() throws Exception { |
203 | 211 | ActivityFailedException failure = |
204 | 212 | new ActivityFailedException( |
205 | 213 | "activity failed", "id", "run", new RuntimeException("root cause")); |
|
0 commit comments