From 70b65bcafba02a06ec1aa959042c53a130fbdba2 Mon Sep 17 00:00:00 2001 From: vil02 Date: Fri, 13 Oct 2023 16:58:22 +0200 Subject: [PATCH] Make some Java classes proper utilities Made the design cleaner by marking Java classes as `final` and explicitly declaring their default constructors as `private`. This change makes the code coverage reports more accurate. Closes #4921. --- changelog.md | 1 + .../ballerina/stdlib/sql/utils/ProcedureCallResultUtils.java | 4 ++-- .../io/ballerina/stdlib/sql/utils/RecordIteratorUtils.java | 4 ++-- native/src/test/java/io/ballerina/stdlib/sql/TestUtils.java | 4 +++- .../io/ballerina/stdlib/sql/testutils/nativeimpl/Exec.java | 4 +++- .../ballerina/stdlib/sql/testutils/nativeimpl/ExitCode.java | 4 +++- .../stdlib/sql/testutils/nativeimpl/WaitForExit.java | 4 +++- .../java/io/ballerina/stdlib/sql/testutils/utils/OSUtils.java | 4 +++- 8 files changed, 20 insertions(+), 9 deletions(-) diff --git a/changelog.md b/changelog.md index 58c29783..32eee4e9 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - [Support retrieval of enum types](https://github.com/ballerina-platform/ballerina-standard-library/issues/4588) +- [Make some of the Java classes proper utility classes](https://github.com/ballerina-platform/ballerina-standard-library/issues/4921) ## [1.9.0] - 2023-06-01 diff --git a/native/src/main/java/io/ballerina/stdlib/sql/utils/ProcedureCallResultUtils.java b/native/src/main/java/io/ballerina/stdlib/sql/utils/ProcedureCallResultUtils.java index 6d4b6012..315ef510 100644 --- a/native/src/main/java/io/ballerina/stdlib/sql/utils/ProcedureCallResultUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/sql/utils/ProcedureCallResultUtils.java @@ -51,8 +51,8 @@ /** * This class provides functionality for the `ProcedureCallResult` to iterate through the sql result sets. */ -public class ProcedureCallResultUtils { - public ProcedureCallResultUtils() { +public final class ProcedureCallResultUtils { + private ProcedureCallResultUtils() { } public static Object getNextQueryResult(BObject procedureCallResult) { diff --git a/native/src/main/java/io/ballerina/stdlib/sql/utils/RecordIteratorUtils.java b/native/src/main/java/io/ballerina/stdlib/sql/utils/RecordIteratorUtils.java index dc427664..1942b70b 100644 --- a/native/src/main/java/io/ballerina/stdlib/sql/utils/RecordIteratorUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/sql/utils/RecordIteratorUtils.java @@ -36,8 +36,8 @@ * * @since 1.2.0 */ -public class RecordIteratorUtils { - public RecordIteratorUtils() { +public final class RecordIteratorUtils { + private RecordIteratorUtils() { } public static Object nextResult(BObject recordIterator) { diff --git a/native/src/test/java/io/ballerina/stdlib/sql/TestUtils.java b/native/src/test/java/io/ballerina/stdlib/sql/TestUtils.java index 1eedca47..34735d6c 100644 --- a/native/src/test/java/io/ballerina/stdlib/sql/TestUtils.java +++ b/native/src/test/java/io/ballerina/stdlib/sql/TestUtils.java @@ -73,7 +73,9 @@ /** * TestUtils class for testing ballerina native classes/methods. */ -public class TestUtils { +public final class TestUtils { + + private TestUtils() {} /** * ExtendedColumnDefinition Class for test utils. diff --git a/test-utils/src/main/java/io/ballerina/stdlib/sql/testutils/nativeimpl/Exec.java b/test-utils/src/main/java/io/ballerina/stdlib/sql/testutils/nativeimpl/Exec.java index 56d97902..b08a79d3 100644 --- a/test-utils/src/main/java/io/ballerina/stdlib/sql/testutils/nativeimpl/Exec.java +++ b/test-utils/src/main/java/io/ballerina/stdlib/sql/testutils/nativeimpl/Exec.java @@ -36,7 +36,9 @@ * * @since 0.6.0 */ -public class Exec { +public final class Exec { + + private Exec() {} public static Object exec(BString command, BMap env, Object dir, BString[] args) { List commandList = new ArrayList<>(); diff --git a/test-utils/src/main/java/io/ballerina/stdlib/sql/testutils/nativeimpl/ExitCode.java b/test-utils/src/main/java/io/ballerina/stdlib/sql/testutils/nativeimpl/ExitCode.java index 689a9594..350aebee 100644 --- a/test-utils/src/main/java/io/ballerina/stdlib/sql/testutils/nativeimpl/ExitCode.java +++ b/test-utils/src/main/java/io/ballerina/stdlib/sql/testutils/nativeimpl/ExitCode.java @@ -27,7 +27,9 @@ * * @since 0.6.0 */ -public class ExitCode { +public final class ExitCode { + + private ExitCode() {} public static Object exitCode(BObject objVal) { Process process = OSUtils.processFromObject(objVal); diff --git a/test-utils/src/main/java/io/ballerina/stdlib/sql/testutils/nativeimpl/WaitForExit.java b/test-utils/src/main/java/io/ballerina/stdlib/sql/testutils/nativeimpl/WaitForExit.java index 3329c99a..7c9c8fb1 100644 --- a/test-utils/src/main/java/io/ballerina/stdlib/sql/testutils/nativeimpl/WaitForExit.java +++ b/test-utils/src/main/java/io/ballerina/stdlib/sql/testutils/nativeimpl/WaitForExit.java @@ -27,7 +27,9 @@ * * @since 0.6.0 */ -public class WaitForExit { +public final class WaitForExit { + + private WaitForExit() {} public static Object waitForExit(BObject objVal) { Process process = OSUtils.processFromObject(objVal); diff --git a/test-utils/src/main/java/io/ballerina/stdlib/sql/testutils/utils/OSUtils.java b/test-utils/src/main/java/io/ballerina/stdlib/sql/testutils/utils/OSUtils.java index aea008f9..4df69838 100644 --- a/test-utils/src/main/java/io/ballerina/stdlib/sql/testutils/utils/OSUtils.java +++ b/test-utils/src/main/java/io/ballerina/stdlib/sql/testutils/utils/OSUtils.java @@ -30,7 +30,9 @@ /** * @since 0.6.0 */ -public class OSUtils { +public final class OSUtils { + + private OSUtils() {} private static final BString UNKNOWN_MESSAGE = StringUtils.fromString("Unknown Error");