Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.List;
import org.jspecify.annotations.Nullable;
import org.testng.ITestNGMethod;
import org.testng.annotations.IAnnotation;
import org.testng.internal.ConstructorOrMethod;
Expand All @@ -19,7 +20,7 @@ public interface IAnnotationFinder {
* @param <A> The expected {@link IAnnotation} type
* @return The annotation on the class or null if none found.
*/
<A extends IAnnotation> A findAnnotation(Class<?> cls, Class<A> annotationClass);
<A extends IAnnotation> @Nullable A findAnnotation(Class<?> cls, Class<A> annotationClass);

/**
* @param m - The corresponding {@link Method}
Expand All @@ -28,14 +29,15 @@ public interface IAnnotationFinder {
* @return The annotation on the method. If not found, return the annotation on the declaring
* class. If not found, return null.
*/
<A extends IAnnotation> A findAnnotation(Method m, Class<A> annotationClass);
<A extends IAnnotation> @Nullable A findAnnotation(Method m, Class<A> annotationClass);

<A extends IAnnotation> A findAnnotation(ITestNGMethod m, Class<A> annotationClass);
<A extends IAnnotation> @Nullable A findAnnotation(ITestNGMethod m, Class<A> annotationClass);

<A extends IAnnotation> A findAnnotation(ConstructorOrMethod com, Class<A> annotationClass);
<A extends IAnnotation> @Nullable A findAnnotation(
ConstructorOrMethod com, Class<A> annotationClass);

<A extends IAnnotation> A findAnnotation(
Class<?> clazz, Method m, java.lang.Class<A> annotationClass);
<A extends IAnnotation> @Nullable A findAnnotation(
@Nullable Class<?> clazz, Method m, java.lang.Class<A> annotationClass);

/**
* @param cons - The corresponding {@link Constructor}
Expand All @@ -44,7 +46,7 @@ <A extends IAnnotation> A findAnnotation(
* @return The annotation on the method. If not found, return the annotation on the declaring
* class. If not found, return null.
*/
<A extends IAnnotation> A findAnnotation(Constructor<?> cons, Class<A> annotationClass);
<A extends IAnnotation> @Nullable A findAnnotation(Constructor<?> cons, Class<A> annotationClass);

/**
* @param cls - The corresponding class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package org.testng.internal.annotations;

import org.jspecify.annotations.Nullable;

/** A trait shared by all the annotations that have dataProvider/dataProviderClass attributes. */
public interface IDataProvidable {
String getDataProvider();

void setDataProvider(String v);

/** @return The class holding the data provider, or {@code null} when none was named. */
@Nullable
Class<?> getDataProviderClass();

void setDataProviderClass(Class<?> v);
void setDataProviderClass(@Nullable Class<?> v);

String getDataProviderDynamicClass();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** Reads TestNG's annotations off classes, methods and constructors, and models what they say. */
@NullMarked
package org.testng.internal.annotations;

import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;
import org.jspecify.annotations.Nullable;
import org.testng.ITestNGMethod;
import org.testng.ITestObjectFactory;
import org.testng.annotations.IAnnotation;
Expand Down Expand Up @@ -63,27 +64,32 @@ private AnnotationHelper() {
// Utility class.defeat instantiation.
}

public static ITestAnnotation findTest(IAnnotationFinder finder, Class<?> cls) {
public static @Nullable ITestAnnotation findTest(IAnnotationFinder finder, Class<?> cls) {
return finder.findAnnotation(cls, ITestAnnotation.class);
}

public static ITestAnnotation findTest(IAnnotationFinder finder, Method m) {
public static @Nullable ITestAnnotation findTest(IAnnotationFinder finder, Method m) {
return finder.findAnnotation(m, ITestAnnotation.class);
}

public static ITestAnnotation findTest(IAnnotationFinder finder, ITestNGMethod m) {
public static @Nullable ITestAnnotation findTest(IAnnotationFinder finder, ITestNGMethod m) {
return finder.findAnnotation(m, ITestAnnotation.class);
}

public static IFactoryAnnotation findFactory(IAnnotationFinder finder, Method m) {
public static @Nullable IFactoryAnnotation findFactory(IAnnotationFinder finder, Method m) {
return finder.findAnnotation(m, IFactoryAnnotation.class);
}

public static IFactoryAnnotation findFactory(IAnnotationFinder finder, Constructor<?> c) {
public static @Nullable IFactoryAnnotation findFactory(
IAnnotationFinder finder, Constructor<?> c) {
return finder.findAnnotation(c, IFactoryAnnotation.class);
}

public static IConfigurationAnnotation findConfiguration(
/**
* @return The configuration annotation carried by the method, or {@code null} when it carries
* none.
*/
public static @Nullable IConfigurationAnnotation findConfiguration(
IAnnotationFinder finder, ConstructorOrMethod m) {
IConfigurationAnnotation result = null;
boolean ignoreFailure = false;
Expand Down Expand Up @@ -137,21 +143,22 @@ public static IConfigurationAnnotation findConfiguration(
return result;
}

public static IConfigurationAnnotation findConfiguration(IAnnotationFinder finder, Method m) {
public static @Nullable IConfigurationAnnotation findConfiguration(
IAnnotationFinder finder, Method m) {
return findConfiguration(finder, new ConstructorOrMethod(m));
}

private static IConfigurationAnnotation createConfiguration(
IConfigurationAnnotation bs,
IConfigurationAnnotation as,
IConfigurationAnnotation bt,
IConfigurationAnnotation at,
IConfigurationAnnotation bg,
IConfigurationAnnotation ag,
IConfigurationAnnotation bc,
IConfigurationAnnotation ac,
IConfigurationAnnotation bm,
IConfigurationAnnotation am) {
@Nullable IConfigurationAnnotation bs,
@Nullable IConfigurationAnnotation as,
@Nullable IConfigurationAnnotation bt,
@Nullable IConfigurationAnnotation at,
@Nullable IConfigurationAnnotation bg,
@Nullable IConfigurationAnnotation ag,
@Nullable IConfigurationAnnotation bc,
@Nullable IConfigurationAnnotation ac,
@Nullable IConfigurationAnnotation bm,
@Nullable IConfigurationAnnotation am) {
ConfigurationAnnotation result = new ConfigurationAnnotation();

if (bs != null) {
Expand Down Expand Up @@ -306,7 +313,7 @@ && isAnnotationPresent(annotationFinder, cls, ITestAnnotation.class)) {
return vResult.values().toArray(new ITestNGMethod[0]);
}

public static <A extends Annotation> A findAnnotationSuperClasses(
public static <A extends Annotation> @Nullable A findAnnotationSuperClasses(
Class<A> annotationClass, Class<?> parameterClass) {
Class<?> c = parameterClass;
while (c != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,31 @@

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import org.jspecify.annotations.Nullable;

public class BaseAnnotation {

private Class<?> m_testClass;
private Method m_method;
private Constructor m_constructor;
private @Nullable Class<?> m_testClass;
private @Nullable Method m_method;
private @Nullable Constructor m_constructor;

public Constructor getConstructor() {
public @Nullable Constructor getConstructor() {
return m_constructor;
}

public void setConstructor(Constructor constructor) {
m_constructor = constructor;
}

public Method getMethod() {
public @Nullable Method getMethod() {
return m_method;
}

public void setMethod(Method method) {
m_method = method;
}

public Class<?> getTestClass() {
public @Nullable Class<?> getTestClass() {
return m_testClass;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package org.testng.internal.annotations;

import org.jspecify.annotations.Nullable;

public class BaseBeforeAfter extends TestOrConfiguration implements IBaseBeforeAfter {

private boolean m_alwaysRun = false;
private boolean m_inheritGroups = true;
private String[] m_beforeGroups = {};
private String[] m_afterGroups = {};
private String m_description;
private @Nullable String m_description;

/** @return the description */
@Override
public String getDescription() {
public @Nullable String getDescription() {
return m_description;
}

/** @param description the description to set */
@Override
public void setDescription(String description) {
public void setDescription(@Nullable String description) {
m_description = description;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package org.testng.internal.annotations;

import java.util.Collections;
import java.util.List;
import org.testng.IRetryDataProvider;
import org.testng.annotations.IDataProviderAnnotation;

/** An implementation of IDataProvider. */
public class DataProviderAnnotation extends BaseAnnotation implements IDataProviderAnnotation {

private String m_name;
private String m_name = "";
private boolean m_parallel;
private List<Integer> m_indices;
private List<Integer> m_indices = Collections.emptyList();
private boolean m_bubbleUpFailures = false;
private Class<? extends IRetryDataProvider> retryUsing;
private Class<? extends IRetryDataProvider> retryUsing =
IRetryDataProvider.DisableDataProviderRetries.class;

private boolean cachedDataForTestRetries = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import org.jspecify.annotations.Nullable;
import org.testng.IAnnotationTransformer;
import org.testng.annotations.ITestAnnotation;

Expand All @@ -15,7 +16,11 @@ public void transform(

@Override
public void transform(
ITestAnnotation annotation, Class testClass, Constructor cons, Method tm, Class<?> clazz) {
ITestAnnotation annotation,
@Nullable Class testClass,
@Nullable Constructor cons,
@Nullable Method tm,
@Nullable Class<?> clazz) {
super.transform(annotation, testClass, cons, tm, clazz);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package org.testng.internal.annotations;

import java.util.List;
import org.jspecify.annotations.Nullable;
import org.testng.annotations.IFactoryAnnotation;
import org.testng.annotations.Lazy;

/** An implementation of IFactory */
public class FactoryAnnotation extends BaseAnnotation implements IFactoryAnnotation {

private String m_dataProvider = null;
private Class<?> m_dataProviderClass;
private String m_dataProviderDynamicClass;
private String m_dataProvider = "";
private @Nullable Class<?> m_dataProviderClass;
private String m_dataProviderDynamicClass = "";
private boolean m_enabled = true;
private List<Integer> m_indices;
private @Nullable List<Integer> m_indices;
private Lazy m_lazy = Lazy.UNSET;

@Override
Expand All @@ -24,12 +25,12 @@ public void setDataProvider(String dataProvider) {
m_dataProvider = dataProvider;
}

public void setDataProviderClass(Class<?> dataProviderClass) {
public void setDataProviderClass(@Nullable Class<?> dataProviderClass) {
m_dataProviderClass = dataProviderClass;
}

@Override
public Class<?> getDataProviderClass() {
public @Nullable Class<?> getDataProviderClass() {
return m_dataProviderClass;
}

Expand All @@ -54,7 +55,7 @@ public void setEnabled(boolean enabled) {
}

@Override
public List<Integer> getIndices() {
public @Nullable List<Integer> getIndices() {
return m_indices;
}

Expand All @@ -69,7 +70,7 @@ public Lazy getLazy() {
}

@Override
public void setLazy(Lazy lazy) {
public void setLazy(@Nullable Lazy lazy) {
m_lazy = lazy == null ? Lazy.UNSET : lazy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import org.jspecify.annotations.Nullable;
import org.testng.annotations.ITestAnnotation;

/** For backward compatibility. */
public interface IAnnotationTransformer extends org.testng.IAnnotationTransformer {

default void transform(
ITestAnnotation annotation,
Class testClass,
Constructor testConstructor,
Method testMethod,
Class<?> occurringClazz) {
@Nullable Class testClass,
@Nullable Constructor testConstructor,
@Nullable Method testMethod,
@Nullable Class<?> occurringClazz) {
// not implemented
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.testng.internal.annotations;

import org.jspecify.annotations.Nullable;
import org.testng.annotations.ITestOrConfiguration;

/** Base interface for IBeforeSuite, IAfterSuite, etc... */
Expand Down Expand Up @@ -46,6 +47,7 @@ public interface IBaseBeforeAfter extends ITestOrConfiguration {
* The description for this method. The string used will appear in the HTML report and also on
* standard output if verbose &gt; 2.
*/
@Nullable
String getDescription();

default boolean ignoreFailure() {
Expand Down
Loading
Loading