/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.shardingsphere.driver.governance.internal.state;

import org.apache.shardingsphere.driver.governance.internal.circuit.connection.CircuitBreakerConnection;
import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import org.apache.shardingsphere.infra.state.StateContext;
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.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 {
    
    @Test
    public void assertGetConnection() {
        Connection actual1 = 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));
        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(
                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));
    }
}

@@ -1440,24 +1440,185 @@
 actionType;%0A
+import org.junit.After;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport javax.sql.DataSource;%0Aimport java.sql.Connection;%0Aimport java.util.Collections;%0A%0A
 import stati
@@ -1700,39 +1700,16 @@
 rtThat;%0A
-import org.junit.Test;%0A
 import s
@@ -1799,133 +1799,181 @@
 k;%0A%0A
-import javax.sql.DataSource;%0Aimport java.sql.Connection;%0Aimport java.util.Collections;%0A%0Apublic class DriverStateContextTest %7B
+public final class DriverStateContextTest %7B%0A    %0A    @Before%0A    @After%0A    public void reset() %7B%0A        StateContext.switchState(new StateEvent(StateType.OK, true));%0A    %7D
 %0A   
@@ -2019,16 +2019,27 @@
 nnection
+WithOkState
 () %7B%0A   
@@ -2060,17 +2060,16 @@
 n actual
-1
  = Drive
@@ -2325,9 +2325,8 @@
 tual
-1
 , in
@@ -2376,367 +2376,85 @@
     
+%7D%0A
     
-StateContext.switchState(new StateEvent(StateType.CIRCUIT_BREAK, true));%0A        Connection actual2 = DriverStateContext.getConnection(%0A                Collections.emptyMap(), mock(MetaDataContexts.class), mock(TransactionContexts.class, RETURNS_DEEP_STUBS), TransactionType.LOCAL);%0A        assertThat(actual2, instanceOf(CircuitBreakerConnection.class));
+%0A    @Test%0A    public void assertGetConnectionWithCircuitBreakState() %7B
 %0A   
@@ -2527,12 +2527,11 @@
 AK, 
-fals
+tru
 e));
@@ -2556,17 +2556,16 @@
 n actual
-3
  = Drive
@@ -2821,9 +2821,8 @@
 tual
-3
 , in
@@ -2826,38 +2826,38 @@
  instanceOf(
-ShardingSphere
+CircuitBreaker
 Connection.c

Split multi test cases into diff asserttion methods in DriverStateContextTest (#8244)