Created
July 14, 2022 22:36
-
-
Save beyondxscratch/e312d37965f865972da845cd85d794d4 to your computer and use it in GitHub Desktop.
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
class BookmarkResolver implements ParameterResolver { | |
@Override | |
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { | |
// Le type d'arguments concernés par le resolver | |
return parameterContext.getParameter().getType() == Bookmark.class; | |
} | |
@Override | |
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { | |
if (parameterContext.isAnnotated(Article.class)) { | |
return Bookmark.create("https://www.programmez.com/article/1", "Cool article"); | |
} | |
return Bookmark.create("https://www.programmez.com", "Programmez Magazine"); | |
} | |
} | |
@ExtendWith(BookmarkResolver.class) | |
class BookmarkTest { | |
@BeforeEach | |
void set_up(Bookmark bookmark) { | |
// Bookmark injecté : https://www.programmez.com | |
} | |
@Test | |
void a_test(@Article Bookmark bookmark) { | |
// Bookmark injecté : https://www.programmez.com/article/1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment