elharo commented on code in PR #422:
URL: https://github.com/apache/maven-help-plugin/pull/422#discussion_r3804804553
##########
src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java:
##########
@@ -213,6 +215,13 @@ private static void cleanModel(Model pom) {
pom.setProperties(properties);
}
+ static String encodingOrDefault(String encoding) {
+ if (encoding == null || encoding.isEmpty()) {
+ return Charset.defaultCharset().name();
Review Comment:
why use the default encoding instead of UTF-8?
##########
src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.help;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+class EffectivePomMojoTest {
+
+ @Test
+ void encodingFallbackNeverNull() {
+ String fromNull = EffectivePomMojo.encodingOrDefault(null);
+ assertNotNull(fromNull);
+ assertFalse(fromNull.isEmpty());
+
+ String fromBlank = EffectivePomMojo.encodingOrDefault("");
Review Comment:
This is two different tests
##########
src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java:
##########
@@ -107,7 +108,8 @@ public void execute() throws MojoExecutionException {
}
StringWriter w = new StringWriter();
- String encoding = output != null ?
project.getModel().getModelEncoding() : System.getProperty("file.encoding");
+ String encoding = encodingOrDefault(
+ output != null ? project.getModel().getModelEncoding() :
System.getProperty("file.encoding"));
Review Comment:
This should be split into multiple statements for clarity
--
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]