vlsi commented on code in PR #133:
URL: https://github.com/apache/xalan-java/pull/133#discussion_r1411671578


##########
xalan/src/test/java/org/apache/xalan/VersionTest.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.xalan;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+
+import java.io.ByteArrayInputStream;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class VersionTest {
+
+  @ParameterizedTest(name = "{0} -> {2}")
+  @MethodSource("testReadPropertiesArgs")
+  public void testReadProperties(String ignoredName, String properties, String 
version) {
+    try (MockedStatic<Version> versionMock = Mockito.mockStatic(Version.class, 
Mockito.CALLS_REAL_METHODS)) {
+      versionMock
+        .when(Version::getPropertiesStream)
+        .thenReturn(new ByteArrayInputStream(properties.getBytes()));
+      assertEquals(version, Version.readVersionNumber());
+    }
+  }
+
+  private static Stream<Arguments> testReadPropertiesArgs() {
+    return Stream.of(
+      Arguments.of("single line without line feed", "version=1.2.3", "1.2.3"),
+      Arguments.of("single line with line feed", "version=4.5.D6-SNAPSHOT\n", 
"4.5.D6-SNAPSHOT"),
+      Arguments.of("multiple lines with version number", 
"foo=bar\nversion=7.8.9\nbaz=zot\n", "7.8.9"),
+      Arguments.of("single line without version number", "verXion=7.8.9\n", 
"0.0.0"),
+      Arguments.of("multiple lines without version number", 
"foo=bar\nverXion=7.8.9\nbaz=zot\n", "0.0.0")
+    );
+  }
+
+  @Test
+  public void testCannotReadProperties() {
+    try (MockedStatic<Version> versionMock = Mockito.mockStatic(Version.class, 
Mockito.CALLS_REAL_METHODS)) {
+      versionMock
+        .when(Version::getPropertiesStream)
+        .thenThrow(NullPointerException.class);
+      assertEquals("0.0.0", Version.readVersionNumber());

Review Comment:
   Do you expect NPE from `getPropertiesStream`? The method is a single line 
only (~`.getResourceAsStream`), and Javadoc says the method returns `null` in 
case the value is not found. Is there a real value in testing "what happens if 
getPropertiesStream throws NPE"?



-- 
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: dev-unsubscr...@xalan.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@xalan.apache.org
For additional commands, e-mail: dev-h...@xalan.apache.org

Reply via email to