-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34239 from mkouba/componenttest-interceptor-methods
QuarkusComponentTest: convenient way of mocking interceptors
- Loading branch information
Showing
6 changed files
with
447 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...rk/junit5-component/src/main/java/io/quarkus/test/component/InterceptorMethodCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.quarkus.test.component; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
import io.quarkus.arc.InterceptorCreator; | ||
import io.quarkus.arc.SyntheticCreationalContext; | ||
|
||
public class InterceptorMethodCreator implements InterceptorCreator { | ||
|
||
static final String CREATE_KEY = "createKey"; | ||
|
||
private static final Map<String, Function<SyntheticCreationalContext<?>, InterceptFunction>> createFunctions = new HashMap<>(); | ||
|
||
@Override | ||
public InterceptFunction create(SyntheticCreationalContext<Object> context) { | ||
Object createKey = context.getParams().get(CREATE_KEY); | ||
if (createKey != null) { | ||
Function<SyntheticCreationalContext<?>, InterceptFunction> createFun = createFunctions.get(createKey); | ||
if (createFun != null) { | ||
return createFun.apply(context); | ||
} | ||
} | ||
throw new IllegalStateException("Create function not found: " + createKey); | ||
} | ||
|
||
static void registerCreate(String key, Function<SyntheticCreationalContext<?>, InterceptFunction> create) { | ||
createFunctions.put(key, create); | ||
} | ||
|
||
static void clear() { | ||
createFunctions.clear(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.