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

sunnianjun 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 870082c8187 Refactor LogContentAssert (#32203)
870082c8187 is described below

commit 870082c81873297e4d6cd5f95dd9b7a636a152e3
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Jul 20 19:46:44 2024 +0800

    Refactor LogContentAssert (#32203)
---
 .../test/e2e/agent/file/FilePluginE2EIT.java           |  8 ++++----
 .../{ContentAssert.java => LogContentAssert.java}      | 18 +++++-------------
 .../cases/{LogTestCase.java => LogE2ETestCase.java}    |  6 +++---
 .../test/e2e/agent/file/cases/LogE2ETestCases.java     |  4 ++--
 4 files changed, 14 insertions(+), 22 deletions(-)

diff --git 
a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
 
b/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
index 44242f5a438..95ace7e314d 100644
--- 
a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
+++ 
b/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/FilePluginE2EIT.java
@@ -20,9 +20,9 @@ package org.apache.shardingsphere.test.e2e.agent.file;
 import 
org.apache.shardingsphere.test.e2e.agent.common.env.AgentE2ETestEnvironment;
 import 
org.apache.shardingsphere.test.e2e.agent.common.framework.AgentE2ETestActionExtension;
 import 
org.apache.shardingsphere.test.e2e.agent.common.framework.AgentE2ETestCaseArgumentsProvider;
-import org.apache.shardingsphere.test.e2e.agent.file.asserts.ContentAssert;
+import org.apache.shardingsphere.test.e2e.agent.file.asserts.LogContentAssert;
 import org.apache.shardingsphere.test.e2e.agent.file.cases.LogE2ETestCases;
-import org.apache.shardingsphere.test.e2e.agent.file.cases.LogTestCase;
+import org.apache.shardingsphere.test.e2e.agent.file.cases.LogE2ETestCase;
 import org.junit.jupiter.api.condition.EnabledIf;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.junit.jupiter.params.ParameterizedTest;
@@ -36,9 +36,9 @@ class FilePluginE2EIT {
     @EnabledIf("isEnabled")
     @ParameterizedTest
     @ArgumentsSource(TestCaseArgumentsProvider.class)
-    void assertWithAgent(final LogTestCase testCase) {
+    void assertWithAgent(final LogE2ETestCase testCase) {
         
assertFalse(AgentE2ETestEnvironment.getInstance().getActualLogs().isEmpty(), 
"The actual log is empty");
-        
ContentAssert.assertIs(AgentE2ETestEnvironment.getInstance().getActualLogs(), 
testCase.getLogRegex());
+        
LogContentAssert.assertIs(AgentE2ETestEnvironment.getInstance().getActualLogs(),
 testCase.getLogRegex());
     }
     
     private static boolean isEnabled() {
diff --git 
a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/asserts/ContentAssert.java
 
b/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/asserts/LogContentAssert.java
similarity index 70%
rename from 
test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/asserts/ContentAssert.java
rename to 
test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/asserts/LogContentAssert.java
index 41787214b13..e8eda6550b0 100644
--- 
a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/asserts/ContentAssert.java
+++ 
b/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/asserts/LogContentAssert.java
@@ -20,29 +20,21 @@ package 
org.apache.shardingsphere.test.e2e.agent.file.asserts;
 import java.util.Collection;
 import java.util.regex.Pattern;
 
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
- * Content assert.
+ * Log content assert.
  */
-public final class ContentAssert {
+public final class LogContentAssert {
     
     /**
      * Assertion specifies regular log content.
      *
-     * @param actualLogLines actual logs
+     * @param actualLogLines actual log lines
      * @param expectedLogRegex expected log regex
      */
     public static void assertIs(final Collection<String> actualLogLines, final 
String expectedLogRegex) {
         Pattern pattern = Pattern.compile(expectedLogRegex);
-        String actualLog = null;
-        for (String each : actualLogLines) {
-            if (pattern.matcher(each).find()) {
-                actualLog = each;
-                break;
-            }
-        }
-        assertThat(String.format("No logs matching `%s`", expectedLogRegex), 
actualLog, notNullValue());
+        assertTrue(actualLogLines.stream().anyMatch(each -> 
pattern.matcher(each).find()));
     }
 }
diff --git 
a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/cases/LogTestCase.java
 
b/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/cases/LogE2ETestCase.java
similarity index 94%
rename from 
test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/cases/LogTestCase.java
rename to 
test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/cases/LogE2ETestCase.java
index 1ec5a172d34..34329e6854f 100644
--- 
a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/cases/LogTestCase.java
+++ 
b/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/cases/LogE2ETestCase.java
@@ -27,12 +27,12 @@ import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
 
 /**
- * Log test case.
+ * Log E2E test case.
  */
+@XmlAccessorType(XmlAccessType.FIELD)
 @Getter
 @Setter
-@XmlAccessorType(XmlAccessType.FIELD)
-public final class LogTestCase implements AgentE2ETestCase {
+public final class LogE2ETestCase implements AgentE2ETestCase {
     
     @XmlAttribute(name = "log-regex")
     private String logRegex;
diff --git 
a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/cases/LogE2ETestCases.java
 
b/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/cases/LogE2ETestCases.java
index 7e4a7b94b4c..5500a1a97c5 100644
--- 
a/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/cases/LogE2ETestCases.java
+++ 
b/test/e2e/agent/plugins/logging/file/src/test/java/org/apache/shardingsphere/test/e2e/agent/file/cases/LogE2ETestCases.java
@@ -30,8 +30,8 @@ import java.util.LinkedList;
  */
 @XmlRootElement(name = "e2e-test-cases")
 @Getter
-public final class LogE2ETestCases implements AgentE2ETestCases<LogTestCase> {
+public final class LogE2ETestCases implements 
AgentE2ETestCases<LogE2ETestCase> {
     
     @XmlElement(name = "test-case")
-    private final Collection<LogTestCase> testCases = new LinkedList<>();
+    private final Collection<LogE2ETestCase> testCases = new LinkedList<>();
 }

Reply via email to