|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2024 the original author or authors. |
|
|
|
* Copyright 2002-2025 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -43,32 +43,31 @@ import static org.mockito.Mockito.verify; |
|
|
|
class AsyncExecutionInterceptorTests { |
|
|
|
class AsyncExecutionInterceptorTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testInvokeOnInterface() throws Throwable { |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
AsyncExecutionInterceptor interceptor = spy( new AsyncExecutionInterceptor( null ) ); |
|
|
|
void invokeOnInterfaceWithGeneric() throws Throwable { |
|
|
|
Impl impl = new Impl(); |
|
|
|
AsyncExecutionInterceptor interceptor = spy(new AsyncExecutionInterceptor(null)); |
|
|
|
ArgumentCaptor<Class<?>> classArgumentCaptor = ArgumentCaptor.forClass( Class.class ); |
|
|
|
FutureRunner impl = new FutureRunner(); |
|
|
|
MethodInvocation mi = mock(); |
|
|
|
MethodInvocation mi = mock(); |
|
|
|
given( mi.getThis() ).willReturn( impl ); |
|
|
|
given(mi.getThis()).willReturn(impl); |
|
|
|
given( mi.getMethod() ).willReturn( I.class.getMethod( "doSomeThing" ) ); |
|
|
|
given(mi.getMethod()).willReturn(GenericRunner.class.getMethod("run")); |
|
|
|
interceptor.invoke( mi ); |
|
|
|
|
|
|
|
verify( interceptor ).doSubmit( |
|
|
|
interceptor.invoke(mi); |
|
|
|
any( Callable.class ), |
|
|
|
ArgumentCaptor<Class<?>> classArgumentCaptor = ArgumentCaptor.forClass(Class.class); |
|
|
|
any( AsyncTaskExecutor.class ), |
|
|
|
verify(interceptor).doSubmit(any(Callable.class), any(AsyncTaskExecutor.class), classArgumentCaptor.capture()); |
|
|
|
classArgumentCaptor.capture() |
|
|
|
assertThat(classArgumentCaptor.getValue()).isEqualTo(Future.class); |
|
|
|
); |
|
|
|
|
|
|
|
assertThat( classArgumentCaptor.getValue() ).isEqualTo( Future.class ); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private interface I<O> { |
|
|
|
interface GenericRunner<O> { |
|
|
|
O doSomeThing(); |
|
|
|
|
|
|
|
|
|
|
|
O run(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static final class Impl implements I<Future<Void>> { |
|
|
|
static class FutureRunner implements GenericRunner<Future<Void>> { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Future<Void> doSomeThing() { |
|
|
|
public Future<Void> run() { |
|
|
|
return CompletableFuture.runAsync( () -> { |
|
|
|
return CompletableFuture.runAsync(() -> { |
|
|
|
} ); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|