|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2024 the original author or authors. |
| 2 | + * Copyright 2002-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
43 | 43 | class AsyncExecutionInterceptorTests {
|
44 | 44 |
|
45 | 45 | @Test
|
46 |
| - public void testInvokeOnInterface() throws Throwable { |
47 |
| - AsyncExecutionInterceptor interceptor = spy( new AsyncExecutionInterceptor( null ) ); |
48 |
| - Impl impl = new Impl(); |
49 |
| - ArgumentCaptor<Class<?>> classArgumentCaptor = ArgumentCaptor.forClass( Class.class ); |
| 46 | + @SuppressWarnings("unchecked") |
| 47 | + void invokeOnInterfaceWithGeneric() throws Throwable { |
| 48 | + AsyncExecutionInterceptor interceptor = spy(new AsyncExecutionInterceptor(null)); |
| 49 | + FutureRunner impl = new FutureRunner(); |
50 | 50 | MethodInvocation mi = mock();
|
51 |
| - given( mi.getThis() ).willReturn( impl ); |
52 |
| - given( mi.getMethod() ).willReturn( I.class.getMethod( "doSomeThing" ) ); |
53 |
| - interceptor.invoke( mi ); |
54 |
| - verify( interceptor ).doSubmit( |
55 |
| - any( Callable.class ), |
56 |
| - any( AsyncTaskExecutor.class ), |
57 |
| - classArgumentCaptor.capture() |
58 |
| - ); |
59 |
| - assertThat( classArgumentCaptor.getValue() ).isEqualTo( Future.class ); |
| 51 | + given(mi.getThis()).willReturn(impl); |
| 52 | + given(mi.getMethod()).willReturn(GenericRunner.class.getMethod("run")); |
| 53 | + |
| 54 | + interceptor.invoke(mi); |
| 55 | + ArgumentCaptor<Class<?>> classArgumentCaptor = ArgumentCaptor.forClass(Class.class); |
| 56 | + verify(interceptor).doSubmit(any(Callable.class), any(AsyncTaskExecutor.class), classArgumentCaptor.capture()); |
| 57 | + assertThat(classArgumentCaptor.getValue()).isEqualTo(Future.class); |
60 | 58 | }
|
61 | 59 |
|
62 | 60 |
|
63 |
| - private interface I<O> { |
64 |
| - O doSomeThing(); |
| 61 | + interface GenericRunner<O> { |
| 62 | + |
| 63 | + O run(); |
65 | 64 | }
|
66 | 65 |
|
67 |
| - private static final class Impl implements I<Future<Void>> { |
| 66 | + static class FutureRunner implements GenericRunner<Future<Void>> { |
68 | 67 | @Override
|
69 |
| - public Future<Void> doSomeThing() { |
70 |
| - return CompletableFuture.runAsync( () -> { |
71 |
| - } ); |
| 68 | + public Future<Void> run() { |
| 69 | + return CompletableFuture.runAsync(() -> { |
| 70 | + }); |
72 | 71 | }
|
73 | 72 | }
|
74 | 73 | }
|
0 commit comments