Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
- remove DataProviderMethodRemovable.java class
  add isDynamic flag to IDataProviderMethod
- remove excessive params
- fix Class raw usage
  • Loading branch information
Dzmitry Sankouski committed Mar 28, 2022
1 parent 561a432 commit 56f0713
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> getIndices();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ 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;
this.method = method;
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;
Expand All @@ -38,8 +46,21 @@ public boolean isParallel() {
return annotation.isParallel();
}

@Override
public boolean isDynamic() {
return isDynamic;
}

@Override
public List<Integer> getIndices() {
return annotation.getIndices();
}

public void setInstance(Object instance) {
this.instance = instance;
}

public void setMethod(Method method) {
this.method = method;
}
}

This file was deleted.

8 changes: 4 additions & 4 deletions testng-core/src/main/java/org/testng/internal/Parameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ public boolean isParallel() {
return dp.isParallel();
}

@Override
public boolean isDynamic() {
return dp.isDynamic();
}

@Override
public List<Integer> getIndices() {
if (dp == null) {
Expand Down

0 comments on commit 56f0713

Please sign in to comment.