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

panjuan 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 5220ef0  Split multi test cases into diff asserttion methods in 
DriverStateContextTest (#8244)
5220ef0 is described below

commit 5220ef05a9a5d5fddf9d952b44df59aad10db8d3
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Nov 20 17:33:45 2020 +0800

    Split multi test cases into diff asserttion methods in 
DriverStateContextTest (#8244)
---
 .../internal/state/DriverStateContextTest.java     | 37 ++++++++++++++--------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/DriverStateContextTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/DriverStateContextTest.java
index f01416e..09cc11c 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/DriverStateContextTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/DriverStateContextTest.java
@@ -25,30 +25,39 @@ import org.apache.shardingsphere.infra.state.StateEvent;
 import org.apache.shardingsphere.infra.state.StateType;
 import org.apache.shardingsphere.transaction.context.TransactionContexts;
 import org.apache.shardingsphere.transaction.core.TransactionType;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.junit.Assert.assertThat;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
 
 import javax.sql.DataSource;
 import java.sql.Connection;
 import java.util.Collections;
 
-public class DriverStateContextTest {
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+
+public final class DriverStateContextTest {
+    
+    @Before
+    @After
+    public void reset() {
+        StateContext.switchState(new StateEvent(StateType.OK, true));
+    }
     
     @Test
-    public void assertGetConnection() {
-        Connection actual1 = DriverStateContext.getConnection(
+    public void assertGetConnectionWithOkState() {
+        Connection actual = DriverStateContext.getConnection(
                 Collections.singletonMap("ds", mock(DataSource.class, 
RETURNS_DEEP_STUBS)), mock(MetaDataContexts.class), 
mock(TransactionContexts.class, RETURNS_DEEP_STUBS), TransactionType.LOCAL);
-        assertThat(actual1, instanceOf(ShardingSphereConnection.class));
+        assertThat(actual, instanceOf(ShardingSphereConnection.class));
+    }
+    
+    @Test
+    public void assertGetConnectionWithCircuitBreakState() {
         StateContext.switchState(new StateEvent(StateType.CIRCUIT_BREAK, 
true));
-        Connection actual2 = DriverStateContext.getConnection(
-                Collections.emptyMap(), mock(MetaDataContexts.class), 
mock(TransactionContexts.class, RETURNS_DEEP_STUBS), TransactionType.LOCAL);
-        assertThat(actual2, instanceOf(CircuitBreakerConnection.class));
-        StateContext.switchState(new StateEvent(StateType.CIRCUIT_BREAK, 
false));
-        Connection actual3 = DriverStateContext.getConnection(
+        Connection actual = DriverStateContext.getConnection(
                 Collections.singletonMap("ds", mock(DataSource.class, 
RETURNS_DEEP_STUBS)), mock(MetaDataContexts.class), 
mock(TransactionContexts.class, RETURNS_DEEP_STUBS), TransactionType.LOCAL);
-        assertThat(actual3, instanceOf(ShardingSphereConnection.class));
+        assertThat(actual, instanceOf(CircuitBreakerConnection.class));
     }
 }

Reply via email to