This is an automated email from the ASF dual-hosted git repository.

zhaojinchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 0c3082a0524 Fix sonar issue of Remove this failure assertion and 
simply add the exception type to the method signature (#25825)
0c3082a0524 is described below

commit 0c3082a0524e513eeab4f699b966e55ab3129c0a
Author: Liang Zhang <[email protected]>
AuthorDate: Sun May 21 19:28:44 2023 +0800

    Fix sonar issue of Remove this failure assertion and simply add the 
exception type to the method signature (#25825)
---
 .../pipeline/core/execute/ExecuteEngineTest.java   | 22 +++++++++++---------
 .../proxy/frontend/ssl/SSLUtilsTest.java           | 24 +++++-----------------
 .../readonly/PostgreSQLSetReadOnlyTestCase.java    |  4 ----
 3 files changed, 17 insertions(+), 33 deletions(-)

diff --git 
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/execute/ExecuteEngineTest.java
 
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/execute/ExecuteEngineTest.java
index 89eb9fca42d..99aa5222e5e 100644
--- 
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/execute/ExecuteEngineTest.java
+++ 
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/execute/ExecuteEngineTest.java
@@ -25,6 +25,7 @@ import org.mockito.internal.configuration.plugins.Plugins;
 
 import java.time.Duration;
 import java.util.Arrays;
+import java.util.Optional;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
@@ -35,7 +36,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertTimeout;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -62,19 +63,20 @@ class ExecuteEngineTest {
         ExecuteCallback callback = mock(ExecuteCallback.class);
         ExecuteEngine executeEngine = 
ExecuteEngine.newCachedThreadInstance(ExecuteEngineTest.class.getSimpleName());
         Future<?> future = executeEngine.submit(lifecycleExecutor, callback);
-        Throwable actualCause = null;
+        Optional<Throwable> actualCause = 
assertTimeout(Duration.ofSeconds(30L), () -> execute(future));
+        assertTrue(actualCause.isPresent());
+        assertThat(actualCause.get(), is(expectedException));
+        shutdownAndAwaitTerminal(executeEngine);
+        verify(callback).onFailure(expectedException);
+    }
+    
+    private Optional<Throwable> execute(final Future<?> future) throws 
InterruptedException {
         try {
-            // TODO assertTimeout
             future.get();
-        } catch (final InterruptedException ex) {
-            Thread.currentThread().interrupt();
-            fail();
+            return Optional.empty();
         } catch (final ExecutionException ex) {
-            actualCause = ex.getCause();
+            return Optional.of(ex.getCause());
         }
-        assertThat(actualCause, is(expectedException));
-        shutdownAndAwaitTerminal(executeEngine);
-        verify(callback).onFailure(expectedException);
     }
     
     @SneakyThrows({ReflectiveOperationException.class, 
InterruptedException.class})
diff --git 
a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/ssl/SSLUtilsTest.java
 
b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/ssl/SSLUtilsTest.java
index 9d057ff03cd..92157e4c646 100644
--- 
a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/ssl/SSLUtilsTest.java
+++ 
b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/ssl/SSLUtilsTest.java
@@ -19,14 +19,9 @@ package org.apache.shardingsphere.proxy.frontend.ssl;
 
 import org.junit.jupiter.api.Test;
 
-import java.security.InvalidKeyException;
+import java.security.GeneralSecurityException;
 import java.security.KeyPair;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
 import java.security.SignatureException;
-import java.security.cert.CertificateException;
-import java.security.cert.CertificateExpiredException;
-import java.security.cert.CertificateNotYetValidException;
 import java.security.cert.X509Certificate;
 import java.time.Instant;
 import java.util.Date;
@@ -35,7 +30,6 @@ import java.util.concurrent.TimeUnit;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.fail;
 
 class SSLUtilsTest {
     
@@ -49,20 +43,12 @@ class SSLUtilsTest {
     }
     
     @Test
-    void assertGenerateSelfSignedX509Certificate() {
+    void assertGenerateSelfSignedX509Certificate() throws 
GeneralSecurityException {
         KeyPair keyPair = SSLUtils.generateRSAKeyPair();
         X509Certificate actual = 
SSLUtils.generateSelfSignedX509Certificate(keyPair);
-        try {
-            actual.checkValidity(new Date());
-            
actual.checkValidity(Date.from(Instant.ofEpochMilli(System.currentTimeMillis() 
+ TimeUnit.DAYS.toMillis(365 * 99))));
-        } catch (final CertificateExpiredException | 
CertificateNotYetValidException ex) {
-            fail(ex);
-        }
-        try {
-            actual.verify(keyPair.getPublic());
-        } catch (final CertificateException | NoSuchAlgorithmException | 
InvalidKeyException | NoSuchProviderException | SignatureException ex) {
-            fail(ex);
-        }
+        actual.checkValidity(new Date());
+        
actual.checkValidity(Date.from(Instant.ofEpochMilli(System.currentTimeMillis() 
+ TimeUnit.DAYS.toMillis(365 * 99))));
+        actual.verify(keyPair.getPublic());
         assertThrows(SignatureException.class, () -> 
actual.verify(SSLUtils.generateRSAKeyPair().getPublic()));
     }
 }
diff --git 
a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readonly/PostgreSQLSetReadOnlyTestCase.java
 
b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readonly/PostgreSQLSetReadOnlyTestCase.java
index cca197c8545..251868f24bb 100644
--- 
a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readonly/PostgreSQLSetReadOnlyTestCase.java
+++ 
b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/readonly/PostgreSQLSetReadOnlyTestCase.java
@@ -27,8 +27,6 @@ import javax.sql.DataSource;
 import java.sql.Connection;
 import java.sql.SQLException;
 
-import static org.junit.jupiter.api.Assertions.fail;
-
 /**
  * PostgreSQL set read only transaction integration test.
  */
@@ -55,8 +53,6 @@ public final class PostgreSQLSetReadOnlyTestCase extends 
SetReadOnlyTestCase {
             assertQueryBalance(connection2);
             executeWithLog(connection2, "update account set balance = 100 
where id = 2;");
             log.info("Using the driver of postgresql:42.4.1 expect to update 
successfully.");
-        } catch (final SQLException ex) {
-            fail("Update failed, should be successfully.");
         }
     }
 }

Reply via email to