slawekjaranowski commented on code in PR #716:
URL:
https://github.com/apache/maven-checkstyle-plugin/pull/716#discussion_r4267252483
##########
src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojoTest.java:
##########
@@ -132,4 +137,35 @@ public void
testPlainOutputFile(CheckstyleViolationCheckMojo mojo) throws Except
public void testNoFail(CheckstyleViolationCheckMojo mojo) throws Exception
{
mojo.execute();
}
+
+ @InjectMojo(goal = "check", pom =
"src/test/resources/plugin-configs/check-plugin-config.xml")
+ @MojoParameter(name = "outputFile", value =
"src/test/resources/plugin-configs/check-plugin-warning-output.xml")
+ @MojoParameter(name = "skipExec", value = "true")
+ @MojoParameter(name = "failOnViolation", value = "false")
+ @MojoParameter(name = "violationSeverity", value = "error")
+ @MojoParameter(name = "logViolationsToConsole", value = "true")
+ @Test
+ public void testWarningsAreLoggedWhenSeverityIsError(
+ CheckstyleViolationCheckMojo mojo) throws Exception {
+ List<String> loggedMessages = new ArrayList<>();
+ Log log = (Log) Proxy.newProxyInstance(
+ Log.class.getClassLoader(),
+ new Class<?>[] {Log.class},
+ (proxy, method, args) -> {
+ if (method.getName().startsWith("is") &&
method.getName().endsWith("Enabled")) {
+ return true;
+ }
+ if (args != null && args.length > 0 && args[0] != null) {
+ loggedMessages.add(String.valueOf(args[0]));
+ }
+ return null;
+ });
Review Comment:
Instead of it you can inject `Log` in test and simply use moclkito to verify
actions on it
https://maven.apache.org/plugin-testing/maven-plugin-testing-harness/examples/complex-mojo-parameters.html#plugin-logger
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]