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 5e822b2deb6 Use mock to instead of FixtureJobType (#37117)
5e822b2deb6 is described below
commit 5e822b2deb6de851dc45b2cacf242c20b3ab1f1c
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Nov 15 22:14:56 2025 +0800
Use mock to instead of FixtureJobType (#37117)
---
.../pipeline/core/job/type/JobCodeRegistry.java | 1 +
.../pipeline/core/job/type/FixtureJobType.java | 42 ----------------------
.../core/job/type/JobCodeRegistryTest.java | 17 ++++++++-
...ere.data.pipeline.core.job.type.PipelineJobType | 18 ----------
4 files changed, 17 insertions(+), 61 deletions(-)
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/type/JobCodeRegistry.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/type/JobCodeRegistry.java
index 10ed2cde6c7..d856e3d46f0 100644
---
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/type/JobCodeRegistry.java
+++
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/type/JobCodeRegistry.java
@@ -29,6 +29,7 @@ import java.util.Map;
* Job code registry.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
+@SuppressWarnings("rawtypes")
public final class JobCodeRegistry {
private static final Map<String, PipelineJobType> JOB_CODE_AND_TYPE_MAP =
new HashMap<>();
diff --git
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/type/FixtureJobType.java
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/type/FixtureJobType.java
deleted file mode 100644
index efaad7bf5f9..00000000000
---
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/type/FixtureJobType.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.data.pipeline.core.job.type;
-
-import
org.apache.shardingsphere.data.pipeline.core.job.config.PipelineJobConfiguration;
-import org.apache.shardingsphere.data.pipeline.core.pojo.PipelineJobObjective;
-
-/**
- * Fixture job type.
- */
-public final class FixtureJobType implements
PipelineJobType<PipelineJobConfiguration> {
-
- @Override
- public PipelineJobOption getOption() {
- return new PipelineJobOption("00", true, null, null, null, false,
null, null, false);
- }
-
- @Override
- public PipelineJobObjective getJobObjective(final PipelineJobConfiguration
jobConfig) {
- return null;
- }
-
- @Override
- public String getType() {
- return "FIXTURE";
- }
-}
diff --git
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/type/JobCodeRegistryTest.java
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/type/JobCodeRegistryTest.java
index 7292b1e99bb..740f46b46b3 100644
---
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/type/JobCodeRegistryTest.java
+++
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/type/JobCodeRegistryTest.java
@@ -17,15 +17,30 @@
package org.apache.shardingsphere.data.pipeline.core.job.type;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import
org.apache.shardingsphere.test.infra.framework.extension.mock.AutoMockExtension;
+import
org.apache.shardingsphere.test.infra.framework.extension.mock.StaticMockSettings;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+@ExtendWith(AutoMockExtension.class)
+@StaticMockSettings(ShardingSphereServiceLoader.class)
class JobCodeRegistryTest {
@Test
void assertGetJobType() {
- assertThat(JobCodeRegistry.getJobType("00").getType(), is("FIXTURE"));
+ PipelineJobType<?> pipelineJobType = mock(PipelineJobType.class,
RETURNS_DEEP_STUBS);
+ when(pipelineJobType.getOption().getCode()).thenReturn("-1");
+ when(pipelineJobType.getType()).thenReturn("FIXTURE");
+
when(ShardingSphereServiceLoader.getServiceInstances(PipelineJobType.class)).thenReturn(Collections.singleton(pipelineJobType));
+ assertThat(JobCodeRegistry.getJobType("-1").getType(), is("FIXTURE"));
}
}
diff --git
a/kernel/data-pipeline/core/src/test/resources/META-INF/services/org.apache.shardingsphere.data.pipeline.core.job.type.PipelineJobType
b/kernel/data-pipeline/core/src/test/resources/META-INF/services/org.apache.shardingsphere.data.pipeline.core.job.type.PipelineJobType
deleted file mode 100644
index ef84c8840d9..00000000000
---
a/kernel/data-pipeline/core/src/test/resources/META-INF/services/org.apache.shardingsphere.data.pipeline.core.job.type.PipelineJobType
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# 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.
-#
-
-org.apache.shardingsphere.data.pipeline.core.job.type.FixtureJobType