vlsi commented on PR #133: URL: https://github.com/apache/xalan-java/pull/133#issuecomment-1836426048
> I see that you have not identified any real problems with this PR, @kriegaex , please read my first comment: https://github.com/apache/xalan-java/pull/133#issuecomment-1833170148 I say: "This looks great to me". I was OK merging this from the beginning. ---- > Vladimir: In the current case, the same test coverage can be achieved without Mockito (see below) > Alexander: Not true @kriegaex , here's a diff that replaces Mockito with a line of Java code keeping the same test coverage. Am I missing something? Would you please elaborate on why do you think my statement is not true? Sure I read all your comments. This does not introduce new IO operations, and it tests the same things. It just uses regular Java method overrides instead of Mockito, but all-in-all it yields the same test coverage yet it does not depend on Mockito, and Mockito-less approach is easier to maintain overall. Of course, I do not claim it is the only way to go, however, as I claimed "In the current case, the same test coverage can be achieved without Mockito (see below)", please acknowledge that "In the current case, the same test coverage can be achieved without Mockito (see below)" ```diff diff --git a/xalan/src/main/java/org/apache/xalan/Version.java b/xalan/src/main/java/org/apache/xalan/Version.java index 4ca166919..0d29483a1 100644 --- a/xalan/src/main/java/org/apache/xalan/Version.java +++ b/xalan/src/main/java/org/apache/xalan/Version.java @@ -49,11 +49,11 @@ public class Version { private static boolean snapshot; static { - parseVersionNumber(readVersionNumber()); + parseVersionNumber(readVersionNumber(getPropertiesStream())); } - static String readVersionNumber() { - try (InputStream fromResource = getPropertiesStream()) { + static String readVersionNumber(InputStream versionStream) { + try (InputStream fromResource = versionStream) { Properties properties = new Properties(); if (fromResource != null) { properties.load(fromResource); ``` ```diff diff --git a/xalan/src/test/java/org/apache/xalan/VersionTest.java b/xalan/src/test/java/org/apache/xalan/VersionTest.java index 6cec8447d..3a004f5f8 100644 --- a/xalan/src/test/java/org/apache/xalan/VersionTest.java +++ b/xalan/src/test/java/org/apache/xalan/VersionTest.java @@ -21,10 +21,10 @@ 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.io.IOException; +import java.io.InputStream; import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -34,12 +34,7 @@ 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()); - } + assertEquals(version, Version.readVersionNumber(new ByteArrayInputStream(properties.getBytes()))); } private static Stream<Arguments> testReadPropertiesArgs() { @@ -54,12 +49,17 @@ public class VersionTest { @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()); - } + assertEquals( + "0.0.0", + Version.readVersionNumber( + new InputStream() { + @Override + public int read() throws IOException { + throw new IOException("IO exception to test how version parser behaves to IO Exceptions"); + } + } + ) + ); } ``` -- 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