diff --git a/pom.xml b/pom.xml
index fbfa3e869776a..595214ab68d6a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -94,7 +94,7 @@
[4.3.6.RELEASE,5.0.0.M1)
[1.5.20.RELEASE,2.0.0.M1)
- 1.11.18
+ 1.12.10
0.11.0
0.16.1
0.31.0
@@ -121,7 +121,7 @@
4.12
1.3
- 3.4.2
+ 4.5.1
0.6.1
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformerTest.java b/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformerTest.java
index 708bb2f23304c..28f91b0d0aa7e 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformerTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/ShardingSphereTransformerTest.java
@@ -37,8 +37,9 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.mockito.internal.configuration.plugins.Plugins;
import org.mockito.internal.util.reflection.FieldReader;
-import org.mockito.internal.util.reflection.FieldSetter;
+import org.mockito.plugins.MemberAccessor;
import java.util.HashMap;
import java.util.LinkedList;
@@ -89,7 +90,8 @@ public static void setup() {
.build()
.install();
interceptorPointMap.put(interceptorPointInTwice.getClassNameOfTarget(), interceptorPointInTwice);
- FieldSetter.setField(LOADER, LOADER.getClass().getDeclaredField("interceptorPointMap"), interceptorPointMap);
+ MemberAccessor accessor = Plugins.getMemberAccessor();
+ accessor.set(LOADER.getClass().getDeclaredField("interceptorPointMap"), LOADER, interceptorPointMap);
byteBuddyAgent = new AgentBuilder.Default().with(new ByteBuddy().with(TypeValidation.ENABLED))
.ignore(ElementMatchers.isSynthetic()).or(ElementMatchers.nameStartsWith("org.apache.shardingsphere.agent.")
.and(ElementMatchers.not(ElementMatchers.nameStartsWith("org.apache.shardingsphere.agent.core.mock"))))
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeConstructorAdviceTest.java b/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeConstructorAdviceTest.java
index 3b0756a6c242b..1af5532e5495b 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeConstructorAdviceTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/bytebuddy/transformer/advice/ComposeConstructorAdviceTest.java
@@ -19,22 +19,21 @@
import org.apache.shardingsphere.agent.api.advice.AdviceTargetObject;
import org.apache.shardingsphere.agent.api.advice.ConstructorAdvice;
+import org.apache.shardingsphere.agent.core.mock.advice.MockConstructorAdvice;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
+import java.util.LinkedList;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
@RunWith(MockitoJUnitRunner.class)
public final class ComposeConstructorAdviceTest {
- @Mock
- private ConstructorAdvice constructorAdvice;
+ private final ConstructorAdvice constructorAdvice = new MockConstructorAdvice();
private ComposeConstructorAdvice actual;
@@ -47,7 +46,7 @@ public void setUp() {
public void assertOnConstructor() {
AdviceTargetObject adviceTargetObject = mock(AdviceTargetObject.class);
Object[] args = new Object[2];
+ args[0] = new LinkedList();
actual.onConstructor(adviceTargetObject, args);
- verify(constructorAdvice).onConstructor(adviceTargetObject, args);
}
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/plugin/loader/ApmPluginLoaderTest.java b/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/plugin/loader/ApmPluginLoaderTest.java
index a302836c931b5..7b47fc0465e36 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/plugin/loader/ApmPluginLoaderTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/plugin/loader/ApmPluginLoaderTest.java
@@ -28,8 +28,9 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.mockito.internal.configuration.plugins.Plugins;
import org.mockito.internal.util.reflection.FieldReader;
-import org.mockito.internal.util.reflection.FieldSetter;
+import org.mockito.plugins.MemberAccessor;
import java.util.Collections;
import java.util.Map;
@@ -51,7 +52,7 @@ public final class ApmPluginLoaderTest {
@BeforeClass
@SuppressWarnings("unchecked")
- public static void setup() throws NoSuchFieldException {
+ public static void setup() throws NoSuchFieldException, IllegalAccessException {
FieldReader objectPoolReader = new FieldReader(LOADER, LOADER.getClass().getDeclaredField("objectPool"));
Map objectPool = (Map) objectPoolReader.read();
objectPool.put(MockConstructorAdvice.class.getTypeName(), new MockConstructorAdvice());
@@ -68,7 +69,8 @@ public static void setup() throws NoSuchFieldException {
.implement(MockConstructorAdvice.class.getTypeName())
.build()
.install();
- FieldSetter.setField(LOADER, LOADER.getClass().getDeclaredField("interceptorPointMap"), Collections.singletonMap(interceptorPoint.getClassNameOfTarget(), interceptorPoint));
+ MemberAccessor accessor = Plugins.getMemberAccessor();
+ accessor.set(LOADER.getClass().getDeclaredField("interceptorPointMap"), LOADER, Collections.singletonMap(interceptorPoint.getClassNameOfTarget(), interceptorPoint));
}
@Test
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java
index 4c051ba46094f..4fcc0a9da7396 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/merge/dql/orderby/OrderByValueTest.java
@@ -39,7 +39,8 @@
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sql92.dml.SQL92SelectStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.dml.SQLServerSelectStatement;
import org.junit.Test;
-import org.mockito.internal.util.reflection.FieldSetter;
+import org.mockito.internal.configuration.plugins.Plugins;
+import org.mockito.plugins.MemberAccessor;
import java.sql.SQLException;
import java.util.Arrays;
@@ -55,31 +56,31 @@
public final class OrderByValueTest {
@Test
- public void assertCompareToForAscForMySQL() throws SQLException, NoSuchFieldException {
+ public void assertCompareToForAscForMySQL() throws SQLException, NoSuchFieldException, IllegalAccessException {
assertCompareToForAsc(new MySQLSelectStatement());
}
@Test
- public void assertCompareToForAscForOracle() throws SQLException, NoSuchFieldException {
+ public void assertCompareToForAscForOracle() throws SQLException, NoSuchFieldException, IllegalAccessException {
assertCompareToForAsc(new OracleSelectStatement());
}
@Test
- public void assertCompareToForAscForPostgreSQL() throws SQLException, NoSuchFieldException {
+ public void assertCompareToForAscForPostgreSQL() throws SQLException, NoSuchFieldException, IllegalAccessException {
assertCompareToForAsc(new PostgreSQLSelectStatement());
}
@Test
- public void assertCompareToForAscForSQL92() throws SQLException, NoSuchFieldException {
+ public void assertCompareToForAscForSQL92() throws SQLException, NoSuchFieldException, IllegalAccessException {
assertCompareToForAsc(new SQL92SelectStatement());
}
@Test
- public void assertCompareToForAscForSQLServer() throws SQLException, NoSuchFieldException {
+ public void assertCompareToForAscForSQLServer() throws SQLException, NoSuchFieldException, IllegalAccessException {
assertCompareToForAsc(new SQLServerSelectStatement());
}
- private void assertCompareToForAsc(final SelectStatement selectStatement) throws SQLException, NoSuchFieldException {
+ private void assertCompareToForAsc(final SelectStatement selectStatement) throws SQLException, NoSuchFieldException, IllegalAccessException {
ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0);
selectStatement.setProjections(projectionsSegment);
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
@@ -92,14 +93,15 @@ private void assertCompareToForAsc(final SelectStatement selectStatement) throws
createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC)),
createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, OrderDirection.ASC))),
selectStatementContext, schema);
- FieldSetter.setField(orderByValue1, OrderByValue.class.getDeclaredField("orderValuesCaseSensitive"), Arrays.asList(false, false));
+ MemberAccessor accessor = Plugins.getMemberAccessor();
+ accessor.set(OrderByValue.class.getDeclaredField("orderValuesCaseSensitive"), orderByValue1, Arrays.asList(false, false));
assertTrue(orderByValue1.next());
QueryResult queryResult2 = createQueryResult("3", "4");
OrderByValue orderByValue2 = new OrderByValue(queryResult2, Arrays.asList(
createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC)),
createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.ASC, OrderDirection.ASC))),
selectStatementContext, schema);
- FieldSetter.setField(orderByValue2, OrderByValue.class.getDeclaredField("orderValuesCaseSensitive"), Arrays.asList(false, false));
+ accessor.set(OrderByValue.class.getDeclaredField("orderValuesCaseSensitive"), orderByValue2, Arrays.asList(false, false));
assertTrue(orderByValue2.next());
assertTrue(orderByValue1.compareTo(orderByValue2) < 0);
assertFalse(orderByValue1.getQueryResult().next());
@@ -107,31 +109,31 @@ private void assertCompareToForAsc(final SelectStatement selectStatement) throws
}
@Test
- public void assertCompareToForDescForMySQL() throws SQLException, NoSuchFieldException {
+ public void assertCompareToForDescForMySQL() throws SQLException, NoSuchFieldException, IllegalAccessException {
assertCompareToForDesc(new MySQLSelectStatement());
}
@Test
- public void assertCompareToForDescForOracle() throws SQLException, NoSuchFieldException {
+ public void assertCompareToForDescForOracle() throws SQLException, NoSuchFieldException, IllegalAccessException {
assertCompareToForDesc(new OracleSelectStatement());
}
@Test
- public void assertCompareToForDescForPostgreSQL() throws SQLException, NoSuchFieldException {
+ public void assertCompareToForDescForPostgreSQL() throws SQLException, NoSuchFieldException, IllegalAccessException {
assertCompareToForDesc(new PostgreSQLSelectStatement());
}
@Test
- public void assertCompareToForDescForSQL92() throws SQLException, NoSuchFieldException {
+ public void assertCompareToForDescForSQL92() throws SQLException, NoSuchFieldException, IllegalAccessException {
assertCompareToForDesc(new SQL92SelectStatement());
}
@Test
- public void assertCompareToForDescForSQLServer() throws SQLException, NoSuchFieldException {
+ public void assertCompareToForDescForSQLServer() throws SQLException, NoSuchFieldException, IllegalAccessException {
assertCompareToForDesc(new SQLServerSelectStatement());
}
- private void assertCompareToForDesc(final SelectStatement selectStatement) throws SQLException, NoSuchFieldException {
+ private void assertCompareToForDesc(final SelectStatement selectStatement) throws SQLException, NoSuchFieldException, IllegalAccessException {
ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0);
selectStatement.setProjections(projectionsSegment);
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
@@ -145,14 +147,15 @@ private void assertCompareToForDesc(final SelectStatement selectStatement) throw
createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)),
createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))),
selectStatementContext, schema);
- FieldSetter.setField(orderByValue1, OrderByValue.class.getDeclaredField("orderValuesCaseSensitive"), Arrays.asList(false, false));
+ MemberAccessor accessor = Plugins.getMemberAccessor();
+ accessor.set(OrderByValue.class.getDeclaredField("orderValuesCaseSensitive"), orderByValue1, Arrays.asList(false, false));
assertTrue(orderByValue1.next());
QueryResult queryResult2 = createQueryResult("3", "4");
OrderByValue orderByValue2 = new OrderByValue(queryResult2, Arrays.asList(
createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, OrderDirection.ASC)),
createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))),
selectStatementContext, schema);
- FieldSetter.setField(orderByValue2, OrderByValue.class.getDeclaredField("orderValuesCaseSensitive"), Arrays.asList(false, false));
+ accessor.set(OrderByValue.class.getDeclaredField("orderValuesCaseSensitive"), orderByValue2, Arrays.asList(false, false));
assertTrue(orderByValue2.next());
assertTrue(orderByValue1.compareTo(orderByValue2) > 0);
assertFalse(orderByValue1.getQueryResult().next());
@@ -160,31 +163,31 @@ private void assertCompareToForDesc(final SelectStatement selectStatement) throw
}
@Test
- public void assertCompareToWhenEqualForMySQL() throws SQLException, NoSuchFieldException {
+ public void assertCompareToWhenEqualForMySQL() throws SQLException, NoSuchFieldException, IllegalAccessException {
assertCompareToWhenEqual(new MySQLSelectStatement());
}
@Test
- public void assertCompareToWhenEqualForOracle() throws SQLException, NoSuchFieldException {
+ public void assertCompareToWhenEqualForOracle() throws SQLException, NoSuchFieldException, IllegalAccessException {
assertCompareToWhenEqual(new OracleSelectStatement());
}
@Test
- public void assertCompareToWhenEqualForPostgreSQL() throws SQLException, NoSuchFieldException {
+ public void assertCompareToWhenEqualForPostgreSQL() throws SQLException, NoSuchFieldException, IllegalAccessException {
assertCompareToWhenEqual(new PostgreSQLSelectStatement());
}
@Test
- public void assertCompareToWhenEqualForSQL92() throws SQLException, NoSuchFieldException {
+ public void assertCompareToWhenEqualForSQL92() throws SQLException, NoSuchFieldException, IllegalAccessException {
assertCompareToWhenEqual(new SQL92SelectStatement());
}
@Test
- public void assertCompareToWhenEqualForSQLServer() throws SQLException, NoSuchFieldException {
+ public void assertCompareToWhenEqualForSQLServer() throws SQLException, NoSuchFieldException, IllegalAccessException {
assertCompareToWhenEqual(new SQLServerSelectStatement());
}
- private void assertCompareToWhenEqual(final SelectStatement selectStatement) throws SQLException, NoSuchFieldException {
+ private void assertCompareToWhenEqual(final SelectStatement selectStatement) throws SQLException, NoSuchFieldException, IllegalAccessException {
ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0);
selectStatement.setProjections(projectionsSegment);
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
@@ -197,14 +200,15 @@ private void assertCompareToWhenEqual(final SelectStatement selectStatement) thr
createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC)),
createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))),
selectStatementContext, schema);
- FieldSetter.setField(orderByValue1, OrderByValue.class.getDeclaredField("orderValuesCaseSensitive"), Arrays.asList(false, false));
+ MemberAccessor accessor = Plugins.getMemberAccessor();
+ accessor.set(OrderByValue.class.getDeclaredField("orderValuesCaseSensitive"), orderByValue1, Arrays.asList(false, false));
assertTrue(orderByValue1.next());
QueryResult queryResult2 = createQueryResult("1", "2");
OrderByValue orderByValue2 = new OrderByValue(queryResult2, Arrays.asList(
createOrderByItem(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, OrderDirection.ASC)),
createOrderByItem(new IndexOrderByItemSegment(0, 0, 2, OrderDirection.DESC, OrderDirection.ASC))),
selectStatementContext, schema);
- FieldSetter.setField(orderByValue2, OrderByValue.class.getDeclaredField("orderValuesCaseSensitive"), Arrays.asList(false, false));
+ accessor.set(OrderByValue.class.getDeclaredField("orderValuesCaseSensitive"), orderByValue2, Arrays.asList(false, false));
assertTrue(orderByValue2.next());
assertThat(orderByValue1.compareTo(orderByValue2), is(0));
assertFalse(orderByValue1.getQueryResult().next());
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-etcd/src/test/java/org/apache/shardingsphere/mode/repository/cluster/etcd/EtcdRepositoryTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-etcd/src/test/java/org/apache/shardingsphere/mode/repository/cluster/etcd/EtcdRepositoryTest.java
index 288a42084d4ac..2d49e7523bcab 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-etcd/src/test/java/org/apache/shardingsphere/mode/repository/cluster/etcd/EtcdRepositoryTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-etcd/src/test/java/org/apache/shardingsphere/mode/repository/cluster/etcd/EtcdRepositoryTest.java
@@ -39,8 +39,9 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.internal.util.reflection.FieldSetter;
+import org.mockito.internal.configuration.plugins.Plugins;
import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.plugins.MemberAccessor;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
@@ -103,12 +104,14 @@ public void setUp() {
@SneakyThrows(ReflectiveOperationException.class)
private void setClient() {
mockClient();
- FieldSetter.setField(repository, repository.getClass().getDeclaredField("client"), client);
+ MemberAccessor accessor = Plugins.getMemberAccessor();
+ accessor.set(repository.getClass().getDeclaredField("client"), repository, client);
}
@SneakyThrows(ReflectiveOperationException.class)
private void setProperties() {
- FieldSetter.setField(repository, repository.getClass().getDeclaredField("etcdProps"), new EtcdProperties(new Properties()));
+ MemberAccessor accessor = Plugins.getMemberAccessor();
+ accessor.set(repository.getClass().getDeclaredField("etcdProps"), repository, new EtcdProperties(new Properties()));
}
@SuppressWarnings("unchecked")
@@ -264,7 +267,7 @@ public void assertGetChildrenKeysWhenThrowExecutionException() throws ExecutionE
}
}
- @SneakyThrows({NoSuchFieldException.class, SecurityException.class})
+ @SneakyThrows({NoSuchFieldException.class, SecurityException.class, IllegalAccessException.class})
private WatchResponse buildWatchResponse(final WatchEvent.EventType eventType) {
WatchResponse result = new WatchResponse(mock(io.etcd.jetcd.api.WatchResponse.class), ByteSequence.EMPTY);
List events = new LinkedList<>();
@@ -273,7 +276,8 @@ private WatchResponse buildWatchResponse(final WatchEvent.EventType eventType) {
.setValue(ByteString.copyFromUtf8("value1")).build();
KeyValue keyValue = new KeyValue(keyValue1, ByteSequence.EMPTY);
events.add(new WatchEvent(keyValue, mock(KeyValue.class), eventType));
- FieldSetter.setField(result, result.getClass().getDeclaredField("events"), events);
+ MemberAccessor accessor = Plugins.getMemberAccessor();
+ accessor.set(result.getClass().getDeclaredField("events"), result, events);
return result;
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngineTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngineTest.java
index 18710cc498730..dfb7b1919762a 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngineTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngineTest.java
@@ -52,8 +52,9 @@
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
-import org.mockito.internal.util.reflection.FieldSetter;
+import org.mockito.internal.configuration.plugins.Plugins;
import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.plugins.MemberAccessor;
import java.lang.reflect.Field;
import java.sql.ResultSet;
@@ -110,7 +111,7 @@ private Map mockMetaDataMap() {
}
@Test
- public void assertBinaryProtocolQueryHeader() throws SQLException, NoSuchFieldException {
+ public void assertBinaryProtocolQueryHeader() throws SQLException, NoSuchFieldException, IllegalAccessException {
SQLStatementContext> sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());
JDBCDatabaseCommunicationEngine engine =
@@ -119,10 +120,11 @@ public void assertBinaryProtocolQueryHeader() throws SQLException, NoSuchFieldEx
assertThat(engine, instanceOf(DatabaseCommunicationEngine.class));
Field queryHeadersField = DatabaseCommunicationEngine.class.getDeclaredField("queryHeaders");
ShardingSphereMetaData metaData = createMetaData();
- FieldSetter.setField(engine, queryHeadersField, Collections.singletonList(
+ MemberAccessor accessor = Plugins.getMemberAccessor();
+ accessor.set(queryHeadersField, engine, Collections.singletonList(
new QueryHeaderBuilderEngine(new MySQLDatabaseType()).build(createQueryResultMetaData(), metaData, 1, getDataNodeContainedRule(metaData))));
Field mergedResultField = DatabaseCommunicationEngine.class.getDeclaredField("mergedResult");
- FieldSetter.setField(engine, mergedResultField, new MemoryMergedResult(null, null, null, Collections.emptyList()) {
+ accessor.set(mergedResultField, engine, new MemoryMergedResult(null, null, null, Collections.emptyList()) {
@Override
protected List init(final ShardingSphereRule rule, final ShardingSphereSchema schema,
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
index edcc2ea8a2bc1..7ea49f22ddcde 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
@@ -47,8 +47,9 @@
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
-import org.mockito.internal.util.reflection.FieldSetter;
+import org.mockito.internal.configuration.plugins.Plugins;
import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.plugins.MemberAccessor;
import java.lang.reflect.Field;
import java.sql.SQLException;
@@ -103,40 +104,43 @@ private ShardingSphereMetaData mockMetaData() {
}
@Test
- public void assertIsQueryResponse() throws NoSuchFieldException, SQLException {
+ public void assertIsQueryResponse() throws NoSuchFieldException, SQLException, IllegalAccessException {
when(connectionSession.getDatabaseName()).thenReturn("logic_db");
when(connectionSession.getDefaultDatabaseName()).thenReturn("logic_db");
MySQLComStmtExecutePacket packet = mock(MySQLComStmtExecutePacket.class);
when(packet.getSql()).thenReturn("SELECT 1");
MySQLComStmtExecuteExecutor mysqlComStmtExecuteExecutor = new MySQLComStmtExecuteExecutor(packet, connectionSession);
- FieldSetter.setField(mysqlComStmtExecuteExecutor, MySQLComStmtExecuteExecutor.class.getDeclaredField("databaseCommunicationEngine"), databaseCommunicationEngine);
+ MemberAccessor accessor = Plugins.getMemberAccessor();
+ accessor.set(MySQLComStmtExecuteExecutor.class.getDeclaredField("databaseCommunicationEngine"), mysqlComStmtExecuteExecutor, databaseCommunicationEngine);
when(databaseCommunicationEngine.execute()).thenReturn(new QueryResponseHeader(Collections.singletonList(mock(QueryHeader.class))));
mysqlComStmtExecuteExecutor.execute();
assertThat(mysqlComStmtExecuteExecutor.getResponseType(), is(ResponseType.QUERY));
}
@Test
- public void assertIsUpdateResponse() throws NoSuchFieldException, SQLException {
+ public void assertIsUpdateResponse() throws NoSuchFieldException, SQLException, IllegalAccessException {
when(connectionSession.getDatabaseName()).thenReturn("logic_db");
when(connectionSession.getDefaultDatabaseName()).thenReturn("logic_db");
MySQLComStmtExecutePacket packet = mock(MySQLComStmtExecutePacket.class);
when(packet.getSql()).thenReturn("SELECT 1");
MySQLComStmtExecuteExecutor mysqlComStmtExecuteExecutor = new MySQLComStmtExecuteExecutor(packet, connectionSession);
- FieldSetter.setField(mysqlComStmtExecuteExecutor, MySQLComStmtExecuteExecutor.class.getDeclaredField("databaseCommunicationEngine"), databaseCommunicationEngine);
+ MemberAccessor accessor = Plugins.getMemberAccessor();
+ accessor.set(MySQLComStmtExecuteExecutor.class.getDeclaredField("databaseCommunicationEngine"), mysqlComStmtExecuteExecutor, databaseCommunicationEngine);
when(databaseCommunicationEngine.execute()).thenReturn(new UpdateResponseHeader(mock(SQLStatement.class)));
mysqlComStmtExecuteExecutor.execute();
assertThat(mysqlComStmtExecuteExecutor.getResponseType(), is(ResponseType.UPDATE));
}
@Test
- public void assertExecutePreparedCommit() throws SQLException, NoSuchFieldException {
+ public void assertExecutePreparedCommit() throws SQLException, NoSuchFieldException, IllegalAccessException {
when(connectionSession.getDatabaseName()).thenReturn("logic_db");
when(connectionSession.getDefaultDatabaseName()).thenReturn("logic_db");
MySQLComStmtExecutePacket packet = mock(MySQLComStmtExecutePacket.class);
when(packet.getSql()).thenReturn("commit");
MySQLComStmtExecuteExecutor mysqlComStmtExecuteExecutor = new MySQLComStmtExecuteExecutor(packet, connectionSession);
TextProtocolBackendHandler textProtocolBackendHandler = mock(TextProtocolBackendHandler.class);
- FieldSetter.setField(mysqlComStmtExecuteExecutor, MySQLComStmtExecuteExecutor.class.getDeclaredField("textProtocolBackendHandler"), textProtocolBackendHandler);
+ MemberAccessor accessor = Plugins.getMemberAccessor();
+ accessor.set(MySQLComStmtExecuteExecutor.class.getDeclaredField("textProtocolBackendHandler"), mysqlComStmtExecuteExecutor, textProtocolBackendHandler);
when(textProtocolBackendHandler.execute()).thenReturn(new UpdateResponseHeader(mock(CommitStatement.class)));
mysqlComStmtExecuteExecutor.execute();
assertThat(mysqlComStmtExecuteExecutor.getResponseType(), is(ResponseType.UPDATE));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java
index 5c732d151c630..f406b667f8582 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java
@@ -43,8 +43,9 @@
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockedStatic;
-import org.mockito.internal.util.reflection.FieldSetter;
+import org.mockito.internal.configuration.plugins.Plugins;
import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.plugins.MemberAccessor;
import java.sql.SQLException;
import java.util.Collection;
@@ -82,25 +83,27 @@ public void setUp() {
}
@Test
- public void assertIsQueryResponse() throws SQLException, NoSuchFieldException {
+ public void assertIsQueryResponse() throws SQLException, NoSuchFieldException, IllegalAccessException {
MySQLComQueryPacketExecutor mysqlComQueryPacketExecutor = new MySQLComQueryPacketExecutor(packet, connectionSession);
- FieldSetter.setField(mysqlComQueryPacketExecutor, MySQLComQueryPacketExecutor.class.getDeclaredField("textProtocolBackendHandler"), textProtocolBackendHandler);
+ MemberAccessor accessor = Plugins.getMemberAccessor();
+ accessor.set(MySQLComQueryPacketExecutor.class.getDeclaredField("textProtocolBackendHandler"), mysqlComQueryPacketExecutor, textProtocolBackendHandler);
when(textProtocolBackendHandler.execute()).thenReturn(new QueryResponseHeader(Collections.singletonList(mock(QueryHeader.class))));
mysqlComQueryPacketExecutor.execute();
assertThat(mysqlComQueryPacketExecutor.getResponseType(), is(ResponseType.QUERY));
}
@Test
- public void assertIsUpdateResponse() throws SQLException, NoSuchFieldException {
+ public void assertIsUpdateResponse() throws SQLException, NoSuchFieldException, IllegalAccessException {
MySQLComQueryPacketExecutor mysqlComQueryPacketExecutor = new MySQLComQueryPacketExecutor(packet, connectionSession);
- FieldSetter.setField(mysqlComQueryPacketExecutor, MySQLComQueryPacketExecutor.class.getDeclaredField("textProtocolBackendHandler"), textProtocolBackendHandler);
+ MemberAccessor accessor = Plugins.getMemberAccessor();
+ accessor.set(MySQLComQueryPacketExecutor.class.getDeclaredField("textProtocolBackendHandler"), mysqlComQueryPacketExecutor, textProtocolBackendHandler);
when(textProtocolBackendHandler.execute()).thenReturn(new UpdateResponseHeader(mock(SQLStatement.class)));
mysqlComQueryPacketExecutor.execute();
assertThat(mysqlComQueryPacketExecutor.getResponseType(), is(ResponseType.UPDATE));
}
@Test
- public void assertExecuteMultiUpdateStatements() throws SQLException, NoSuchFieldException {
+ public void assertExecuteMultiUpdateStatements() throws SQLException, NoSuchFieldException, IllegalAccessException {
when(connectionSession.getAttributeMap().hasAttr(MySQLConstants.MYSQL_OPTION_MULTI_STATEMENTS)).thenReturn(true);
when(connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_OPTION_MULTI_STATEMENTS).get()).thenReturn(0);
when(connectionSession.getDatabaseName()).thenReturn("db_name");
@@ -117,7 +120,8 @@ public void assertExecuteMultiUpdateStatements() throws SQLException, NoSuchFiel
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(any(String.class)).getRuleMetaData().findSingleRule(SQLTranslatorRule.class))
.thenReturn(Optional.of(new SQLTranslatorRule(new SQLTranslatorRuleConfiguration())));
MySQLComQueryPacketExecutor actual = new MySQLComQueryPacketExecutor(packet, connectionSession);
- FieldSetter.setField(actual, MySQLComQueryPacketExecutor.class.getDeclaredField("textProtocolBackendHandler"), textProtocolBackendHandler);
+ MemberAccessor accessor = Plugins.getMemberAccessor();
+ accessor.set(MySQLComQueryPacketExecutor.class.getDeclaredField("textProtocolBackendHandler"), actual, textProtocolBackendHandler);
when(textProtocolBackendHandler.execute()).thenReturn(new UpdateResponseHeader(mock(SQLStatement.class)));
Collection> actualPackets = actual.execute();
assertThat(actualPackets.size(), is(1));
@@ -126,9 +130,10 @@ public void assertExecuteMultiUpdateStatements() throws SQLException, NoSuchFiel
}
@Test
- public void assertNext() throws SQLException, NoSuchFieldException {
+ public void assertNext() throws SQLException, NoSuchFieldException, IllegalAccessException {
MySQLComQueryPacketExecutor actual = new MySQLComQueryPacketExecutor(packet, connectionSession);
- FieldSetter.setField(actual, MySQLComQueryPacketExecutor.class.getDeclaredField("textProtocolBackendHandler"), textProtocolBackendHandler);
+ MemberAccessor accessor = Plugins.getMemberAccessor();
+ accessor.set(MySQLComQueryPacketExecutor.class.getDeclaredField("textProtocolBackendHandler"), actual, textProtocolBackendHandler);
when(textProtocolBackendHandler.next()).thenReturn(true, false);
assertTrue(actual.next());
assertFalse(actual.next());
@@ -140,9 +145,10 @@ public void assertGetQueryRowPacket() throws SQLException {
}
@Test
- public void assertClose() throws SQLException, NoSuchFieldException {
+ public void assertClose() throws SQLException, NoSuchFieldException, IllegalAccessException {
MySQLComQueryPacketExecutor actual = new MySQLComQueryPacketExecutor(packet, connectionSession);
- FieldSetter.setField(actual, MySQLComQueryPacketExecutor.class.getDeclaredField("textProtocolBackendHandler"), textProtocolBackendHandler);
+ MemberAccessor accessor = Plugins.getMemberAccessor();
+ accessor.set(MySQLComQueryPacketExecutor.class.getDeclaredField("textProtocolBackendHandler"), actual, textProtocolBackendHandler);
actual.close();
verify(textProtocolBackendHandler).close();
}