-
Notifications
You must be signed in to change notification settings - Fork 3
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 #7 from jamezp/issue5
[5] Only allow injection of the UriBuilder as a method parameter or c…
- Loading branch information
Showing
4 changed files
with
40 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
...on/src/main/java/dev/resteasy/junit/extension/extensions/UriBuilderParameterResolver.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 @@ | ||
/* | ||
* Copyright The RESTEasy Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package dev.resteasy.junit.extension.extensions; | ||
|
||
import jakarta.ws.rs.core.UriBuilder; | ||
|
||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.api.extension.ParameterContext; | ||
import org.junit.jupiter.api.extension.ParameterResolutionException; | ||
import org.junit.jupiter.api.extension.ParameterResolver; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">James R. Perkins</a> | ||
*/ | ||
public class UriBuilderParameterResolver implements ParameterResolver { | ||
@Override | ||
public boolean supportsParameter(final ParameterContext parameterContext, final ExtensionContext extensionContext) | ||
throws ParameterResolutionException { | ||
return UriBuilder.class.isAssignableFrom(parameterContext.getParameter().getType()); | ||
} | ||
|
||
@Override | ||
public Object resolveParameter(final ParameterContext parameterContext, final ExtensionContext extensionContext) | ||
throws ParameterResolutionException { | ||
if (UriBuilder.class.isAssignableFrom(parameterContext.getParameter().getType())) { | ||
return InstanceManager.getInstance(extensionContext) | ||
.map(im -> im.instance().configuration().baseUriBuilder()) | ||
.orElseThrow(() -> new ParameterResolutionException("Failed to lookup URI builder instance.")); | ||
} | ||
throw new ParameterResolutionException(String.format("Type %s is not assignable to %s", | ||
parameterContext.getParameter().getType().getName(), UriBuilder.class.getName())); | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
extension/src/main/java/dev/resteasy/junit/extension/extensions/UriBuilderProducer.java
This file was deleted.
Oops, something went wrong.