You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/12/19 14:27:31 UTC
[shardingsphere] branch master updated: Revise fixture class names (#22980)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 f306248c8d1 Revise fixture class names (#22980)
f306248c8d1 is described below
commit f306248c8d1d7e4b54ffec60eb4a125eb0f52119
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Mon Dec 19 22:27:23 2022 +0800
Revise fixture class names (#22980)
---
.../core/fixture/targeted/ConstructorMaterial.java | 30 -----
.../core/fixture/targeted/InstanceMaterial.java | 45 --------
.../core/fixture/targeted/StaticMaterial.java | 45 --------
.../executor/ConstructorAdviceExecutorTest.java | 102 -----------------
.../executor/InstanceMethodAdviceExecutorTest.java | 124 ---------------------
.../executor/StaticMethodAdviceExecutorTest.java | 115 -------------------
.../core/transformer/AgentTransformerTest.java | 36 +++---
.../fixture/advice/BarInstanceMethodAdvice.java} | 4 +-
.../fixture/advice/FooConstructorAdvice.java} | 18 +--
.../fixture/advice/FooInstanceMethodAdvice.java} | 6 +-
.../fixture/advice/FooStaticMethodAdvice.java} | 6 +-
.../fixture/targeted/BarTargetObjectFixture.java} | 7 +-
.../fixture/targeted/FooTargetObjectFixture.java} | 6 +-
13 files changed, 34 insertions(+), 510 deletions(-)
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/targeted/ConstructorMaterial.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/targeted/ConstructorMaterial.java
deleted file mode 100644
index d966488a136..00000000000
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/targeted/ConstructorMaterial.java
+++ /dev/null
@@ -1,30 +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.agent.core.fixture.targeted;
-
-import lombok.NoArgsConstructor;
-
-import java.util.List;
-
-@NoArgsConstructor
-public final class ConstructorMaterial {
-
- public ConstructorMaterial(final List<String> queue) {
- queue.add("constructor");
- }
-}
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/targeted/InstanceMaterial.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/targeted/InstanceMaterial.java
deleted file mode 100644
index ac91ac59302..00000000000
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/targeted/InstanceMaterial.java
+++ /dev/null
@@ -1,45 +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.agent.core.fixture.targeted;
-
-import java.io.IOException;
-import java.util.List;
-
-public class InstanceMaterial {
-
- /**
- * Mock method for testing.
- *
- * @param queue queue
- * @return result
- */
- public String mock(final List<String> queue) {
- queue.add("on");
- return "invocation";
- }
-
- /**
- * Mock method for testing with exception.
- *
- * @param queue queue
- * @throws IOException IO Exception
- */
- public void mockWithException(final List<String> queue) throws IOException {
- throw new IOException();
- }
-}
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/targeted/StaticMaterial.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/targeted/StaticMaterial.java
deleted file mode 100644
index ee4e1598c98..00000000000
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/targeted/StaticMaterial.java
+++ /dev/null
@@ -1,45 +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.agent.core.fixture.targeted;
-
-import java.io.IOException;
-import java.util.List;
-
-public final class StaticMaterial {
-
- /**
- * Mock static method for testing.
- *
- * @param queue queue
- * @return result
- */
- public static String staticMock(final List<String> queue) {
- queue.add("on");
- return "static invocation";
- }
-
- /**
- * Mock static method for testing with exception.
- *
- * @param queue queue
- * @throws IOException IO Exception
- */
- public static void staticMockWithException(final List<String> queue) throws IOException {
- throw new IOException();
- }
-}
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/executor/ConstructorAdviceExecutorTest.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/executor/ConstructorAdviceExecutorTest.java
deleted file mode 100644
index 1d5b5370b47..00000000000
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/executor/ConstructorAdviceExecutorTest.java
+++ /dev/null
@@ -1,102 +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.agent.core.plugin.executor;
-
-import net.bytebuddy.ByteBuddy;
-import net.bytebuddy.agent.ByteBuddyAgent;
-import net.bytebuddy.agent.builder.AgentBuilder;
-import net.bytebuddy.agent.builder.ResettableClassFileTransformer;
-import net.bytebuddy.dynamic.scaffold.TypeValidation;
-import net.bytebuddy.implementation.FieldAccessor;
-import net.bytebuddy.implementation.MethodDelegation;
-import net.bytebuddy.implementation.SuperMethodCall;
-import net.bytebuddy.jar.asm.Opcodes;
-import net.bytebuddy.matcher.ElementMatchers;
-import org.apache.shardingsphere.agent.advice.TargetAdviceObject;
-import org.apache.shardingsphere.agent.core.logging.LoggingListener;
-import org.apache.shardingsphere.agent.core.fixture.advice.MockConstructorAdvice;
-import org.apache.shardingsphere.agent.core.fixture.targeted.ConstructorMaterial;
-import org.apache.shardingsphere.agent.core.plugin.executor.type.ConstructorAdviceExecutor;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertArrayEquals;
-
-public final class ConstructorAdviceExecutorTest {
-
- private static final String EXTRA_DATA = "_$EXTRA_DATA$_";
-
- private static final String CLASS_PATH = "org.apache.shardingsphere.agent.core.fixture.targeted.ConstructorMaterial";
-
- private static final List<String> QUEUE = new LinkedList<>();
-
- private static ResettableClassFileTransformer byteBuddyAgent;
-
- @BeforeClass
- public static void setup() {
- ByteBuddyAgent.install();
- byteBuddyAgent = new AgentBuilder.Default()
- .with(new ByteBuddy().with(TypeValidation.ENABLED))
- .ignore(ElementMatchers.isSynthetic())
- .with(new LoggingListener())
- .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
- .type(ElementMatchers.named(CLASS_PATH))
- .transform((builder, typeDescription, classLoader, module) -> {
- if (CLASS_PATH.equals(typeDescription.getTypeName())) {
- return builder.defineField(EXTRA_DATA, Object.class, Opcodes.ACC_PRIVATE | Opcodes.ACC_VOLATILE)
- .implement(TargetAdviceObject.class)
- .intercept(FieldAccessor.ofField(EXTRA_DATA))
- .constructor(ElementMatchers.isConstructor())
- .intercept(SuperMethodCall.INSTANCE.andThen(MethodDelegation.withDefaultConfiguration()
- .to(new ConstructorAdviceExecutor(Collections.singleton(new MockConstructorAdvice(QUEUE))))));
- }
- return builder;
- })
- .asTerminalTransformation()
- .installOnByteBuddyAgent();
- }
-
- @Test
- public void assertNoArgConstructor() {
- assertThat(new ConstructorMaterial(), instanceOf(TargetAdviceObject.class));
- }
-
- @Test
- public void assertConstructor() {
- new ConstructorMaterial(QUEUE);
- assertArrayEquals(new String[]{"constructor", "on constructor"}, QUEUE.toArray());
- }
-
- @After
- public void cleanup() {
- QUEUE.clear();
- }
-
- @AfterClass
- public static void destroy() {
- byteBuddyAgent.reset(ByteBuddyAgent.getInstrumentation(), AgentBuilder.RedefinitionStrategy.RETRANSFORMATION);
- }
-}
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/executor/InstanceMethodAdviceExecutorTest.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/executor/InstanceMethodAdviceExecutorTest.java
deleted file mode 100644
index 68a167959c0..00000000000
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/executor/InstanceMethodAdviceExecutorTest.java
+++ /dev/null
@@ -1,124 +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.agent.core.plugin.executor;
-
-import lombok.RequiredArgsConstructor;
-import net.bytebuddy.ByteBuddy;
-import net.bytebuddy.agent.ByteBuddyAgent;
-import net.bytebuddy.agent.builder.AgentBuilder;
-import net.bytebuddy.agent.builder.ResettableClassFileTransformer;
-import net.bytebuddy.dynamic.scaffold.TypeValidation;
-import net.bytebuddy.implementation.FieldAccessor;
-import net.bytebuddy.implementation.MethodDelegation;
-import net.bytebuddy.jar.asm.Opcodes;
-import net.bytebuddy.matcher.ElementMatchers;
-import org.apache.shardingsphere.agent.advice.TargetAdviceObject;
-import org.apache.shardingsphere.agent.core.fixture.advice.MockInstanceMethodAdvice;
-import org.apache.shardingsphere.agent.core.fixture.targeted.InstanceMaterial;
-import org.apache.shardingsphere.agent.core.plugin.executor.type.InstanceMethodAdviceExecutor;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertArrayEquals;
-
-@RunWith(Parameterized.class)
-@RequiredArgsConstructor
-public final class InstanceMethodAdviceExecutorTest {
-
- private static final String EXTRA_DATA = "_$EXTRA_DATA$_";
-
- private static final String CLASS_PATH = "org.apache.shardingsphere.agent.core.fixture.targeted.InstanceMaterial";
-
- private static ResettableClassFileTransformer byteBuddyAgent;
-
- private final boolean rebase;
-
- private final String methodName;
-
- private final String result;
-
- private final String[] expected;
-
- @Parameters
- public static Collection<Object[]> prepareData() {
- return Arrays.asList(
- new Object[]{false, "mock", "invocation", new String[]{"before", "on", "after"}},
- new Object[]{true, "mock", "rebase invocation method", new String[]{"before", "after"}},
- new Object[]{false, "mockWithException", null, new String[]{"before", "exception", "after"}});
- }
-
- @BeforeClass
- public static void setup() {
- ByteBuddyAgent.install();
- byteBuddyAgent = new AgentBuilder.Default().with(new ByteBuddy().with(TypeValidation.ENABLED))
- .with(new ByteBuddy())
- .type(ElementMatchers.named(CLASS_PATH))
- .transform((builder, typeDescription, classLoader, module) -> {
- if (CLASS_PATH.equals(typeDescription.getTypeName())) {
- return builder.defineField(EXTRA_DATA, Object.class, Opcodes.ACC_PRIVATE | Opcodes.ACC_VOLATILE)
- .implement(TargetAdviceObject.class)
- .intercept(FieldAccessor.ofField(EXTRA_DATA));
- }
- return builder;
- }).asTerminalTransformation()
- .installOnByteBuddyAgent();
- }
-
- @Test
- public void assertInterceptedMethod() throws ReflectiveOperationException {
- InstanceMaterial material = new ByteBuddy()
- .subclass(InstanceMaterial.class)
- .method(ElementMatchers.named(methodName))
- .intercept(MethodDelegation.withDefaultConfiguration().to(new InstanceMethodAdviceExecutor(Collections.singleton(new MockInstanceMethodAdvice(rebase)))))
- .make()
- .load(new MockClassLoader())
- .getLoaded()
- .getDeclaredConstructor().newInstance();
- List<String> queues = new LinkedList<>();
- if ("mockWithException".equals(methodName)) {
- try {
- material.mockWithException(queues);
- } catch (IOException ignored) {
- }
- } else {
- assertThat(material.mock(queues), is(result));
- }
- assertArrayEquals(expected, queues.toArray());
- }
-
- @AfterClass
- public static void destroy() {
- byteBuddyAgent.reset(ByteBuddyAgent.getInstrumentation(), AgentBuilder.RedefinitionStrategy.RETRANSFORMATION);
- }
-
- private static class MockClassLoader extends ClassLoader {
- }
-}
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/executor/StaticMethodAdviceExecutorTest.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/executor/StaticMethodAdviceExecutorTest.java
deleted file mode 100644
index c544f158d20..00000000000
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/executor/StaticMethodAdviceExecutorTest.java
+++ /dev/null
@@ -1,115 +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.agent.core.plugin.executor;
-
-import lombok.RequiredArgsConstructor;
-import net.bytebuddy.ByteBuddy;
-import net.bytebuddy.agent.ByteBuddyAgent;
-import net.bytebuddy.agent.builder.AgentBuilder;
-import net.bytebuddy.agent.builder.ResettableClassFileTransformer;
-import net.bytebuddy.dynamic.scaffold.TypeValidation;
-import net.bytebuddy.implementation.FieldAccessor;
-import net.bytebuddy.implementation.MethodDelegation;
-import net.bytebuddy.jar.asm.Opcodes;
-import net.bytebuddy.matcher.ElementMatchers;
-import org.apache.shardingsphere.agent.advice.TargetAdviceObject;
-import org.apache.shardingsphere.agent.core.fixture.advice.MockStaticMethodAdvice;
-import org.apache.shardingsphere.agent.core.fixture.targeted.StaticMaterial;
-import org.apache.shardingsphere.agent.core.plugin.executor.type.StaticMethodAdviceExecutor;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertArrayEquals;
-
-@RunWith(Parameterized.class)
-@RequiredArgsConstructor
-public final class StaticMethodAdviceExecutorTest {
-
- private static final String EXTRA_DATA = "_$EXTRA_DATA$_";
-
- private static final String CLASS_PATH = "org.apache.shardingsphere.agent.core.fixture.targeted.StaticMaterial";
-
- private static ResettableClassFileTransformer byteBuddyAgent;
-
- private final String methodName;
-
- private final String result;
-
- private final String[] expected;
-
- @Parameters
- public static Collection<Object[]> prepareData() {
- return Arrays.asList(
- new Object[]{"staticMock", "rebase static invocation method", new String[]{"before", "after"}},
- new Object[]{"staticMockWithException", null, new String[]{"before", "exception", "after"}});
- }
-
- @BeforeClass
- public static void setup() {
- ByteBuddyAgent.install();
- byteBuddyAgent = new AgentBuilder.Default().with(new ByteBuddy().with(TypeValidation.ENABLED))
- .with(new ByteBuddy())
- .type(ElementMatchers.named(CLASS_PATH))
- .transform((builder, typeDescription, classLoader, module) -> {
- if (CLASS_PATH.equals(typeDescription.getTypeName())) {
- return builder.defineField(EXTRA_DATA, Object.class, Opcodes.ACC_PRIVATE | Opcodes.ACC_VOLATILE)
- .implement(TargetAdviceObject.class)
- .intercept(FieldAccessor.ofField(EXTRA_DATA))
- .method(ElementMatchers.named("staticMockWithException"))
- .intercept(MethodDelegation.withDefaultConfiguration().to(new StaticMethodAdviceExecutor(Collections.singleton(new MockStaticMethodAdvice(false)))))
- .method(ElementMatchers.named("staticMock"))
- .intercept(MethodDelegation.withDefaultConfiguration().to(new StaticMethodAdviceExecutor(Collections.singleton(new MockStaticMethodAdvice(true)))));
- }
- return builder;
- })
- .asTerminalTransformation()
- .installOnByteBuddyAgent();
- }
-
- @Test
- public void assertInterceptedMethod() {
- List<String> queues = new LinkedList<>();
- if ("staticMockWithException".equals(methodName)) {
- try {
- StaticMaterial.staticMockWithException(queues);
- } catch (final IOException ignored) {
- }
- } else {
- assertThat(StaticMaterial.staticMock(queues), is(result));
- }
- assertArrayEquals(expected, queues.toArray());
- }
-
- @AfterClass
- public static void destroy() {
- byteBuddyAgent.reset(ByteBuddyAgent.getInstrumentation(), AgentBuilder.RedefinitionStrategy.RETRANSFORMATION);
- }
-}
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/AgentTransformerTest.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/AgentTransformerTest.java
index b85c18b01af..bff7c41c27a 100644
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/AgentTransformerTest.java
+++ b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/AgentTransformerTest.java
@@ -27,12 +27,12 @@ import org.apache.shardingsphere.agent.config.advisor.AdvisorConfiguration;
import org.apache.shardingsphere.agent.config.advisor.MethodAdvisorConfiguration;
import org.apache.shardingsphere.agent.core.classloader.AgentClassLoader;
import org.apache.shardingsphere.agent.core.logging.LoggingListener;
-import org.apache.shardingsphere.agent.core.fixture.advice.MockConstructorAdvice;
-import org.apache.shardingsphere.agent.core.fixture.advice.MockInstanceMethodAdvice;
-import org.apache.shardingsphere.agent.core.fixture.advice.MockInstanceMethodRepeatedAdvice;
-import org.apache.shardingsphere.agent.core.fixture.advice.MockStaticMethodAdvice;
-import org.apache.shardingsphere.agent.core.fixture.targeted.Material;
-import org.apache.shardingsphere.agent.core.fixture.targeted.RepeatedAdviceMaterial;
+import org.apache.shardingsphere.agent.core.transformer.fixture.advice.FooConstructorAdvice;
+import org.apache.shardingsphere.agent.core.transformer.fixture.advice.FooInstanceMethodAdvice;
+import org.apache.shardingsphere.agent.core.transformer.fixture.advice.BarInstanceMethodAdvice;
+import org.apache.shardingsphere.agent.core.transformer.fixture.advice.FooStaticMethodAdvice;
+import org.apache.shardingsphere.agent.core.transformer.fixture.targeted.FooTargetObjectFixture;
+import org.apache.shardingsphere.agent.core.transformer.fixture.targeted.BarTargetObjectFixture;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -75,42 +75,42 @@ public final class AgentTransformerTest {
}
private static AdvisorConfiguration createAdvisorConfiguration() {
- AdvisorConfiguration result = new AdvisorConfiguration("org.apache.shardingsphere.agent.core.fixture.targeted.Material");
- result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.isConstructor().and(ElementMatchers.takesArguments(1)), MockConstructorAdvice.class.getTypeName()));
- result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("mock"), MockInstanceMethodAdvice.class.getTypeName()));
- result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("staticMock"), MockStaticMethodAdvice.class.getTypeName()));
+ AdvisorConfiguration result = new AdvisorConfiguration("org.apache.shardingsphere.agent.core.fixture.targeted.FooTargetObjectFixture");
+ result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.isConstructor().and(ElementMatchers.takesArguments(1)), FooConstructorAdvice.class.getTypeName()));
+ result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("mock"), FooInstanceMethodAdvice.class.getTypeName()));
+ result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("staticMock"), FooStaticMethodAdvice.class.getTypeName()));
return result;
}
private static AdvisorConfiguration createAdvisorConfigurationInTwice() {
- AdvisorConfiguration result = new AdvisorConfiguration("org.apache.shardingsphere.agent.core.fixture.targeted.RepeatedAdviceMaterial");
- result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("mock"), MockInstanceMethodAdvice.class.getTypeName()));
- result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("mock"), MockInstanceMethodRepeatedAdvice.class.getTypeName()));
+ AdvisorConfiguration result = new AdvisorConfiguration("org.apache.shardingsphere.agent.core.fixture.targeted.BarTargetObjectFixture");
+ result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("mock"), FooInstanceMethodAdvice.class.getTypeName()));
+ result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("mock"), BarInstanceMethodAdvice.class.getTypeName()));
return result;
}
@Test
public void assertInstanceMethod() {
- assertThat(new Material().mock(queue), is("invocation"));
+ assertThat(new FooTargetObjectFixture().mock(queue), is("invocation"));
assertArrayEquals(new String[]{"before", "on", "after"}, queue.toArray());
}
@Test
public void assertInstanceMethodInRepeatedAdvice() {
- assertThat(new RepeatedAdviceMaterial().mock(queue), is("invocation"));
+ assertThat(new BarTargetObjectFixture().mock(queue), is("invocation"));
assertArrayEquals(new String[]{"before", "twice_before", "on", "after", "twice_after"}, queue.toArray());
}
@Test
public void assertStaticMethod() {
- assertThat(Material.staticMock(queue), is("static invocation"));
+ assertThat(FooTargetObjectFixture.staticMock(queue), is("static invocation"));
assertArrayEquals(new String[]{"before", "on", "after"}, queue.toArray());
}
@Test
public void assertConstructor() {
- new Material(queue);
- assertArrayEquals(new String[]{"constructor", "on constructor"}, queue.toArray());
+ new FooTargetObjectFixture(queue);
+ assertArrayEquals(new String[]{"constructor", "advice constructor"}, queue.toArray());
}
@After
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/advice/MockInstanceMethodRepeatedAdvice.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/advice/BarInstanceMethodAdvice.java
similarity index 92%
rename from agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/advice/MockInstanceMethodRepeatedAdvice.java
rename to agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/advice/BarInstanceMethodAdvice.java
index 00788007e33..902f613edfd 100644
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/advice/MockInstanceMethodRepeatedAdvice.java
+++ b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/advice/BarInstanceMethodAdvice.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.fixture.advice;
+package org.apache.shardingsphere.agent.core.transformer.fixture.advice;
import org.apache.shardingsphere.agent.advice.type.InstanceMethodAdvice;
import org.apache.shardingsphere.agent.advice.TargetAdviceObject;
@@ -25,7 +25,7 @@ import java.lang.reflect.Method;
import java.util.List;
@SuppressWarnings("unchecked")
-public final class MockInstanceMethodRepeatedAdvice implements InstanceMethodAdvice {
+public final class BarInstanceMethodAdvice implements InstanceMethodAdvice {
@Override
public void beforeMethod(final TargetAdviceObject target, final Method method, final Object[] args, final MethodInvocationResult invocationResult) {
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/advice/MockConstructorAdvice.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/advice/FooConstructorAdvice.java
similarity index 67%
rename from agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/advice/MockConstructorAdvice.java
rename to agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/advice/FooConstructorAdvice.java
index 8944ee028b9..a0bb33feea7 100644
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/advice/MockConstructorAdvice.java
+++ b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/advice/FooConstructorAdvice.java
@@ -15,30 +15,18 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.fixture.advice;
+package org.apache.shardingsphere.agent.core.transformer.fixture.advice;
-import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.agent.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.advice.type.ConstructorAdvice;
import java.util.List;
-import java.util.Optional;
-@RequiredArgsConstructor
-public final class MockConstructorAdvice implements ConstructorAdvice {
-
- private final List<String> queues;
-
- public MockConstructorAdvice() {
- this(null);
- }
+public final class FooConstructorAdvice implements ConstructorAdvice {
@Override
@SuppressWarnings("unchecked")
public void onConstructor(final TargetAdviceObject target, final Object[] args) {
- if (null != args && args.length > 0) {
- List<String> list = Optional.ofNullable(queues).orElse((List<String>) args[0]);
- list.add("on constructor");
- }
+ ((List<String>) args[0]).add("advice constructor");
}
}
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/advice/MockInstanceMethodAdvice.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/advice/FooInstanceMethodAdvice.java
similarity index 91%
rename from agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/advice/MockInstanceMethodAdvice.java
rename to agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/advice/FooInstanceMethodAdvice.java
index c6744037250..051a990bdf5 100644
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/advice/MockInstanceMethodAdvice.java
+++ b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/advice/FooInstanceMethodAdvice.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.fixture.advice;
+package org.apache.shardingsphere.agent.core.transformer.fixture.advice;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.agent.advice.type.InstanceMethodAdvice;
@@ -27,11 +27,11 @@ import java.util.List;
@RequiredArgsConstructor
@SuppressWarnings("unchecked")
-public final class MockInstanceMethodAdvice implements InstanceMethodAdvice {
+public final class FooInstanceMethodAdvice implements InstanceMethodAdvice {
private final boolean rebase;
- public MockInstanceMethodAdvice() {
+ public FooInstanceMethodAdvice() {
this(false);
}
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/advice/MockStaticMethodAdvice.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/advice/FooStaticMethodAdvice.java
similarity index 91%
rename from agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/advice/MockStaticMethodAdvice.java
rename to agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/advice/FooStaticMethodAdvice.java
index b8f8f86c8b8..08aecd2506f 100644
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/advice/MockStaticMethodAdvice.java
+++ b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/advice/FooStaticMethodAdvice.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.fixture.advice;
+package org.apache.shardingsphere.agent.core.transformer.fixture.advice;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.agent.advice.type.StaticMethodAdvice;
@@ -26,11 +26,11 @@ import java.util.List;
@RequiredArgsConstructor
@SuppressWarnings("unchecked")
-public final class MockStaticMethodAdvice implements StaticMethodAdvice {
+public final class FooStaticMethodAdvice implements StaticMethodAdvice {
private final boolean rebase;
- public MockStaticMethodAdvice() {
+ public FooStaticMethodAdvice() {
this(false);
}
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/targeted/RepeatedAdviceMaterial.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/targeted/BarTargetObjectFixture.java
similarity index 86%
rename from agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/targeted/RepeatedAdviceMaterial.java
rename to agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/targeted/BarTargetObjectFixture.java
index fd0faa9e16d..f5c3c5d752f 100644
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/targeted/RepeatedAdviceMaterial.java
+++ b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/targeted/BarTargetObjectFixture.java
@@ -15,14 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.fixture.targeted;
-
-import lombok.NoArgsConstructor;
+package org.apache.shardingsphere.agent.core.transformer.fixture.targeted;
import java.util.List;
-@NoArgsConstructor
-public final class RepeatedAdviceMaterial {
+public final class BarTargetObjectFixture {
/**
* Mock method for testing.
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/targeted/Material.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/targeted/FooTargetObjectFixture.java
similarity index 88%
rename from agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/targeted/Material.java
rename to agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/targeted/FooTargetObjectFixture.java
index f64507592d9..d82f03fdf29 100644
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/fixture/targeted/Material.java
+++ b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/transformer/fixture/targeted/FooTargetObjectFixture.java
@@ -15,16 +15,16 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.fixture.targeted;
+package org.apache.shardingsphere.agent.core.transformer.fixture.targeted;
import lombok.NoArgsConstructor;
import java.util.List;
@NoArgsConstructor
-public final class Material {
+public final class FooTargetObjectFixture {
- public Material(final List<String> queue) {
+ public FooTargetObjectFixture(final List<String> queue) {
queue.add("constructor");
}