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

jimin pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git


The following commit(s) were added to refs/heads/2.x by this push:
     new 5f60247faf test: add UT for 
org.apache.seata.spring.annotation.scannercheckers (#7423)
5f60247faf is described below

commit 5f60247fafcf5c344c302c91c7a162b1c474107a
Author: maple <[email protected]>
AuthorDate: Mon Jun 9 00:19:06 2025 +0800

    test: add UT for org.apache.seata.spring.annotation.scannercheckers (#7423)
---
 changes/en-us/2.x.md                               |   1 +
 changes/zh-cn/2.x.md                               |   1 +
 .../ConfigBeansScannerCheckerTest.java             |  88 +++++++
 .../scannercheckers/PackageScannerCheckerTest.java | 187 ++++++++++++++
 .../ScopeBeansScannerCheckerTest.java              | 278 +++++++++++++++++++++
 5 files changed, 555 insertions(+)

diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index 7b911a4e6f..9f4217e1e2 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -81,6 +81,7 @@ Add changes here for all PR submitted to the 2.x branch.
 - [[#7295](https://github.com/apache/incubator-seata/pull/7295)] updated 3 
tests in StringUtilsTest to use parameterized unit testing
 - [[#7205](https://github.com/apache/incubator-seata/issues/7205)] add UT for 
namingserver module
 - [[#7359](https://github.com/apache/incubator-seata/issues/7359)] merge 
submodule test reports
+- [[#7377](https://github.com/apache/incubator-seata/issues/7377)] add UT for 
org.apache.seata.spring.annotation.scannercheckers
 - [[#7379](https://github.com/apache/incubator-seata/issues/7379)] add UT for 
TccAnnotationProcessor class
 
 
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index c8e1cb5d89..a80d2b0d16 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -82,6 +82,7 @@
 - [[#7295](https://github.com/apache/incubator-seata/pull/7295)] 重构了 
StringUtilsTest 中的 3 个测试,改为使用参数化单元测试
 - [[#7205](https://github.com/apache/incubator-seata/issues/7205)] 为 
namingserver module 添加单元测试
 - [[#7359](https://github.com/apache/incubator-seata/issues/7359)] 
合并所有模块的单测报告,准确显示单测覆盖度
+- [[#7377](https://github.com/apache/incubator-seata/issues/7377)] 为 
org.apache.seata.spring.annotation.scannercheckers 添加单元测试
 - [[#7379](https://github.com/apache/incubator-seata/issues/7379)] 为 
TccAnnotationProcessor 添加了单元测试 
 
 
diff --git 
a/spring/src/test/java/org/apache/seata/spring/annotation/scannercheckers/ConfigBeansScannerCheckerTest.java
 
b/spring/src/test/java/org/apache/seata/spring/annotation/scannercheckers/ConfigBeansScannerCheckerTest.java
new file mode 100644
index 0000000000..aa3c33a6c8
--- /dev/null
+++ 
b/spring/src/test/java/org/apache/seata/spring/annotation/scannercheckers/ConfigBeansScannerCheckerTest.java
@@ -0,0 +1,88 @@
+/*
+ * 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.seata.spring.annotation.scannercheckers;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import 
org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+
+import java.util.stream.Stream;
+
+/**
+ * Test for {@link ConfigBeansScannerChecker} class
+ */
+public class ConfigBeansScannerCheckerTest {
+
+    private final ConfigBeansScannerChecker checker = new 
ConfigBeansScannerChecker();
+    private final Object testBean = new Object();
+    private final ConfigurableListableBeanFactory beanFactory = null;
+
+    /**
+     * Provide test data
+     */
+    private static Stream<Arguments> provideBeanNameTestCases() {
+        return Stream.of(
+                // Bean names ending with Configuration should return false
+                Arguments.of("testConfiguration", false),
+                // Bean names ending with Properties should return false
+                Arguments.of("testProperties", false),
+                // Bean names ending with Config should return false
+                Arguments.of("testConfig", false),
+                // Normal bean names should return true
+                Arguments.of("normalBean", true),
+                // Empty bean name should return true
+                Arguments.of("", true),
+                // Bean names containing but not ending with Configuration 
should return true
+                Arguments.of("ConfigurationTest", true),
+                // Bean names containing but not ending with Properties should 
return true
+                Arguments.of("PropertiesTest", true),
+                // Bean names containing but not ending with Config should 
return true
+                Arguments.of("ConfigTest", true)
+        );
+    }
+
+    /**
+     * Helper method: execute checker.check and return result
+     */
+    private boolean doCheck(String beanName) throws Exception {
+        return checker.check(testBean, beanName, beanFactory);
+    }
+
+    @ParameterizedTest
+    @MethodSource("provideBeanNameTestCases")
+    public void testCheck(String beanName, boolean expected) throws Exception {
+        boolean result = doCheck(beanName);
+        Assertions.assertEquals(expected, result, "Bean name '" + beanName + 
"' should return " + expected);
+    }
+
+    @Test
+    public void testCheckWithNullBeanName() throws Exception {
+        boolean result = doCheck(null);
+        Assertions.assertTrue(result, "Should return true when bean name is 
null");
+    }
+
+    @Test
+    public void testRealConfigBeans() throws Exception {
+        // Test common configuration class naming patterns
+        Assertions.assertFalse(doCheck("dataSourceConfiguration"));
+        Assertions.assertFalse(doCheck("applicationProperties"));
+        Assertions.assertFalse(doCheck("serverConfig"));
+    }
+} 
\ No newline at end of file
diff --git 
a/spring/src/test/java/org/apache/seata/spring/annotation/scannercheckers/PackageScannerCheckerTest.java
 
b/spring/src/test/java/org/apache/seata/spring/annotation/scannercheckers/PackageScannerCheckerTest.java
new file mode 100644
index 0000000000..633fa64a15
--- /dev/null
+++ 
b/spring/src/test/java/org/apache/seata/spring/annotation/scannercheckers/PackageScannerCheckerTest.java
@@ -0,0 +1,187 @@
+/*
+ * 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.seata.spring.annotation.scannercheckers;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import 
org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+
+import java.lang.reflect.Field;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Test for {@link PackageScannerChecker} class
+ */
+public class PackageScannerCheckerTest {
+
+    private final PackageScannerChecker checker = new PackageScannerChecker();
+    private final ConfigurableListableBeanFactory beanFactory = null;
+    private Set<String> originalPackages;
+
+    /**
+     * Setup before each test - save original packages and clear the set
+     */
+    @BeforeEach
+    public void setUp() throws Exception {
+        // Save original packages
+        originalPackages = getScannablePackageSet();
+        
+        // Clear the package set for testing
+        clearScannablePackageSet();
+    }
+
+    /**
+     * Cleanup after each test - restore original packages
+     */
+    @AfterEach
+    public void tearDown() throws Exception {
+        // Restore original packages
+        clearScannablePackageSet();
+        if (originalPackages != null) {
+            for (String pkg : originalPackages) {
+                PackageScannerChecker.addScannablePackages(pkg);
+            }
+        }
+    }
+
+    /**
+     * Test check method when package set is empty
+     */
+    @Test
+    public void testCheckWhenPackageSetEmpty() throws Exception {
+        // When package set is empty, should return true for any bean
+        Object testBean = new Object();
+        boolean result = checker.check(testBean, "testBean", beanFactory);
+        Assertions.assertTrue(result, "Should return true when package set is 
empty");
+    }
+
+    /**
+     * Test check method with matching package
+     */
+    @Test
+    public void testCheckWithMatchingPackage() throws Exception {
+        // Add test packages
+        PackageScannerChecker.addScannablePackages("org.apache.seata");
+        
+        // Test with bean in the scannable package
+        TestBean testBean = new TestBean();
+        boolean result = checker.check(testBean, "testBean", beanFactory);
+        Assertions.assertTrue(result, "Should return true when bean's package 
matches scannable package");
+    }
+
+    /**
+     * Test check method with non-matching package
+     */
+    @Test
+    public void testCheckWithNonMatchingPackage() throws Exception {
+        // Add test packages
+        PackageScannerChecker.addScannablePackages("com.example");
+        
+        // Test with bean not in the scannable package
+        TestBean testBean = new TestBean();
+        boolean result = checker.check(testBean, "testBean", beanFactory);
+        Assertions.assertFalse(result, "Should return false when bean's 
package doesn't match scannable package");
+    }
+
+    /**
+     * Test addScannablePackages method
+     */
+    @Test
+    public void testAddScannablePackages() throws Exception {
+        // Add test packages
+        PackageScannerChecker.addScannablePackages("com.example", 
"org.apache.seata");
+        
+        // Verify packages were added
+        Set<String> packages = getScannablePackageSet();
+        Assertions.assertEquals(2, packages.size(), "Should have 2 packages in 
the set");
+        Assertions.assertTrue(packages.contains("com.example"), "Should 
contain 'com.example'");
+        Assertions.assertTrue(packages.contains("org.apache.seata"), "Should 
contain 'org.apache.seata'");
+    }
+
+    /**
+     * Test addScannablePackages with blank packages
+     */
+    @Test
+    public void testAddScannablePackagesWithBlankPackages() throws Exception {
+        // Add test packages including blank ones
+        PackageScannerChecker.addScannablePackages("com.example", "", "  ", 
null);
+        
+        // Verify only non-blank packages were added
+        Set<String> packages = getScannablePackageSet();
+        Assertions.assertEquals(1, packages.size(), "Should have 1 package in 
the set");
+        Assertions.assertTrue(packages.contains("com.example"), "Should 
contain 'com.example'");
+    }
+
+    /**
+     * Test addScannablePackages with null
+     */
+    @Test
+    public void testAddScannablePackagesWithNull() throws Exception {
+        // Add null packages
+        PackageScannerChecker.addScannablePackages((String[])null);
+        
+        // Verify no packages were added
+        Set<String> packages = getScannablePackageSet();
+        Assertions.assertTrue(packages.isEmpty(), "Package set should be 
empty");
+    }
+
+    /**
+     * Test case sensitivity in package names
+     */
+    @Test
+    public void testPackageNameCaseSensitivity() throws Exception {
+        // Add test packages with mixed case
+        PackageScannerChecker.addScannablePackages("Com.Example");
+        
+        // Verify package was added in lowercase
+        Set<String> packages = getScannablePackageSet();
+        Assertions.assertEquals(1, packages.size(), "Should have 1 package in 
the set");
+        Assertions.assertTrue(packages.contains("com.example"), "Should 
contain lowercase 'com.example'");
+        Assertions.assertFalse(packages.contains("Com.Example"), "Should not 
contain 'Com.Example' with original case");
+    }
+
+    /**
+     * Helper method to get the SCANNABLE_PACKAGE_SET field value
+     */
+    @SuppressWarnings("unchecked")
+    private Set<String> getScannablePackageSet() throws Exception {
+        Field field = 
PackageScannerChecker.class.getDeclaredField("SCANNABLE_PACKAGE_SET");
+        field.setAccessible(true);
+        Set<String> packages = (Set<String>)field.get(null);
+        return new HashSet<>(packages); // Return a copy to avoid modifying 
the original
+    }
+
+    /**
+     * Helper method to clear the SCANNABLE_PACKAGE_SET
+     */
+    private void clearScannablePackageSet() throws Exception {
+        Field field = 
PackageScannerChecker.class.getDeclaredField("SCANNABLE_PACKAGE_SET");
+        field.setAccessible(true);
+        Set<String> packages = (Set<String>)field.get(null);
+        packages.clear();
+    }
+
+    /**
+     * Test bean class for package testing
+     */
+    private static class TestBean {
+        // Empty class for testing
+    }
+} 
\ No newline at end of file
diff --git 
a/spring/src/test/java/org/apache/seata/spring/annotation/scannercheckers/ScopeBeansScannerCheckerTest.java
 
b/spring/src/test/java/org/apache/seata/spring/annotation/scannercheckers/ScopeBeansScannerCheckerTest.java
new file mode 100644
index 0000000000..5e205da65a
--- /dev/null
+++ 
b/spring/src/test/java/org/apache/seata/spring/annotation/scannercheckers/ScopeBeansScannerCheckerTest.java
@@ -0,0 +1,278 @@
+/*
+ * 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.seata.spring.annotation.scannercheckers;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
+import org.springframework.beans.factory.config.BeanDefinition;
+import 
org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.core.type.AnnotationMetadata;
+import org.springframework.core.type.MethodMetadata;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+
+import java.lang.reflect.Field;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Test for {@link ScopeBeansScannerChecker} class
+ */
+public class ScopeBeansScannerCheckerTest {
+
+    private final ScopeBeansScannerChecker checker = new 
ScopeBeansScannerChecker();
+    private final Object testBean = new Object();
+    private Set<String> originalExcludeScopes;
+
+    /**
+     * Setup before each test - save original exclude scopes
+     */
+    @BeforeEach
+    public void setUp() throws Exception {
+        // Save original exclude scopes
+        originalExcludeScopes = getExcludeScopeSet();
+    }
+
+    /**
+     * Cleanup after each test - restore original exclude scopes
+     */
+    @AfterEach
+    public void tearDown() throws Exception {
+        // Restore original exclude scopes
+        setExcludeScopeSet(originalExcludeScopes);
+    }
+
+    /**
+     * Test check method when beanFactory is null
+     */
+    @Test
+    public void testCheckWhenBeanFactoryIsNull() throws Exception {
+        boolean result = checker.check(testBean, "testBean", null);
+        Assertions.assertTrue(result, "Should return true when beanFactory is 
null");
+    }
+
+    /**
+     * Test check method when bean definition is not found
+     */
+    @Test
+    public void testCheckWhenBeanDefinitionNotFound() throws Exception {
+        ConfigurableListableBeanFactory beanFactory = 
Mockito.mock(ConfigurableListableBeanFactory.class);
+        Mockito.when(beanFactory.getBeanDefinition(Mockito.anyString()))
+               .thenThrow(new NoSuchBeanDefinitionException("testBean"));
+        
+        boolean result = checker.check(testBean, "testBean", beanFactory);
+        Assertions.assertTrue(result, "Should return true when bean definition 
is not found");
+    }
+
+    /**
+     * Test check method when bean definition is not an AnnotatedBeanDefinition
+     */
+    @Test
+    public void testCheckWhenBeanDefinitionIsNotAnnotated() throws Exception {
+        ConfigurableListableBeanFactory beanFactory = 
Mockito.mock(ConfigurableListableBeanFactory.class);
+        BeanDefinition beanDefinition = Mockito.mock(BeanDefinition.class);
+        
+        
Mockito.when(beanFactory.getBeanDefinition(Mockito.anyString())).thenReturn(beanDefinition);
+        
Mockito.when(beanDefinition.getOriginatingBeanDefinition()).thenReturn(null);
+        
+        boolean result = checker.check(testBean, "testBean", beanFactory);
+        Assertions.assertTrue(result, "Should return true when bean definition 
is not an AnnotatedBeanDefinition");
+    }
+
+    /**
+     * Test check method with non-excluded scope
+     */
+    @Test
+    public void testCheckWithNonExcludedScope() throws Exception {
+        // Mock objects
+        ConfigurableListableBeanFactory beanFactory = 
Mockito.mock(ConfigurableListableBeanFactory.class);
+        AnnotatedBeanDefinition beanDefinition = 
Mockito.mock(AnnotatedBeanDefinition.class);
+        AnnotationMetadata metadata = Mockito.mock(AnnotationMetadata.class);
+        
+        // Setup scope attributes with a non-excluded scope
+        MultiValueMap<String, Object> scopeAttributes = new 
LinkedMultiValueMap<>();
+        scopeAttributes.add("scopeName", "singleton");
+        
+        // Setup mock behavior
+        
Mockito.when(beanFactory.getBeanDefinition(Mockito.anyString())).thenReturn(beanDefinition);
+        Mockito.when(beanDefinition.getMetadata()).thenReturn(metadata);
+        
Mockito.when(beanDefinition.getFactoryMethodMetadata()).thenReturn(null);
+        
Mockito.when(metadata.getAllAnnotationAttributes(Mockito.eq(Scope.class.getName()))).thenReturn(scopeAttributes);
+        
+        boolean result = checker.check(testBean, "testBean", beanFactory);
+        Assertions.assertTrue(result, "Should return true when scope is not 
excluded");
+    }
+
+    /**
+     * Test check method with excluded scope
+     */
+    @Test
+    public void testCheckWithExcludedScope() throws Exception {
+        // Mock objects
+        ConfigurableListableBeanFactory beanFactory = 
Mockito.mock(ConfigurableListableBeanFactory.class);
+        AnnotatedBeanDefinition beanDefinition = 
Mockito.mock(AnnotatedBeanDefinition.class);
+        AnnotationMetadata metadata = Mockito.mock(AnnotationMetadata.class);
+        
+        // Setup scope attributes with an excluded scope (request)
+        MultiValueMap<String, Object> scopeAttributes = new 
LinkedMultiValueMap<>();
+        scopeAttributes.add("scopeName", 
ScopeBeansScannerChecker.REQUEST_SCOPE_NAME);
+        
+        // Setup mock behavior
+        
Mockito.when(beanFactory.getBeanDefinition(Mockito.anyString())).thenReturn(beanDefinition);
+        Mockito.when(beanDefinition.getMetadata()).thenReturn(metadata);
+        
Mockito.when(beanDefinition.getFactoryMethodMetadata()).thenReturn(null);
+        
Mockito.when(metadata.getAllAnnotationAttributes(Mockito.eq(Scope.class.getName()))).thenReturn(scopeAttributes);
+        
+        boolean result = checker.check(testBean, "testBean", beanFactory);
+        Assertions.assertFalse(result, "Should return false when scope is 
excluded");
+    }
+
+    /**
+     * Test check method with factory method metadata having excluded scope
+     */
+    @Test
+    public void testCheckWithFactoryMethodHavingExcludedScope() throws 
Exception {
+        // Mock objects
+        ConfigurableListableBeanFactory beanFactory = 
Mockito.mock(ConfigurableListableBeanFactory.class);
+        AnnotatedBeanDefinition beanDefinition = 
Mockito.mock(AnnotatedBeanDefinition.class);
+        AnnotationMetadata metadata = Mockito.mock(AnnotationMetadata.class);
+        MethodMetadata factoryMethodMetadata = 
Mockito.mock(MethodMetadata.class);
+        
+        // Setup factory method metadata with an excluded scope (session)
+        MultiValueMap<String, Object> factoryScopeAttributes = new 
LinkedMultiValueMap<>();
+        factoryScopeAttributes.add("scopeName", 
ScopeBeansScannerChecker.SESSION_SCOPE_NAME);
+        
+        // Setup mock behavior
+        
Mockito.when(beanFactory.getBeanDefinition(Mockito.anyString())).thenReturn(beanDefinition);
+        Mockito.when(beanDefinition.getMetadata()).thenReturn(metadata);
+        
Mockito.when(beanDefinition.getFactoryMethodMetadata()).thenReturn(factoryMethodMetadata);
+        
Mockito.when(factoryMethodMetadata.getAllAnnotationAttributes(Mockito.eq(Scope.class.getName())))
+               .thenReturn(factoryScopeAttributes);
+        
Mockito.when(metadata.getAllAnnotationAttributes(Mockito.eq(Scope.class.getName()))).thenReturn(null);
+        
+        boolean result = checker.check(testBean, "testBean", beanFactory);
+        Assertions.assertFalse(result, "Should return false when factory 
method has excluded scope");
+    }
+
+    /**
+     * Test check method with no scope annotation
+     */
+    @Test
+    public void testCheckWithNoScopeAnnotation() throws Exception {
+        // Mock objects
+        ConfigurableListableBeanFactory beanFactory = 
Mockito.mock(ConfigurableListableBeanFactory.class);
+        AnnotatedBeanDefinition beanDefinition = 
Mockito.mock(AnnotatedBeanDefinition.class);
+        AnnotationMetadata metadata = Mockito.mock(AnnotationMetadata.class);
+        
+        // Setup mock behavior
+        
Mockito.when(beanFactory.getBeanDefinition(Mockito.anyString())).thenReturn(beanDefinition);
+        Mockito.when(beanDefinition.getMetadata()).thenReturn(metadata);
+        
Mockito.when(beanDefinition.getFactoryMethodMetadata()).thenReturn(null);
+        
Mockito.when(metadata.getAllAnnotationAttributes(Mockito.eq(Scope.class.getName()))).thenReturn(null);
+        
+        boolean result = checker.check(testBean, "testBean", beanFactory);
+        Assertions.assertTrue(result, "Should return true when no scope 
annotation is present");
+    }
+
+    /**
+     * Test addExcludeScopes method
+     */
+    @Test
+    public void testAddExcludeScopes() throws Exception {
+        // Clear exclude scopes first
+        Set<String> originalSet = getExcludeScopeSet();
+        setExcludeScopeSet(new HashSet<>());
+        
+        // Add exclude scopes
+        ScopeBeansScannerChecker.addExcludeScopes("custom1", "custom2");
+        
+        // Verify scopes were added
+        Set<String> excludeScopes = getExcludeScopeSet();
+        Assertions.assertEquals(2, excludeScopes.size(), "Should have 2 
exclude scopes");
+        Assertions.assertTrue(excludeScopes.contains("custom1"), "Should 
contain 'custom1'");
+        Assertions.assertTrue(excludeScopes.contains("custom2"), "Should 
contain 'custom2'");
+        
+        // Restore original set
+        setExcludeScopeSet(originalSet);
+    }
+
+    /**
+     * Test addExcludeScopes with blank scopes
+     */
+    @Test
+    public void testAddExcludeScopesWithBlankScopes() throws Exception {
+        // Clear exclude scopes first
+        Set<String> originalSet = getExcludeScopeSet();
+        setExcludeScopeSet(new HashSet<>());
+        
+        // Add exclude scopes including blank ones
+        ScopeBeansScannerChecker.addExcludeScopes("custom", "", "  ", null);
+        
+        // Verify only non-blank scopes were added
+        Set<String> excludeScopes = getExcludeScopeSet();
+        Assertions.assertEquals(1, excludeScopes.size(), "Should have 1 
exclude scope");
+        Assertions.assertTrue(excludeScopes.contains("custom"), "Should 
contain 'custom'");
+        
+        // Restore original set
+        setExcludeScopeSet(originalSet);
+    }
+
+    /**
+     * Test default exclude scopes
+     */
+    @Test
+    public void testDefaultExcludeScopes() throws Exception {
+        Set<String> excludeScopes = getExcludeScopeSet();
+        
Assertions.assertTrue(excludeScopes.contains(ScopeBeansScannerChecker.REQUEST_SCOPE_NAME),
 
+                             "Should contain 'request' scope by default");
+        
Assertions.assertTrue(excludeScopes.contains(ScopeBeansScannerChecker.SESSION_SCOPE_NAME),
 
+                             "Should contain 'session' scope by default");
+        
Assertions.assertTrue(excludeScopes.contains(ScopeBeansScannerChecker.JOB_SCOPE_NAME),
 
+                             "Should contain 'job' scope by default");
+        
Assertions.assertTrue(excludeScopes.contains(ScopeBeansScannerChecker.STEP_SCOPE_NAME),
 
+                             "Should contain 'step' scope by default");
+    }
+
+    /**
+     * Helper method to get the EXCLUDE_SCOPE_SET field value
+     */
+    @SuppressWarnings("unchecked")
+    private Set<String> getExcludeScopeSet() throws Exception {
+        Field field = 
ScopeBeansScannerChecker.class.getDeclaredField("EXCLUDE_SCOPE_SET");
+        field.setAccessible(true);
+        Set<String> scopes = (Set<String>)field.get(null);
+        return new HashSet<>(scopes); // Return a copy to avoid modifying the 
original
+    }
+
+    /**
+     * Helper method to set the EXCLUDE_SCOPE_SET field value
+     */
+    @SuppressWarnings("unchecked")
+    private void setExcludeScopeSet(Set<String> scopes) throws Exception {
+        Field field = 
ScopeBeansScannerChecker.class.getDeclaredField("EXCLUDE_SCOPE_SET");
+        field.setAccessible(true);
+        Set<String> originalSet = (Set<String>)field.get(null);
+        originalSet.clear();
+        originalSet.addAll(scopes);
+    }
+} 
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to