From 9f3bbabe2cda1a17ac5544d6c73923a852fc7ffc Mon Sep 17 00:00:00 2001 From: Robert Faust Date: Mon, 3 Jun 2024 22:06:42 -0500 Subject: [PATCH] Fixing SonarLint recommendations --- .../java/com/labelzoom/moca/LegacyMocaConnection.java | 2 +- src/main/java/com/labelzoom/moca/MocaConnection.java | 2 -- src/main/java/com/labelzoom/moca/MocaResultSet.java | 2 +- .../moca/exceptions/MocaExceptionFactory.java | 2 ++ .../com/labelzoom/moca/HttpMocaConnectionTest.java | 8 ++++---- .../com/labelzoom/moca/LegacyMocaConnectionTest.java | 10 +++++----- src/test/java/com/labelzoom/moca/MocaRequestTest.java | 6 +++--- .../java/com/labelzoom/moca/MocaResultSetTest.java | 6 +++--- src/test/java/com/labelzoom/moca/MocaTester.java | 2 +- src/test/java/com/labelzoom/moca/MocaTests.java | 10 +++++----- 10 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/labelzoom/moca/LegacyMocaConnection.java b/src/main/java/com/labelzoom/moca/LegacyMocaConnection.java index 296e2d4..7ec51fe 100644 --- a/src/main/java/com/labelzoom/moca/LegacyMocaConnection.java +++ b/src/main/java/com/labelzoom/moca/LegacyMocaConnection.java @@ -34,7 +34,7 @@ protected MocaResponse send(String command) throws MocaException final byte[] data = new byte[socket.getInputStream().available()]; final int bytes = socket.getInputStream().read(data, 0, data.length); - final String responseData = new String(data, 0 , bytes, "ASCII"); + final String responseData = new String(data, 0 , bytes, StandardCharsets.US_ASCII); return MocaResponse.fromLegacy(responseData); } catch (final IOException | InterruptedException ex) diff --git a/src/main/java/com/labelzoom/moca/MocaConnection.java b/src/main/java/com/labelzoom/moca/MocaConnection.java index 6e6c6f1..36295a1 100644 --- a/src/main/java/com/labelzoom/moca/MocaConnection.java +++ b/src/main/java/com/labelzoom/moca/MocaConnection.java @@ -2,8 +2,6 @@ import com.labelzoom.moca.exceptions.MocaException; -import java.io.Closeable; -import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Map; diff --git a/src/main/java/com/labelzoom/moca/MocaResultSet.java b/src/main/java/com/labelzoom/moca/MocaResultSet.java index 61765d6..9495be0 100644 --- a/src/main/java/com/labelzoom/moca/MocaResultSet.java +++ b/src/main/java/com/labelzoom/moca/MocaResultSet.java @@ -17,7 +17,7 @@ class MocaResultSet extends AbstractResultSet private int rowNum = -1; - public MocaResultSet(final Node mocaResults) throws SQLException + public MocaResultSet(final Node mocaResults) { final Node metadata = ((Element)mocaResults).getElementsByTagName("metadata").item(0); this.metadata = new MocaResultSetMetaData(metadata); diff --git a/src/main/java/com/labelzoom/moca/exceptions/MocaExceptionFactory.java b/src/main/java/com/labelzoom/moca/exceptions/MocaExceptionFactory.java index a104493..0fe56f2 100644 --- a/src/main/java/com/labelzoom/moca/exceptions/MocaExceptionFactory.java +++ b/src/main/java/com/labelzoom/moca/exceptions/MocaExceptionFactory.java @@ -4,6 +4,8 @@ public class MocaExceptionFactory { + private MocaExceptionFactory() {} + public static MocaException produce(final String message, final int code) { return produce(message, code, null); } public static MocaException produce(final String message, final int code, final ResultSet results) { diff --git a/src/test/java/com/labelzoom/moca/HttpMocaConnectionTest.java b/src/test/java/com/labelzoom/moca/HttpMocaConnectionTest.java index 8f60298..b98730d 100644 --- a/src/test/java/com/labelzoom/moca/HttpMocaConnectionTest.java +++ b/src/test/java/com/labelzoom/moca/HttpMocaConnectionTest.java @@ -17,7 +17,7 @@ import static org.junit.jupiter.api.Assertions.*; -public class HttpMocaConnectionTest +class HttpMocaConnectionTest { private final String url = System.getenv("MOCA_URL"); private final String userId = System.getenv("MOCA_USER"); @@ -32,7 +32,7 @@ public void testEnvironmentSetup() } @Test - public void testHttpMocaConnection() throws MocaException, IOException, SQLException + void testHttpMocaConnection() throws MocaException, SQLException { try (final MocaConnection conn = new HttpMocaConnection(url, userId, password); final ResultSet res = conn.execute("publish data where message = 'My name is Rob'")) @@ -43,7 +43,7 @@ public void testHttpMocaConnection() throws MocaException, IOException, SQLExcep } @Test - public void testMultipleRows() throws MocaException, IOException, SQLException + void testMultipleRows() throws MocaException, SQLException { try (final MocaConnection conn = new HttpMocaConnection(url, userId, password); final ResultSet res = conn.execute("publish data where a = 1 and b = 2 & publish data where a = 3 and b = 4")) @@ -56,7 +56,7 @@ public void testMultipleRows() throws MocaException, IOException, SQLException } @Test - public void testRawHttp() throws IOException + void testRawHttp() throws IOException { final int TIMEOUT = 5000; final String command = "get encryption information"; diff --git a/src/test/java/com/labelzoom/moca/LegacyMocaConnectionTest.java b/src/test/java/com/labelzoom/moca/LegacyMocaConnectionTest.java index ae374df..1c14341 100644 --- a/src/test/java/com/labelzoom/moca/LegacyMocaConnectionTest.java +++ b/src/test/java/com/labelzoom/moca/LegacyMocaConnectionTest.java @@ -26,7 +26,7 @@ * TODO: LegacyMocaConnection needs some work */ @Disabled -public class LegacyMocaConnectionTest +class LegacyMocaConnectionTest { private final String host = System.getenv("MOCA_HOST"); private final int port = Integer.parseInt(System.getenv("MOCA_PORT")); @@ -42,7 +42,7 @@ public void testEnvironmentSetup() } @Test - public void testReadersAndWriters() throws IOException, InterruptedException + void testReadersAndWriters() throws IOException { try (final Socket socket = new Socket(host, port)) { @@ -68,7 +68,7 @@ public void testReadersAndWriters() throws IOException, InterruptedException } @Test - public void testRawV103() throws IOException, InterruptedException + void testRawV103() throws IOException, InterruptedException { try (final Socket socket = new Socket(host, port)) { @@ -88,7 +88,7 @@ public void testRawV103() throws IOException, InterruptedException } @Test - public void testRawV104() throws IOException, InterruptedException + void testRawV104() throws IOException, InterruptedException { try (final Socket socket = new Socket(host, port)) { @@ -108,7 +108,7 @@ public void testRawV104() throws IOException, InterruptedException } @Test - public void testLegacyMocaConnection() throws MocaException + void testLegacyMocaConnection() throws MocaException { try (final MocaConnection conn = new LegacyMocaConnection(host, port, userId, password); final ResultSet res = conn.execute("create policy where polcod = 'LEGACY-MOCA-CLIENT' and polvar = 'LEGACY-MOCA-CLIENT' and polval = 'LEGACY-MOCA-CLIENT' and rtstr1 = 'success'")) diff --git a/src/test/java/com/labelzoom/moca/MocaRequestTest.java b/src/test/java/com/labelzoom/moca/MocaRequestTest.java index fdfa516..397f027 100644 --- a/src/test/java/com/labelzoom/moca/MocaRequestTest.java +++ b/src/test/java/com/labelzoom/moca/MocaRequestTest.java @@ -2,16 +2,16 @@ import org.junit.jupiter.api.Test; -public class MocaRequestTest +class MocaRequestTest { @Test - public void testMocaResultXml() + void testMocaResultXml() { final MocaRequest request = MocaRequestBuilder.http().command("login user where usr_id = 'RFAUST' and usr_paswd = 'RFaust123'"); System.out.println(request.toString()); } @Test - public void testMocaResultLegacy() + void testMocaResultLegacy() { final MocaRequest request = MocaRequestBuilder.legacy().command("login user where usr_id = 'RFAUST' and usr_paswd = 'RFaust123'"); System.out.println(request.toString()); diff --git a/src/test/java/com/labelzoom/moca/MocaResultSetTest.java b/src/test/java/com/labelzoom/moca/MocaResultSetTest.java index 172a54a..66943e0 100644 --- a/src/test/java/com/labelzoom/moca/MocaResultSetTest.java +++ b/src/test/java/com/labelzoom/moca/MocaResultSetTest.java @@ -9,10 +9,10 @@ import static org.junit.jupiter.api.Assertions.*; -public class MocaResultSetTest extends MocaTester +class MocaResultSetTest extends MocaTester { @Test - public void testIteration() throws MocaException, SQLException + void testIteration() throws MocaException, SQLException { try (final ResultSet res = conn.execute("publish data where a = 1 and b = 2 & publish data where a = 3 and b = 4")) { @@ -55,7 +55,7 @@ public void testIteration() throws MocaException, SQLException } @Test - public void testDataTypes() throws MocaException, SQLException + void testDataTypes() throws MocaException, SQLException { try (final ResultSet res = conn.execute("publish data" + " where intcol = 82332" + diff --git a/src/test/java/com/labelzoom/moca/MocaTester.java b/src/test/java/com/labelzoom/moca/MocaTester.java index 6b74153..01c83c4 100644 --- a/src/test/java/com/labelzoom/moca/MocaTester.java +++ b/src/test/java/com/labelzoom/moca/MocaTester.java @@ -22,7 +22,7 @@ protected void setUp() throws Exception } @AfterEach - protected void tearDown() throws Exception + protected void tearDown() { conn.close(); } diff --git a/src/test/java/com/labelzoom/moca/MocaTests.java b/src/test/java/com/labelzoom/moca/MocaTests.java index c13e28c..e21e86c 100644 --- a/src/test/java/com/labelzoom/moca/MocaTests.java +++ b/src/test/java/com/labelzoom/moca/MocaTests.java @@ -8,10 +8,10 @@ import static org.junit.jupiter.api.Assertions.*; -public class MocaTests extends MocaTester +class MocaTests extends MocaTester { @Test - public void testSyntaxError() + void testSyntaxError() { final MocaException ex = assertThrows(MocaException.class, () -> conn.execute("publish data a = 1")); System.err.println(ex.getMessage()); @@ -19,7 +19,7 @@ public void testSyntaxError() } @Test - public void testCommandNotFound() + void testCommandNotFound() { final MocaException ex = assertThrows(MocaException.class, () -> conn.execute("this command doesnt exist")); System.err.println(ex.getMessage()); @@ -27,7 +27,7 @@ public void testCommandNotFound() } @Test - public void testNoRowsAffected() throws SQLException + void testNoRowsAffected() throws SQLException { final MocaException ex = assertThrows(MocaException.class, () -> conn.execute("[select polcod, polvar, polval from poldat where 1 = 2]")); System.err.println(ex.getMessage()); @@ -40,7 +40,7 @@ public void testNoRowsAffected() throws SQLException } @Test - public void testInvalidColumn() throws SQLException + void testInvalidColumn() { final MocaException ex = assertThrows(MocaException.class, () -> conn.execute("[select qw9io0ejoower from poldat where 1 = 2]")); System.err.println(ex.getMessage());