Skip to content

Commit

Permalink
Fix -verbose javadoc generation.
Browse files Browse the repository at this point in the history
Signed-off-by: Sjoerd Talsma <sjoerdtalsma@users.noreply.github.com>
  • Loading branch information
sjoerdtalsma committed Oct 21, 2024
1 parent eb0965f commit 16a2d31
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2022 Talsma ICT
* Copyright 2016-2024 Talsma ICT
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,7 +46,9 @@ final class LocalizedReporter implements Reporter, Logger {

@Override
public void debug(Object key, Object... args) {
log(Diagnostic.Kind.OTHER, key, args);
if (config.verbose) {
log(Diagnostic.Kind.NOTE, key, args);
}
}

@Override
Expand Down Expand Up @@ -80,15 +82,13 @@ public String localize(Message key, Object... args) {

private Object[] localizeArgs(Object... args) {
for (int i = 0; i < args.length; i++) {
if (args[i] instanceof Message) args[i] = ((Message) args[i]).toString(locale);
if (args[i] instanceof Message) args[i] = localize((Message) args[i]);
}
return args;
}

private boolean mustPrint(Diagnostic.Kind kind) {
Diagnostic.Kind threshold = config.quiet ? Diagnostic.Kind.WARNING
: config.verbose ? Diagnostic.Kind.OTHER
: Diagnostic.Kind.NOTE;
Diagnostic.Kind threshold = config.quiet ? Diagnostic.Kind.WARNING : Diagnostic.Kind.NOTE;
return kind != null && kind.compareTo(threshold) <= 0;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2022 Talsma ICT
* Copyright 2016-2024 Talsma ICT
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,6 +29,8 @@
import javax.tools.Diagnostic;
import java.util.Locale;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -77,7 +79,7 @@ public void testDebug_when_verbose() {
config.verbose = true;
localizedReporter.debug(Message.DOCLET_COPYRIGHT, "1.2.3");

verify(mockReporter).print(eq(Diagnostic.Kind.OTHER),
verify(mockReporter).print(eq(Diagnostic.Kind.NOTE),
eq("UML Doclet (C) Copyright Talsma ICT, version: 1.2.3."));
}

Expand All @@ -87,7 +89,7 @@ public void testDebug_nl() {
config.verbose = true;
localizedReporter.debug(Message.DOCLET_COPYRIGHT, "1.2.3");

verify(mockReporter).print(eq(Diagnostic.Kind.OTHER),
verify(mockReporter).print(eq(Diagnostic.Kind.NOTE),
eq("UML Doclet (C) Copyright Talsma ICT, versie: 1.2.3."));
}

Expand All @@ -96,7 +98,7 @@ public void testDebug_inlineNonResourceMessage() {
config.verbose = true;
localizedReporter.debug("The {1} jumps over the {0}", "lazy dog", "quick brown fox");

verify(mockReporter).print(eq(Diagnostic.Kind.OTHER),
verify(mockReporter).print(eq(Diagnostic.Kind.NOTE),
eq("The quick brown fox jumps over the lazy dog"));
}

Expand Down Expand Up @@ -175,4 +177,9 @@ public void testPrint() {
eq("Test print message + element"));
}

@Test
void testLocalizeMessageParameter() {
String result = localizedReporter.localize(Message.INFO_GENERATING_FILE, Message.PLANTUML_COPYRIGHT);
assertThat(result, stringContainsInOrder("Generating", "This software uses PlantUML"));
}
}

0 comments on commit 16a2d31

Please sign in to comment.