This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 5791a1b6b3a Add ProxyContextTest (#37477)
5791a1b6b3a is described below
commit 5791a1b6b3ad9a2c89fdac68341baf6bba70acd3
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Dec 23 21:23:30 2025 +0800
Add ProxyContextTest (#37477)
* Add ProxyContextTest
* Add ProxyContextTest
---
AGENTS.md | 1 +
.../proxy/backend/context/ProxyContextTest.java | 56 ++++++++++++++++++++++
2 files changed, 57 insertions(+)
diff --git a/AGENTS.md b/AGENTS.md
index 736f10fa496..b0a7a14ab82 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -33,6 +33,7 @@ This guide is written **for AI coding agents only**. Follow
it literally; improv
- **Checkstyle Gate**: do not hand off code with Checkstyle/Spotless
failures—run the relevant module check locally and fix before completion.
- **Continuous Verification**: rely on automated tests and integration
validation.
- **Public-Only Tests**: unit tests must exercise behavior via public APIs
only; never use reflection to access private members.
+- **Single-Test Naming**: when a production method is covered by only one test
case, name that test method `assert<MethodName>` without extra suffixes.
- **Coverage Pledge**: when 100% coverage is required, enumerate every
branch/path and its planned test before coding, then implement once to reach
100% without post-hoc fixes.
- **Mock/Spy Specification**: Use mock by default; consider spy only when the
scenario cannot be adequately represented using a mock. Avoid spy entirely when
standard `mock + when` can express behavior, and do not introduce inner classes
for testing purposes—prefer plain test classes with mocks.
- **Strictness and Stub Control**: Enable @MockitoSettings(strictness =
Strictness.LENIENT) in the Mockito scenario or apply lenient() to specific
stubs to ensure there are no unmatched or redundant stubs; clean up any unused
stubs, imports, or local variables before committing.
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java
new file mode 100644
index 00000000000..926fd2e1054
--- /dev/null
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.proxy.backend.context;
+
+import org.apache.shardingsphere.mode.manager.ContextManager;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.internal.configuration.plugins.Plugins;
+
+import java.lang.reflect.Field;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.mock;
+
+class ProxyContextTest {
+
+ private ContextManager originalContextManager;
+
+ @BeforeEach
+ void setUp() throws ReflectiveOperationException {
+ Field contextManagerField =
ProxyContext.class.getDeclaredField("contextManager");
+ originalContextManager = (ContextManager)
Plugins.getMemberAccessor().get(contextManagerField,
ProxyContext.getInstance());
+ Plugins.getMemberAccessor().set(contextManagerField,
ProxyContext.getInstance(), null);
+ }
+
+ @AfterEach
+ void cleanUp() throws ReflectiveOperationException {
+ Field contextManagerField =
ProxyContext.class.getDeclaredField("contextManager");
+ Plugins.getMemberAccessor().set(contextManagerField,
ProxyContext.getInstance(), originalContextManager);
+ }
+
+ @Test
+ void assertInit() {
+ ProxyContext actualProxyContext = ProxyContext.getInstance();
+ ContextManager expectedContextManager = mock(ContextManager.class);
+ ProxyContext.init(expectedContextManager);
+ assertThat(actualProxyContext.getContextManager(),
is(expectedContextManager));
+ }
+}