From 2112e447a0eb77edd17170883af74bf55a07e666 Mon Sep 17 00:00:00 2001 From: Dzmitry Sankouski Date: Mon, 28 Mar 2022 19:52:19 +0300 Subject: [PATCH] review fixes - remove DataProviderMethodRemovable.java class add isDynamic flag to IDataProviderMethod - remove excessive params - fix Class raw usage --- .../java/org/testng/IDataProviderMethod.java | 2 ++ .../testng/internal/DataProviderLoader.java | 7 ++---- .../testng/internal/DataProviderMethod.java | 22 +++++++++++++++++++ .../internal/DataProviderMethodRemovable.java | 20 ----------------- .../java/org/testng/internal/Parameters.java | 8 +++---- .../internal/LiteWeightTestNGMethod.java | 5 +++++ 6 files changed, 35 insertions(+), 29 deletions(-) delete mode 100644 testng-core/src/main/java/org/testng/internal/DataProviderMethodRemovable.java diff --git a/testng-core-api/src/main/java/org/testng/IDataProviderMethod.java b/testng-core-api/src/main/java/org/testng/IDataProviderMethod.java index 7a495bab1d..2400253913 100644 --- a/testng-core-api/src/main/java/org/testng/IDataProviderMethod.java +++ b/testng-core-api/src/main/java/org/testng/IDataProviderMethod.java @@ -23,6 +23,8 @@ public interface IDataProviderMethod { /** @return Whether this data provider should be run in parallel. */ boolean isParallel(); + boolean isDynamic(); + /** @return Which indices to run from this data provider, default: all. */ List getIndices(); } diff --git a/testng-core/src/main/java/org/testng/internal/DataProviderLoader.java b/testng-core/src/main/java/org/testng/internal/DataProviderLoader.java index 8f27cf3245..3695236a89 100644 --- a/testng-core/src/main/java/org/testng/internal/DataProviderLoader.java +++ b/testng-core/src/main/java/org/testng/internal/DataProviderLoader.java @@ -2,14 +2,11 @@ import java.io.IOException; import java.io.InputStream; -import org.testng.log4testng.Logger; public class DataProviderLoader extends ClassLoader { - private static final int BUFFER_SIZE = 1 << 20; - private static final Logger log = Logger.getLogger(DataProviderLoader.class); - public Class loadClazz(String path) throws ClassNotFoundException { - Class clazz = findLoadedClass(path); + public Class loadClazz(String path) throws ClassNotFoundException { + Class clazz = findLoadedClass(path); if (clazz == null) { byte[] bt = loadClassData(path); clazz = defineClass(path, bt, 0, bt.length); diff --git a/testng-core/src/main/java/org/testng/internal/DataProviderMethod.java b/testng-core/src/main/java/org/testng/internal/DataProviderMethod.java index e9795968cf..0428e4505d 100644 --- a/testng-core/src/main/java/org/testng/internal/DataProviderMethod.java +++ b/testng-core/src/main/java/org/testng/internal/DataProviderMethod.java @@ -11,6 +11,7 @@ class DataProviderMethod implements IDataProviderMethod { protected Object instance; protected Method method; private final IDataProviderAnnotation annotation; + private boolean isDynamic = false; DataProviderMethod(Object instance, Method method, IDataProviderAnnotation annotation) { this.instance = instance; @@ -18,6 +19,14 @@ class DataProviderMethod implements IDataProviderMethod { this.annotation = annotation; } + DataProviderMethod( + Object instance, Method method, IDataProviderAnnotation annotation, boolean isDynamic) { + this.instance = instance; + this.method = method; + this.annotation = annotation; + this.isDynamic = isDynamic; + } + @Override public Object getInstance() { return instance; @@ -38,8 +47,21 @@ public boolean isParallel() { return annotation.isParallel(); } + @Override + public boolean isDynamic() { + return isDynamic; + } + @Override public List getIndices() { return annotation.getIndices(); } + + public void setInstance(Object instance) { + this.instance = instance; + } + + public void setMethod(Method method) { + this.method = method; + } } diff --git a/testng-core/src/main/java/org/testng/internal/DataProviderMethodRemovable.java b/testng-core/src/main/java/org/testng/internal/DataProviderMethodRemovable.java deleted file mode 100644 index b4c1a98171..0000000000 --- a/testng-core/src/main/java/org/testng/internal/DataProviderMethodRemovable.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.testng.internal; - -import java.lang.reflect.Method; -import org.testng.annotations.IDataProviderAnnotation; - -/** Represents an @{@link org.testng.annotations.DataProvider} annotated method. */ -class DataProviderMethodRemovable extends DataProviderMethod { - - DataProviderMethodRemovable(Object instance, Method method, IDataProviderAnnotation annotation) { - super(instance, method, annotation); - } - - public void setInstance(Object instance) { - this.instance = instance; - } - - public void setMethod(Method method) { - this.method = method; - } -} diff --git a/testng-core/src/main/java/org/testng/internal/Parameters.java b/testng-core/src/main/java/org/testng/internal/Parameters.java index 079f45b734..16796c177c 100644 --- a/testng-core/src/main/java/org/testng/internal/Parameters.java +++ b/testng-core/src/main/java/org/testng/internal/Parameters.java @@ -641,7 +641,7 @@ private static IDataProviderMethod findDataProvider( } if (isDynamicDataProvider) { - result = new DataProviderMethodRemovable(instanceToUse, m, dp); + result = new DataProviderMethod(instanceToUse, m, dp, true); } else { result = new DataProviderMethod(instanceToUse, m, dp); } @@ -863,9 +863,9 @@ public void remove() { filteredParameters, dataProviderMethod, testMethod, methodParams.context); } - if (dataProviderMethod instanceof DataProviderMethodRemovable) { - ((DataProviderMethodRemovable) dataProviderMethod).setMethod(null); - ((DataProviderMethodRemovable) dataProviderMethod).setInstance(null); + if (dataProviderMethod.isDynamic()) { + ((DataProviderMethod) dataProviderMethod).setMethod(null); + ((DataProviderMethod) dataProviderMethod).setInstance(null); if (testMethod instanceof TestNGMethod) { ((TestNGMethod) testMethod).setDataProviderMethod(null); } diff --git a/testng-runner-api/src/main/java/org/testng/internal/LiteWeightTestNGMethod.java b/testng-runner-api/src/main/java/org/testng/internal/LiteWeightTestNGMethod.java index c5dee94eb4..39b849d6b8 100644 --- a/testng-runner-api/src/main/java/org/testng/internal/LiteWeightTestNGMethod.java +++ b/testng-runner-api/src/main/java/org/testng/internal/LiteWeightTestNGMethod.java @@ -144,6 +144,11 @@ public boolean isParallel() { return dp.isParallel(); } + @Override + public boolean isDynamic() { + return dp.isDynamic(); + } + @Override public List getIndices() { if (dp == null) {