From 44cbe7bcd67920437607207cc2abc3ea49ec2e23 Mon Sep 17 00:00:00 2001 From: Julien Herr Date: Wed, 29 Jul 2026 14:51:53 +0200 Subject: [PATCH 1/6] build: add OpenRewrite with a hand-curated recipe list Wire the OpenRewrite Gradle plugin at the root project and pin the recipe list in rewrite.yml. No source changes. The upstream composites are deliberately not activated. OpenRewrite offers no way to exclude a single sub-recipe from a composite -- exclusion() filters file paths only, and the upstream request is closed as won't-fix (openrewrite/rewrite#1714). Measured on src/main, CommonStaticAnalysis touches 101 files; about half overlaps with the list we want, and the rest comes from recipes that must not run here: ExplicitInitialization (46), FinalClass (12), FinalizePrivateFields (10), AbstractClassPublicConstructor (6) and ReplaceLambdaWithMethodReference (4) alter an OSGi-exported API with no binary-compatibility gate, or add final to fields TestNG writes reflectively. Java8toJava11 is rejected separately: it would add JAXB, JAX-WS, javax.inject and javax.annotation runtime dependencies to a library that deliberately has almost none. Two things make the setup behave: An ImportLayoutStyle matching google-java-format is declared, because OpenRewrite otherwise auto-detects a layout that groups java.*/javax.* separately. Measured, OrderImports rewrites 34 files under auto-detection and 1 with the style active. failOnDryRunResults is wired to a new failOnRewriteDryRun build parameter rather than hard-coded, so the CI gate is the Gradle task itself and ./gradlew rewriteDryRun -PfailOnRewriteDryRun=true reproduces it locally. This also requires build-logic.build-params at the root, which was not applied there. Scope is src/main only. Test sources are excluded because test/** mixes real tests with fixture classes whose method names, declaration order and finalize() presence are what the surrounding tests assert on, and because testng.xml references test classes by fully qualified name, so a moved class would silently drop tests. --- build-logic/build-parameters/build.gradle.kts | 4 + build.gradle.kts | 37 +++++ rewrite.yml | 134 ++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 rewrite.yml diff --git a/build-logic/build-parameters/build.gradle.kts b/build-logic/build-parameters/build.gradle.kts index b21bb37d6..54e546a27 100644 --- a/build-logic/build-parameters/build.gradle.kts +++ b/build-logic/build-parameters/build.gradle.kts @@ -51,6 +51,10 @@ buildParameters { defaultValue.set(true) description.set("Fail build on javadoc warnings") } + bool("failOnRewriteDryRun") { + defaultValue.set(false) + description.set("Fail rewriteDryRun when OpenRewrite still has changes to make") + } bool("skipErrorProne") { defaultValue.set(false) description.set("Skip Error Prone verifications") diff --git a/build.gradle.kts b/build.gradle.kts index 7911ddba5..b32abc4f1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,44 @@ plugins { id("testng.repositories") + id("build-logic.build-params") id("idea") id("com.gradleup.nmcp.aggregation") version "1.6.1" + id("org.openrewrite.rewrite") version "7.37.0" +} + +dependencies { + rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:3.35.0")) + rewrite("org.openrewrite.recipe:rewrite-static-analysis") + rewrite("org.openrewrite.recipe:rewrite-migrate-java") +} + +rewrite { + // The recipe list lives in rewrite.yml, which documents why the upstream composites + // (CommonStaticAnalysis, CodeCleanup, Java8toJava11) are not used directly. + activeRecipe("org.testng.build.ModernizeMainSources") + + // Makes OpenRewrite lay imports out the way google-java-format does, so its output does not + // have to be corrected by autostyleApply. rewrite.yml explains the measurement behind this. + activeStyle("org.testng.build.ImportLayout") + + // exclusion() matches file paths, not recipe names. + exclusion( + // Test sources are out of scope: test/** mixes real tests with fixture classes whose + // method names, declaration order and finalize() presence are what the surrounding + // tests assert on, and testng.xml references test classes by FQN. + "**/src/test/**", + // Nothing here rewrites build scripts, and .gradle.kts would be routed to the + // experimental Kotlin parser for no benefit. This also covers build-logic/ and + // build-logic-commons/, whose tracked files are all .kt or .gradle.kts. + "**/*.gradle.kts", + "**/*.kt", + "**/*.groovy", + ) + + // rewriteDryRun is a manual maintenance task by default. CI turns this on so the gate is + // the Gradle task itself, which means ./gradlew rewriteDryRun -PfailOnRewriteDryRun=true + // reproduces the CI check exactly. + failOnDryRunResults = buildParameters.failOnRewriteDryRun } val String.v: String get() = rootProject.extra["$this.version"] as String diff --git a/rewrite.yml b/rewrite.yml new file mode 100644 index 000000000..7efccd369 --- /dev/null +++ b/rewrite.yml @@ -0,0 +1,134 @@ +# +# OpenRewrite recipe list for TestNG. +# +# The upstream composites (org.openrewrite.staticanalysis.CommonStaticAnalysis, +# org.openrewrite.staticanalysis.CodeCleanup and org.openrewrite.java.migrate.Java8toJava11) +# are deliberately NOT activated. OpenRewrite has no mechanism to exclude a single sub-recipe +# from a composite -- exclusion() filters file paths only, and the upstream request to support +# recipe exclusion (openrewrite/rewrite#1714) is closed as won't-fix. +# +# Measured on src/main with the import layout below active, CommonStaticAnalysis touches 101 +# files. Roughly half of that overlaps with the list below and is wanted; the rest comes from +# recipes we must not run: +# +# ExplicitInitialization 46 field-declaration churn, no benefit +# FinalClass 12 adds final to OSGi-exported classes +# FinalizePrivateFields 10 adds final to fields TestNG writes reflectively +# AbstractClassPublicConstructor 6 narrows constructors on OSGi-exported classes +# ReplaceLambdaWithMethodReference 4 changes synthetic class shape +# SimplifyBooleanExpression 2 unsound on float comparisons, see the note further down +# OrderImports 1 fights google-java-format; see the style block below +# +# There is no binary-compatibility gate (no japicmp/revapi) protecting the exported +# org.testng.* packages, and TestNG resolves members reflectively, so the API- and +# reflection-affecting recipes are disqualifying on their own. Java8toJava11 is rejected +# separately: it would add JAXB, JAX-WS, javax.inject and javax.annotation runtime +# dependencies and rewrite the Java version in .github/workflows/*.yml. +# +# So the sub-recipes we want are copied out by hand below. +# +# Scope: src/main only. See the exclusion() block in build.gradle.kts. +# +--- +# Import layout, declared so OpenRewrite agrees with the google-java-format output that +# Autostyle enforces: static imports first, one blank line, then everything else in a single +# ASCII-sorted block, never folded into star imports. This matches .editorconfig's +# ij_java_imports_layout = $*,|,* and its two import-on-demand thresholds (lines 34-35). +# +# This is not cosmetic. OpenRewrite otherwise auto-detects a layout from the sources and infers +# one that groups java.*/javax.* separately, which disagrees with google-java-format: measured +# over src/main, OrderImports rewrites 34 files under auto-detection and 1 with this style active. +# Declaring it keeps rewrite output already-formatted, so autostyleApply only has to tidy up, and +# it keeps rewriteDryRun honest as an idempotency check. +type: specs.openrewrite.org/v1beta/style +name: org.testng.build.ImportLayout +styleConfigs: + - org.openrewrite.java.style.ImportLayoutStyle: + classCountToUseStarImport: 999 + nameCountToUseStarImport: 999 + layout: + - 'import static all other imports' + - '' + - 'import all other imports' + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.testng.build.ModernizeMainSources +displayName: TestNG main-source modernization +description: >- + Hand-picked sub-recipes, grouped below from least to most intrusive. Recipes that matched + nothing are kept so a future contribution is covered by the same list. +recipeList: + # --- Syntactic normalization. No intended behaviour change. --- + - org.openrewrite.staticanalysis.NeedBraces + - org.openrewrite.staticanalysis.UnnecessaryParentheses + - org.openrewrite.staticanalysis.MultipleVariableDeclarations + - org.openrewrite.staticanalysis.ModifierOrder + - org.openrewrite.staticanalysis.RemoveExtraSemicolons + - org.openrewrite.staticanalysis.UseDiamondOperator + - org.openrewrite.staticanalysis.UnnecessaryExplicitTypeArguments + - org.openrewrite.staticanalysis.UseJavaStyleArrayDeclarations + - org.openrewrite.staticanalysis.UpperCaseLiteralSuffixes + - org.openrewrite.staticanalysis.WriteOctalValuesAsDecimal + + # --- Semantics-preserving library-call modernization. Includes the source-only leaves of + # Java8toJava11; its build-file and dependency-adding halves are omitted. --- + # String handling + - org.openrewrite.staticanalysis.EqualsAvoidsNull + - org.openrewrite.staticanalysis.StringLiteralEquality + - org.openrewrite.staticanalysis.NoToStringOnStringType + - org.openrewrite.staticanalysis.NoValueOfOnStringType + - org.openrewrite.staticanalysis.ReplaceStringConcatenationWithStringValueOf + - org.openrewrite.staticanalysis.CaseInsensitiveComparisonsDoNotChangeCase + - org.openrewrite.staticanalysis.IndexOfReplaceableByContains + - org.openrewrite.staticanalysis.IndexOfChecksShouldUseAStartPosition + - org.openrewrite.staticanalysis.IndexOfShouldNotCompareGreaterThanZero + # StringBuilder + - org.openrewrite.staticanalysis.ChainStringBuilderAppendCalls + - org.openrewrite.staticanalysis.NewStringBuilderBufferWithCharArgument + - org.openrewrite.staticanalysis.ReplaceStringBuilderWithString + # Collections + - org.openrewrite.staticanalysis.IsEmptyCallOnCollections + - org.openrewrite.staticanalysis.CollectionToArrayShouldHaveProperType + - org.openrewrite.staticanalysis.NoDoubleBraceInitialization + - org.openrewrite.staticanalysis.NoEmptyCollectionWithRawType + - org.openrewrite.staticanalysis.SimplifyArraysAsList + - org.openrewrite.staticanalysis.UseMapContainsKey + # Boxing / numerics + - org.openrewrite.staticanalysis.NoPrimitiveWrappersForToStringOrCompareTo + - org.openrewrite.staticanalysis.PrimitiveWrapperClassConstructorToValueOf + - org.openrewrite.staticanalysis.BigDecimalDoubleConstructorRecipe + - org.openrewrite.staticanalysis.AtomicPrimitiveEqualsUsesGet + # Misc + - org.openrewrite.staticanalysis.RedundantFileCreation + - org.openrewrite.staticanalysis.RemoveRedundantNullCheckBeforeInstanceof + - org.openrewrite.staticanalysis.RemoveRedundantNullCheckBeforeLiteralEquals + # Java 8 -> Java 11 API equivalents + - org.openrewrite.java.migrate.nio.file.PathsGetToPathOf + - org.openrewrite.java.migrate.nio.file.RedundantUtf8Charset + - org.openrewrite.java.migrate.lang.JavaLangAPIs + - org.openrewrite.java.migrate.net.JavaNetAPIs + - org.openrewrite.java.migrate.concurrent.JavaConcurrentAPIs + - org.openrewrite.java.migrate.util.OptionalNotPresentToIsEmpty + - org.openrewrite.java.migrate.util.OptionalNotEmptyToIsPresent + - org.openrewrite.java.migrate.util.UsePredicateNot + - org.openrewrite.java.migrate.UseJavaUtilBase64 + - org.openrewrite.java.migrate.CastArraysAsListToList + + # --- Boolean and control-flow simplification. Read these hunks, do not skim them. --- + # + # SimplifyBooleanExpression and BooleanChecksNotInverted are deliberately NOT enabled: both + # rewrite `!(a <= b)` to `a > b`, which is not equivalent for NaN, where every comparison is + # false, so the negated form fails an assertion as intended while the `>` form silently passes. + # + # The assertion code that made this concrete -- AssertJUnit.assertEquals(double, double, double) + # and Assert.areEqual -- has since moved to the separate org.testng:testng-asserts artifact, and + # a dry-run today shows SimplifyBooleanExpression touching only two benign isEmpty() ternaries. + # They stay excluded anyway: the gain is cosmetic, while enabling them would put a rewrite that + # is unsound on floating-point comparisons behind a CI gate that rewrites new code automatically. + - org.openrewrite.staticanalysis.SimplifyBooleanReturn + - org.openrewrite.staticanalysis.NoRedundantJumpStatements + - org.openrewrite.staticanalysis.UnnecessaryReturnAsLastStatement + - org.openrewrite.staticanalysis.InlineVariable + - org.openrewrite.staticanalysis.NoEqualityInForCondition + - org.openrewrite.staticanalysis.ForLoopIncrementInUpdate From 4779603d4d5c6a07663a7c512aa7580c51e1ddb9 Mon Sep 17 00:00:00 2001 From: Julien Herr Date: Wed, 29 Jul 2026 14:51:53 +0200 Subject: [PATCH 2/6] build: make the skipAutostyle build parameter actually work skipAutostyle has been declared in build-parameters since it was introduced, but nothing ever read it: testng.java applied testng.style unconditionally from its plugins block. Passing -PskipAutostyle=true therefore did nothing at all, while the neighbouring -PskipErrorProne=true worked, because that one is applied conditionally at the bottom of the same file. Apply testng.style the same way Error Prone is applied, so the two parameters behave consistently. Verified by appending a deliberate formatting violation to a source file: ./gradlew :testng-collections:check -PskipAutostyle=true -> passes (was: failed) ./gradlew :testng-collections:check -> fails on the violation Note this means the autostyle tasks do not exist when the parameter is set, so invoking autostyleCheck explicitly alongside it fails with "task not found". That matches how skipErrorProne already behaves; the parameter is meant for whole-build invocations such as ./gradlew build -PskipAutostyle=true. --- build-logic/jvm/src/main/kotlin/testng.java.gradle.kts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build-logic/jvm/src/main/kotlin/testng.java.gradle.kts b/build-logic/jvm/src/main/kotlin/testng.java.gradle.kts index 361ad11b4..96e498b9e 100644 --- a/build-logic/jvm/src/main/kotlin/testng.java.gradle.kts +++ b/build-logic/jvm/src/main/kotlin/testng.java.gradle.kts @@ -4,7 +4,6 @@ plugins { `java-base` id("build-logic.build-params") id("testng.versioning") - id("testng.style") id("testng.repositories") // Improves Gradle Test logging // See https://github.com/vlsi/vlsi-release-plugins/tree/master/plugins/gradle-extensions-plugin @@ -43,6 +42,10 @@ tasks.configureEach { inputs.property("java.vm.vendor", System.getProperty("java.vm.vendor")) } +if (!buildParameters.skipAutostyle) { + apply(plugin = "testng.style") +} + if (!buildParameters.skipErrorProne) { apply(plugin = "testng.errorprone") } From 4b47975cb559fc1aeb79b0bd2e6e94e2b6a45e5a Mon Sep 17 00:00:00 2001 From: Julien Herr Date: Wed, 29 Jul 2026 14:52:10 +0200 Subject: [PATCH 3/6] ci: fail the build when OpenRewrite still has changes to make Without a gate the cleanup decays: the next pull request reintroduces the idioms the recipes just removed, and nothing notices. The gate is the Gradle task, not shell glue -- the job passes failOnRewriteDryRun=true, so ./gradlew rewriteDryRun -PfailOnRewriteDryRun=true reproduces it exactly. The shell step only summarises the patch on failure, and the full patch is uploaded as an artifact. Design notes: * It is its own job, not part of the build matrix, which produces 8 jobs across OS/JDK/timezone/locale. It has no "needs", so it starts immediately and runs alongside the matrix; wall-clock impact is nil. * rewriteDryRun stays out of check/build, so a normal local build is unaffected. * compileTestJava/compileTestKotlin are excluded. rewriteDryRun dependsOn every source set's compileJava, but test sources are excluded from rewriting, so compiling them feeds nothing into the LST. Error Prone is skipped for the same reason -- it is a javac plugin OpenRewrite never sees, and the matrix runs it. Measured roughly 86s -> 41s locally, with the gate still failing on drift. * -Xmx3g is provisioned: rewriteDryRun builds a type-attributed LST of every main source file and OOMed once under Gradle's default heap. One caveat worth stating: this trains contributors to run rewriteRun to make CI green. That is only acceptable because the recipe list is curated and each entry was reviewed -- a hard gate on a composite recipe would be teaching people to apply unreviewed semantic rewrites. --- .github/workflows/test.yml | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fabcfbb23..83398d3a0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,6 +37,58 @@ jobs: npm ci --prefix .github/workflows node .github/workflows/matrix.mjs + rewrite: + name: 'OpenRewrite' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + fetch-depth: 1 + - name: Set up Java 25 + uses: actions/setup-java@03ad4de0992f5dab5e18fcb136590ce7c4a0ac95 # v5 + with: + java-version: 25 + distribution: temurin + architecture: x64 + # The gate is the Gradle task itself, so this is reproducible locally with + # ./gradlew rewriteDryRun -PfailOnRewriteDryRun=true + - name: Check the OpenRewrite recipes leave nothing to do + uses: burrunan/gradle-cache-action@4b67497abd37a511d6c1dc6299bdd84ff39f7bf5 # v3 + with: + job-id: rewrite + # Test sources are excluded from rewriting, so compiling them feeds nothing into the + # LST -- skipping them is most of this job's runtime. Error Prone is a javac plugin + # that OpenRewrite never sees, and the build matrix already runs it. + arguments: | + --no-daemon + rewriteDryRun + -x compileTestJava + -x compileTestKotlin + properties: | + jdkBuildVersion=25 + failOnRewriteDryRun=true + skipErrorProne=true + # rewriteDryRun builds a type-attributed LST of every main source file, which needs + # noticeably more heap than Gradle's default. + org.gradle.jvmargs=-Xmx3g + org.gradle.java.installations.auto-download=false + - name: Summarise the patch + if: ${{ failure() }} + run: | + patch=build/reports/rewrite/rewrite.patch + [ -s "$patch" ] || exit 0 + echo "::error::OpenRewrite would still change these files. Run './gradlew rewriteRun', then './gradlew autostyleApply', review the diff and commit it." + git apply --stat "$patch" + echo "The full patch is attached as the 'rewrite-patch' artifact." + - name: Upload the patch + if: ${{ failure() }} + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 + with: + name: rewrite-patch + path: build/reports/rewrite/rewrite.patch + if-no-files-found: ignore + build: needs: matrix_prep runs-on: ${{ matrix.os }} From 63ef1807602726c613f41073b6541c5186eabed7 Mon Sep 17 00:00:00 2001 From: Julien Herr Date: Wed, 29 Jul 2026 14:52:10 +0200 Subject: [PATCH 4/6] refactor: apply the OpenRewrite recipes to the main sources Apply org.testng.build.ModernizeMainSources, then ./gradlew autostyleApply so google-java-format has the last word on formatting. 45 files, all under src/main. Recipes that matched: NeedBraces 22 UnnecessaryParentheses 22 InlineVariable 11 EqualsAvoidsNull 3 RemoveExtraSemicolons 2 MultipleVariableDeclarations 1 ReplaceStringConcatenationWithStringValueOf 1 org.openrewrite.java.migrate.nio.file.RedundantUtf8Charset 1 The other 44 recipes in the list matched nothing. That is the honest yield: the Java 8 to Java 11 API migration is worth exactly one file, because this codebase was already clean of the idioms those recipes target. Notes on the hunks that are not purely syntactic: EqualsAvoidsNull flips "value.equals(LITERAL)" to "LITERAL.equals(value)". Where value is null this yields false instead of throwing NullPointerException; every call site here is a filter predicate or a branch condition where false is the correct answer, and in one case it subsumes an explicit null check. UnnecessaryParentheses only drops parentheses redundant within their own expression, keeping the grouping pair, so "a + ((x == null) ? 0 : y)" becomes "a + (x == null ? 0 : y)" rather than losing precedence. RedundantUtf8Charset drops the explicit UTF_8 argument from Files.newBufferedWriter, which documents UTF-8 as its default. No test source and no build script is touched, so the set of executed tests is structurally unchanged. Full build green: 12624 tests, 0 failures. --- .../java/org/testng/collections/Objects.java | 8 +- .../testng/internal/AutoCloseableLock.java | 8 +- .../testng/internal/ConstructorOrMethod.java | 7 +- .../internal/KeyAwareAutoCloseableLock.java | 8 +- .../main/java/org/testng/internal/Utils.java | 3 +- .../testng/reporters/FileStringBuffer.java | 8 +- .../java/org/testng/reporters/XMLUtils.java | 4 +- .../main/java/org/testng/xml/XmlClass.java | 25 +++- .../main/java/org/testng/xml/XmlDefine.java | 3 +- .../main/java/org/testng/xml/XmlInclude.java | 33 +++-- .../org/testng/xml/XmlMethodSelector.java | 42 ++++-- .../main/java/org/testng/xml/XmlPackage.java | 53 +++++-- .../main/java/org/testng/xml/XmlSuite.java | 94 +++++++----- .../src/main/java/org/testng/xml/XmlTest.java | 140 ++++++++++++------ .../src/main/java/org/testng/Converter.java | 4 +- .../main/java/org/testng/JarFileUtils.java | 4 +- .../src/main/java/org/testng/SuiteRunner.java | 2 +- .../src/main/java/org/testng/TestRunner.java | 7 +- .../testng/internal/ClassBasedWrapper.java | 8 +- .../java/org/testng/internal/IObject.java | 8 +- .../org/testng/internal/MethodHelper.java | 5 +- .../org/testng/internal/MethodInstance.java | 8 +- .../java/org/testng/internal/Parameters.java | 9 +- .../testng/internal/TestNGClassFinder.java | 4 +- .../testng/internal/WrappedTestNGMethod.java | 2 +- .../testng/internal/XmlMethodSelector.java | 4 +- .../main/java/org/testng/internal/Yaml.java | 4 +- .../annotations/AnnotationHelper.java | 2 +- .../org/testng/internal/collections/Pair.java | 5 +- .../internal/invokers/ConfigInvoker.java | 2 +- .../internal/invokers/MethodRunner.java | 2 +- .../internal/invokers/ParameterHandler.java | 4 +- .../testng/internal/objects/GuiceHelper.java | 3 +- .../internal/objects/ObjectFactoryImpl.java | 2 +- .../internal/reflect/ReflectionRecipes.java | 20 ++- .../testng/reporters/EmailableReporter2.java | 26 ++-- .../testng/reporters/JUnitReportReporter.java | 2 +- .../testng/reporters/MethodInvocationKey.java | 4 +- .../testng/reporters/SuiteHTMLReporter.java | 2 +- .../org/testng/reporters/VerboseReporter.java | 2 +- .../java/org/testng/reporters/jq/Model.java | 4 +- .../testng/reporters/jq/NavigatorPanel.java | 2 +- .../testng/reporters/jq/TestNgXmlPanel.java | 4 +- .../org/testng/xml/TestNGContentHandler.java | 9 +- .../internal/LiteWeightTestNGMethod.java | 12 +- 45 files changed, 394 insertions(+), 218 deletions(-) diff --git a/testng-collections/src/main/java/org/testng/collections/Objects.java b/testng-collections/src/main/java/org/testng/collections/Objects.java index 2e0afbef0..9275efdbd 100644 --- a/testng-collections/src/main/java/org/testng/collections/Objects.java +++ b/testng-collections/src/main/java/org/testng/collections/Objects.java @@ -69,8 +69,12 @@ public String toString() { StringBuilder result = new StringBuilder("[" + m_className + " "); for (int i = 0; i < values.size(); i++) { ValueHolder vh = values.get(i); - if (m_omitNulls && vh.isNull()) continue; - if (m_omitEmptyStrings && vh.isEmptyString()) continue; + if (m_omitNulls && vh.isNull()) { + continue; + } + if (m_omitEmptyStrings && vh.isEmptyString()) { + continue; + } if (i > 0) { result.append(" "); diff --git a/testng-core-api/src/main/java/org/testng/internal/AutoCloseableLock.java b/testng-core-api/src/main/java/org/testng/internal/AutoCloseableLock.java index 213d6d04c..c5e821ba0 100644 --- a/testng-core-api/src/main/java/org/testng/internal/AutoCloseableLock.java +++ b/testng-core-api/src/main/java/org/testng/internal/AutoCloseableLock.java @@ -28,8 +28,12 @@ public void close() { @Override public boolean equals(Object object) { - if (this == object) return true; - if (object == null || getClass() != object.getClass()) return false; + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } AutoCloseableLock that = (AutoCloseableLock) object; return Objects.equals(internalLock, that.internalLock); } diff --git a/testng-core-api/src/main/java/org/testng/internal/ConstructorOrMethod.java b/testng-core-api/src/main/java/org/testng/internal/ConstructorOrMethod.java index fcdd85b3d..d45efdf85 100644 --- a/testng-core-api/src/main/java/org/testng/internal/ConstructorOrMethod.java +++ b/testng-core-api/src/main/java/org/testng/internal/ConstructorOrMethod.java @@ -86,8 +86,11 @@ public boolean getEnabled() { @Override public String toString() { - if (m_method != null) return m_method.toString(); - else return m_constructor.toString(); + if (m_method != null) { + return m_method.toString(); + } else { + return m_constructor.toString(); + } } public String stringifyParameterTypes() { diff --git a/testng-core-api/src/main/java/org/testng/internal/KeyAwareAutoCloseableLock.java b/testng-core-api/src/main/java/org/testng/internal/KeyAwareAutoCloseableLock.java index 9b9df2b66..0f09e3dc0 100644 --- a/testng-core-api/src/main/java/org/testng/internal/KeyAwareAutoCloseableLock.java +++ b/testng-core-api/src/main/java/org/testng/internal/KeyAwareAutoCloseableLock.java @@ -37,8 +37,12 @@ public void close() { @Override public boolean equals(Object object) { - if (this == object) return true; - if (object == null || getClass() != object.getClass()) return false; + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } AutoReleasable that = (AutoReleasable) object; return Objects.equals(lock, that.lock); } diff --git a/testng-core-api/src/main/java/org/testng/internal/Utils.java b/testng-core-api/src/main/java/org/testng/internal/Utils.java index fbcf6cf91..bd9ddfb72 100644 --- a/testng-core-api/src/main/java/org/testng/internal/Utils.java +++ b/testng-core-api/src/main/java/org/testng/internal/Utils.java @@ -69,8 +69,7 @@ public static void setVerbose(int n) { public static void writeUtf8File( @Nullable String outputDir, String fileName, XMLStringBuffer xsb, String prefix) { try { - final File outDir = - (outputDir != null) ? new File(outputDir) : new File("").getAbsoluteFile(); + final File outDir = outputDir != null ? new File(outputDir) : new File("").getAbsoluteFile(); if (!outDir.exists()) { boolean ignored = outDir.mkdirs(); } diff --git a/testng-core-api/src/main/java/org/testng/reporters/FileStringBuffer.java b/testng-core-api/src/main/java/org/testng/reporters/FileStringBuffer.java index d0ae07bd4..96e9bc47f 100644 --- a/testng-core-api/src/main/java/org/testng/reporters/FileStringBuffer.java +++ b/testng-core-api/src/main/java/org/testng/reporters/FileStringBuffer.java @@ -92,13 +92,17 @@ private static void copy(Reader input, Writer output) throws IOException { char[] buf = new char[MAX]; while (true) { int length = input.read(buf); - if (length < 0) break; + if (length < 0) { + break; + } output.write(buf, 0, length); } } private void flushToFile() { - if (m_sb.length() == 0) return; + if (m_sb.length() == 0) { + return; + } if (m_file == null) { try { diff --git a/testng-core-api/src/main/java/org/testng/reporters/XMLUtils.java b/testng-core-api/src/main/java/org/testng/reporters/XMLUtils.java index 6f29acdc6..07ec36eab 100644 --- a/testng-core-api/src/main/java/org/testng/reporters/XMLUtils.java +++ b/testng-core-api/src/main/java/org/testng/reporters/XMLUtils.java @@ -43,7 +43,9 @@ public static String xml( } public static String extractComment(String tag, Properties properties) { - if (properties == null || "span".equals(tag)) return null; + if (properties == null || "span".equals(tag)) { + return null; + } String[] attributes = new String[] {"id", "name", "class"}; for (String a : attributes) { diff --git a/testng-core-api/src/main/java/org/testng/xml/XmlClass.java b/testng-core-api/src/main/java/org/testng/xml/XmlClass.java index 5ce678579..db6099391 100644 --- a/testng-core-api/src/main/java/org/testng/xml/XmlClass.java +++ b/testng-core-api/src/main/java/org/testng/xml/XmlClass.java @@ -77,7 +77,9 @@ private void loadClass() { /** @return Returns the className. */ public Class getSupportClass() { - if (m_class == null) loadClass(); + if (m_class == null) { + loadClass(); + } return m_class; } @@ -202,11 +204,10 @@ public void setIndex(int index) { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((m_class == null) ? 0 : m_class.hashCode()); + result = prime * result + (m_class == null ? 0 : m_class.hashCode()); result = prime * result + (m_loadClasses ? 1 : 0); result = prime * result + m_index; - result = prime * result + ((m_name == null) ? 0 : m_name.hashCode()); - return result; + return prime * result + (m_name == null ? 0 : m_name.hashCode()); } @Override @@ -214,15 +215,23 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj == null) return XmlSuite.f(); - if (getClass() != obj.getClass()) return XmlSuite.f(); + if (obj == null) { + return XmlSuite.f(); + } + if (getClass() != obj.getClass()) { + return XmlSuite.f(); + } XmlClass other = (XmlClass) obj; if (other.m_loadClasses != m_loadClasses) { return XmlSuite.f(); } if (m_name == null) { - if (other.m_name != null) return XmlSuite.f(); - } else if (!m_name.equals(other.m_name)) return XmlSuite.f(); + if (other.m_name != null) { + return XmlSuite.f(); + } + } else if (!m_name.equals(other.m_name)) { + return XmlSuite.f(); + } return true; } diff --git a/testng-core-api/src/main/java/org/testng/xml/XmlDefine.java b/testng-core-api/src/main/java/org/testng/xml/XmlDefine.java index ea74ff06e..d09e4922b 100644 --- a/testng-core-api/src/main/java/org/testng/xml/XmlDefine.java +++ b/testng-core-api/src/main/java/org/testng/xml/XmlDefine.java @@ -63,7 +63,6 @@ public boolean equals(Object o) { @Override public int hashCode() { int result = m_name != null ? m_name.hashCode() : 0; - result = 31 * result + (m_includes != null ? m_includes.hashCode() : 0); - return result; + return 31 * result + (m_includes != null ? m_includes.hashCode() : 0); } } diff --git a/testng-core-api/src/main/java/org/testng/xml/XmlInclude.java b/testng-core-api/src/main/java/org/testng/xml/XmlInclude.java index f93381e90..e3a26b88b 100644 --- a/testng-core-api/src/main/java/org/testng/xml/XmlInclude.java +++ b/testng-core-api/src/main/java/org/testng/xml/XmlInclude.java @@ -96,24 +96,37 @@ public int hashCode() { final int prime = 31; int result = 1; result = prime * result + m_index; - result = prime * result + ((m_invocationNumbers == null) ? 0 : m_invocationNumbers.hashCode()); + result = prime * result + (m_invocationNumbers == null ? 0 : m_invocationNumbers.hashCode()); result = prime * result + m_parameters.hashCode(); - result = prime * result + ((m_name == null) ? 0 : m_name.hashCode()); - return result; + return prime * result + (m_name == null ? 0 : m_name.hashCode()); } @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return XmlSuite.f(); - if (getClass() != obj.getClass()) return XmlSuite.f(); + if (this == obj) { + return true; + } + if (obj == null) { + return XmlSuite.f(); + } + if (getClass() != obj.getClass()) { + return XmlSuite.f(); + } XmlInclude other = (XmlInclude) obj; if (m_invocationNumbers == null) { - if (other.m_invocationNumbers != null) return XmlSuite.f(); - } else if (!m_invocationNumbers.equals(other.m_invocationNumbers)) return XmlSuite.f(); + if (other.m_invocationNumbers != null) { + return XmlSuite.f(); + } + } else if (!m_invocationNumbers.equals(other.m_invocationNumbers)) { + return XmlSuite.f(); + } if (m_name == null) { - if (other.m_name != null) return XmlSuite.f(); - } else if (!m_name.equals(other.m_name)) return XmlSuite.f(); + if (other.m_name != null) { + return XmlSuite.f(); + } + } else if (!m_name.equals(other.m_name)) { + return XmlSuite.f(); + } if (!m_parameters.equals(other.m_parameters)) { return XmlSuite.f(); } diff --git a/testng-core-api/src/main/java/org/testng/xml/XmlMethodSelector.java b/testng-core-api/src/main/java/org/testng/xml/XmlMethodSelector.java index be7ac5feb..e63228d61 100644 --- a/testng-core-api/src/main/java/org/testng/xml/XmlMethodSelector.java +++ b/testng-core-api/src/main/java/org/testng/xml/XmlMethodSelector.java @@ -79,46 +79,58 @@ public String toXml(String indent) { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((m_className == null) ? 0 : m_className.hashCode()); + result = prime * result + (m_className == null ? 0 : m_className.hashCode()); if (getScript() != null) { result = prime * result - + ((getScript().getExpression() == null) - ? 0 - : getScript().getExpression().hashCode()); + + (getScript().getExpression() == null ? 0 : getScript().getExpression().hashCode()); result = prime * result - + ((getScript().getLanguage() == null) ? 0 : getScript().getLanguage().hashCode()); + + (getScript().getLanguage() == null ? 0 : getScript().getLanguage().hashCode()); } - result = prime * result + m_priority; - return result; + return prime * result + m_priority; } @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return XmlSuite.f(); - if (getClass() != obj.getClass()) return XmlSuite.f(); + if (this == obj) { + return true; + } + if (obj == null) { + return XmlSuite.f(); + } + if (getClass() != obj.getClass()) { + return XmlSuite.f(); + } XmlMethodSelector other = (XmlMethodSelector) obj; if (m_className == null) { - if (other.m_className != null) return XmlSuite.f(); - } else if (!m_className.equals(other.m_className)) return XmlSuite.f(); + if (other.m_className != null) { + return XmlSuite.f(); + } + } else if (!m_className.equals(other.m_className)) { + return XmlSuite.f(); + } if (getScript() == null || getScript().getExpression() == null) { - if (other.getScript() != null && other.getScript().getExpression() != null) + if (other.getScript() != null && other.getScript().getExpression() != null) { return XmlSuite.f(); + } } else if (!getScript() .getExpression() .equals(other.getScript() == null ? null : other.getScript().getExpression())) { return XmlSuite.f(); } if (getScript() == null || getScript().getLanguage() == null) { - if (other.getScript() != null && other.getScript().getLanguage() != null) return XmlSuite.f(); + if (other.getScript() != null && other.getScript().getLanguage() != null) { + return XmlSuite.f(); + } } else if (!getScript() .getLanguage() .equals(other.getScript() == null ? null : other.getScript().getLanguage())) { return XmlSuite.f(); } - if (m_priority != other.m_priority) return XmlSuite.f(); + if (m_priority != other.m_priority) { + return XmlSuite.f(); + } return true; } } diff --git a/testng-core-api/src/main/java/org/testng/xml/XmlPackage.java b/testng-core-api/src/main/java/org/testng/xml/XmlPackage.java index db5a5c2e8..b4a9ca27e 100644 --- a/testng-core-api/src/main/java/org/testng/xml/XmlPackage.java +++ b/testng-core-api/src/main/java/org/testng/xml/XmlPackage.java @@ -109,31 +109,52 @@ public String toXml(String indent) { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((m_exclude == null) ? 0 : m_exclude.hashCode()); - result = prime * result + ((m_include == null) ? 0 : m_include.hashCode()); - result = prime * result + ((m_name == null) ? 0 : m_name.hashCode()); - result = prime * result + ((m_xmlClasses == null) ? 0 : m_xmlClasses.hashCode()); - return result; + result = prime * result + (m_exclude == null ? 0 : m_exclude.hashCode()); + result = prime * result + (m_include == null ? 0 : m_include.hashCode()); + result = prime * result + (m_name == null ? 0 : m_name.hashCode()); + return prime * result + (m_xmlClasses == null ? 0 : m_xmlClasses.hashCode()); } @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return XmlSuite.f(); - if (getClass() != obj.getClass()) return XmlSuite.f(); + if (this == obj) { + return true; + } + if (obj == null) { + return XmlSuite.f(); + } + if (getClass() != obj.getClass()) { + return XmlSuite.f(); + } XmlPackage other = (XmlPackage) obj; if (m_exclude == null) { - if (other.m_exclude != null) return XmlSuite.f(); - } else if (!m_exclude.equals(other.m_exclude)) return XmlSuite.f(); + if (other.m_exclude != null) { + return XmlSuite.f(); + } + } else if (!m_exclude.equals(other.m_exclude)) { + return XmlSuite.f(); + } if (m_include == null) { - if (other.m_include != null) return XmlSuite.f(); - } else if (!m_include.equals(other.m_include)) return XmlSuite.f(); + if (other.m_include != null) { + return XmlSuite.f(); + } + } else if (!m_include.equals(other.m_include)) { + return XmlSuite.f(); + } if (m_name == null) { - if (other.m_name != null) return XmlSuite.f(); - } else if (!m_name.equals(other.m_name)) return XmlSuite.f(); + if (other.m_name != null) { + return XmlSuite.f(); + } + } else if (!m_name.equals(other.m_name)) { + return XmlSuite.f(); + } if (m_xmlClasses == null) { - if (other.m_xmlClasses != null) return XmlSuite.f(); - } else if (!m_xmlClasses.equals(other.m_xmlClasses)) return XmlSuite.f(); + if (other.m_xmlClasses != null) { + return XmlSuite.f(); + } + } else if (!m_xmlClasses.equals(other.m_xmlClasses)) { + return XmlSuite.f(); + } return true; } } diff --git a/testng-core-api/src/main/java/org/testng/xml/XmlSuite.java b/testng-core-api/src/main/java/org/testng/xml/XmlSuite.java index 8ade80f68..8c2f3419a 100644 --- a/testng-core-api/src/main/java/org/testng/xml/XmlSuite.java +++ b/testng-core-api/src/main/java/org/testng/xml/XmlSuite.java @@ -263,7 +263,7 @@ public void setObjectFactoryClass(Class objectFact * @param parallel The parallel mode. */ public void setParallel(ParallelMode parallel) { - m_parallel = (parallel == null) ? DEFAULT_PARALLEL : parallel; + m_parallel = parallel == null ? DEFAULT_PARALLEL : parallel; } public void setParentModule(String parentModule) { @@ -673,29 +673,25 @@ public int hashCode() { final int prime = 31; int result = 1; result = - prime * result + ((m_configFailurePolicy == null) ? 0 : m_configFailurePolicy.hashCode()); + prime * result + (m_configFailurePolicy == null ? 0 : m_configFailurePolicy.hashCode()); result = prime * result + m_dataProviderThreadCount; - result = prime * result + ((m_fileName == null) ? 0 : m_fileName.hashCode()); - result = prime * result + ((m_listeners == null) ? 0 : m_listeners.hashCode()); + result = prime * result + (m_fileName == null ? 0 : m_fileName.hashCode()); + result = prime * result + (m_listeners == null ? 0 : m_listeners.hashCode()); - result = prime * result + ((m_methodSelectors == null) ? 0 : m_methodSelectors.hashCode()); - result = prime * result + ((m_name == null) ? 0 : m_name.hashCode()); - result = - prime * result + ((m_objectFactoryClass == null) ? 0 : m_objectFactoryClass.hashCode()); - result = prime * result + ((m_parallel == null) ? 0 : m_parallel.hashCode()); + result = prime * result + (m_methodSelectors == null ? 0 : m_methodSelectors.hashCode()); + result = prime * result + (m_name == null ? 0 : m_name.hashCode()); + result = prime * result + (m_objectFactoryClass == null ? 0 : m_objectFactoryClass.hashCode()); + result = prime * result + (m_parallel == null ? 0 : m_parallel.hashCode()); result = prime * result - + ((m_skipFailedInvocationCounts == null) - ? 0 - : m_skipFailedInvocationCounts.hashCode()); - result = prime * result + ((m_suiteFiles == null) ? 0 : m_suiteFiles.hashCode()); - result = prime * result + ((m_test == null) ? 0 : m_test.hashCode()); - result = prime * result + ((m_tests == null) ? 0 : m_tests.hashCode()); + + (m_skipFailedInvocationCounts == null ? 0 : m_skipFailedInvocationCounts.hashCode()); + result = prime * result + (m_suiteFiles == null ? 0 : m_suiteFiles.hashCode()); + result = prime * result + (m_test == null ? 0 : m_test.hashCode()); + result = prime * result + (m_tests == null ? 0 : m_tests.hashCode()); result = prime * result + m_threadCount; - result = prime * result + ((m_timeOut == null) ? 0 : m_timeOut.hashCode()); - result = prime * result + ((m_verbose == null) ? 0 : m_verbose.hashCode()); - result = prime * result + ((m_xmlPackages == null) ? 0 : m_xmlPackages.hashCode()); - return result; + result = prime * result + (m_timeOut == null ? 0 : m_timeOut.hashCode()); + result = prime * result + (m_verbose == null ? 0 : m_verbose.hashCode()); + return prime * result + (m_xmlPackages == null ? 0 : m_xmlPackages.hashCode()); } /** Used to debug equals() bugs. */ @@ -762,27 +758,57 @@ public boolean equals(Object obj) { } if (m_skipFailedInvocationCounts == null) { - if (other.m_skipFailedInvocationCounts != null) return f(); - } else if (!m_skipFailedInvocationCounts.equals(other.m_skipFailedInvocationCounts)) return f(); + if (other.m_skipFailedInvocationCounts != null) { + return f(); + } + } else if (!m_skipFailedInvocationCounts.equals(other.m_skipFailedInvocationCounts)) { + return f(); + } if (m_suiteFiles == null) { - if (other.m_suiteFiles != null) return f(); - } else if (!m_suiteFiles.equals(other.m_suiteFiles)) return f(); + if (other.m_suiteFiles != null) { + return f(); + } + } else if (!m_suiteFiles.equals(other.m_suiteFiles)) { + return f(); + } if (m_test == null) { - if (other.m_test != null) return f(); - } else if (!m_test.equals(other.m_test)) return f(); + if (other.m_test != null) { + return f(); + } + } else if (!m_test.equals(other.m_test)) { + return f(); + } if (m_tests == null) { - if (other.m_tests != null) return f(); - } else if (!m_tests.equals(other.m_tests)) return f(); - if (m_threadCount != other.m_threadCount) return f(); + if (other.m_tests != null) { + return f(); + } + } else if (!m_tests.equals(other.m_tests)) { + return f(); + } + if (m_threadCount != other.m_threadCount) { + return f(); + } if (m_timeOut == null) { - if (other.m_timeOut != null) return f(); - } else if (!m_timeOut.equals(other.m_timeOut)) return f(); + if (other.m_timeOut != null) { + return f(); + } + } else if (!m_timeOut.equals(other.m_timeOut)) { + return f(); + } if (m_verbose == null) { - if (other.m_verbose != null) return f(); - } else if (!m_verbose.equals(other.m_verbose)) return f(); + if (other.m_verbose != null) { + return f(); + } + } else if (!m_verbose.equals(other.m_verbose)) { + return f(); + } if (m_xmlPackages == null) { - if (other.m_xmlPackages != null) return f(); - } else if (!m_xmlPackages.equals(other.m_xmlPackages)) return f(); + if (other.m_xmlPackages != null) { + return f(); + } + } else if (!m_xmlPackages.equals(other.m_xmlPackages)) { + return f(); + } return true; } diff --git a/testng-core-api/src/main/java/org/testng/xml/XmlTest.java b/testng-core-api/src/main/java/org/testng/xml/XmlTest.java index 3343bda19..7eccd02a7 100644 --- a/testng-core-api/src/main/java/org/testng/xml/XmlTest.java +++ b/testng-core-api/src/main/java/org/testng/xml/XmlTest.java @@ -451,8 +451,11 @@ public void setSuite(XmlSuite result) { } public Boolean getAllowReturnValues() { - if (m_allowReturnValues != null) return m_allowReturnValues; - else return getSuite().getAllowReturnValues(); + if (m_allowReturnValues != null) { + return m_allowReturnValues; + } else { + return getSuite().getAllowReturnValues(); + } } public void setAllowReturnValues(Boolean allowReturnValues) { @@ -480,34 +483,31 @@ public int hashCode() { int result = 1; result = prime * result - + ((m_xmlGroups == null || m_xmlGroups.getRun() == null) + + (m_xmlGroups == null || m_xmlGroups.getRun() == null ? 0 : m_xmlGroups.getRun().getExcludes().hashCode()); result = prime * result - + ((m_failedInvocationNumbers == null) ? 0 : m_failedInvocationNumbers.hashCode()); + + (m_failedInvocationNumbers == null ? 0 : m_failedInvocationNumbers.hashCode()); result = prime * result - + ((m_xmlGroups == null || m_xmlGroups.getRun() == null) + + (m_xmlGroups == null || m_xmlGroups.getRun() == null ? 0 : m_xmlGroups.getRun().getIncludes().hashCode()); - result = prime * result + ((m_xmlGroups == null) ? 0 : m_xmlGroups.getDefines().hashCode()); - result = prime * result + ((m_methodSelectors == null) ? 0 : m_methodSelectors.hashCode()); - result = prime * result + ((m_name == null) ? 0 : m_name.hashCode()); - result = prime * result + ((m_parallel == null) ? 0 : m_parallel.hashCode()); - result = prime * result + ((m_parameters == null) ? 0 : m_parameters.hashCode()); - result = prime * result + ((m_preserveOrder == null) ? 0 : m_preserveOrder.hashCode()); + result = prime * result + (m_xmlGroups == null ? 0 : m_xmlGroups.getDefines().hashCode()); + result = prime * result + (m_methodSelectors == null ? 0 : m_methodSelectors.hashCode()); + result = prime * result + (m_name == null ? 0 : m_name.hashCode()); + result = prime * result + (m_parallel == null ? 0 : m_parallel.hashCode()); + result = prime * result + (m_parameters == null ? 0 : m_parameters.hashCode()); + result = prime * result + (m_preserveOrder == null ? 0 : m_preserveOrder.hashCode()); result = prime * result - + ((m_skipFailedInvocationCounts == null) - ? 0 - : m_skipFailedInvocationCounts.hashCode()); + + (m_skipFailedInvocationCounts == null ? 0 : m_skipFailedInvocationCounts.hashCode()); result = prime * result + m_threadCount; - result = prime * result + ((m_timeOut == null) ? 0 : m_timeOut.hashCode()); - result = prime * result + ((m_verbose == null) ? 0 : m_verbose.hashCode()); - result = prime * result + ((m_xmlClasses == null) ? 0 : m_xmlClasses.hashCode()); - result = prime * result + ((m_xmlPackages == null) ? 0 : m_xmlPackages.hashCode()); - return result; + result = prime * result + (m_timeOut == null ? 0 : m_timeOut.hashCode()); + result = prime * result + (m_verbose == null ? 0 : m_verbose.hashCode()); + result = prime * result + (m_xmlClasses == null ? 0 : m_xmlClasses.hashCode()); + return prime * result + (m_xmlPackages == null ? 0 : m_xmlPackages.hashCode()); } @Override @@ -515,11 +515,17 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj == null) return XmlSuite.f(); - if (getClass() != obj.getClass()) return XmlSuite.f(); + if (obj == null) { + return XmlSuite.f(); + } + if (getClass() != obj.getClass()) { + return XmlSuite.f(); + } XmlTest other = (XmlTest) obj; if (m_xmlGroups == null) { - if (other.m_xmlGroups != null) return XmlSuite.f(); + if (other.m_xmlGroups != null) { + return XmlSuite.f(); + } } else { if (other.m_xmlGroups == null) { return false; @@ -539,41 +545,85 @@ public boolean equals(Object obj) { } } if (m_failedInvocationNumbers == null) { - if (other.m_failedInvocationNumbers != null) return XmlSuite.f(); - } else if (!m_failedInvocationNumbers.equals(other.m_failedInvocationNumbers)) + if (other.m_failedInvocationNumbers != null) { + return XmlSuite.f(); + } + } else if (!m_failedInvocationNumbers.equals(other.m_failedInvocationNumbers)) { return XmlSuite.f(); + } if (m_methodSelectors == null) { - if (other.m_methodSelectors != null) return XmlSuite.f(); - } else if (!m_methodSelectors.equals(other.m_methodSelectors)) return XmlSuite.f(); + if (other.m_methodSelectors != null) { + return XmlSuite.f(); + } + } else if (!m_methodSelectors.equals(other.m_methodSelectors)) { + return XmlSuite.f(); + } if (m_name == null) { - if (other.m_name != null) return XmlSuite.f(); - } else if (!m_name.equals(other.m_name)) return XmlSuite.f(); + if (other.m_name != null) { + return XmlSuite.f(); + } + } else if (!m_name.equals(other.m_name)) { + return XmlSuite.f(); + } if (m_parallel == null) { - if (other.m_parallel != null) return XmlSuite.f(); - } else if (!m_parallel.equals(other.m_parallel)) return XmlSuite.f(); + if (other.m_parallel != null) { + return XmlSuite.f(); + } + } else if (!m_parallel.equals(other.m_parallel)) { + return XmlSuite.f(); + } if (m_parameters == null) { - if (other.m_parameters != null) return XmlSuite.f(); - } else if (!m_parameters.equals(other.m_parameters)) return XmlSuite.f(); + if (other.m_parameters != null) { + return XmlSuite.f(); + } + } else if (!m_parameters.equals(other.m_parameters)) { + return XmlSuite.f(); + } if (m_preserveOrder == null) { - if (other.m_preserveOrder != null) return XmlSuite.f(); - } else if (!m_preserveOrder.equals(other.m_preserveOrder)) return XmlSuite.f(); + if (other.m_preserveOrder != null) { + return XmlSuite.f(); + } + } else if (!m_preserveOrder.equals(other.m_preserveOrder)) { + return XmlSuite.f(); + } if (m_skipFailedInvocationCounts == null) { - if (other.m_skipFailedInvocationCounts != null) return XmlSuite.f(); - } else if (!m_skipFailedInvocationCounts.equals(other.m_skipFailedInvocationCounts)) + if (other.m_skipFailedInvocationCounts != null) { + return XmlSuite.f(); + } + } else if (!m_skipFailedInvocationCounts.equals(other.m_skipFailedInvocationCounts)) { + return XmlSuite.f(); + } + if (m_threadCount != other.m_threadCount) { return XmlSuite.f(); - if (m_threadCount != other.m_threadCount) return XmlSuite.f(); + } if (m_timeOut == null) { - if (other.m_timeOut != null) return XmlSuite.f(); - } else if (!m_timeOut.equals(other.m_timeOut)) return XmlSuite.f(); + if (other.m_timeOut != null) { + return XmlSuite.f(); + } + } else if (!m_timeOut.equals(other.m_timeOut)) { + return XmlSuite.f(); + } if (m_verbose == null) { - if (other.m_verbose != null) return XmlSuite.f(); - } else if (!m_verbose.equals(other.m_verbose)) return XmlSuite.f(); + if (other.m_verbose != null) { + return XmlSuite.f(); + } + } else if (!m_verbose.equals(other.m_verbose)) { + return XmlSuite.f(); + } if (m_xmlClasses == null) { - if (other.m_xmlClasses != null) return XmlSuite.f(); - } else if (!m_xmlClasses.equals(other.m_xmlClasses)) return XmlSuite.f(); + if (other.m_xmlClasses != null) { + return XmlSuite.f(); + } + } else if (!m_xmlClasses.equals(other.m_xmlClasses)) { + return XmlSuite.f(); + } if (m_xmlPackages == null) { - if (other.m_xmlPackages != null) return XmlSuite.f(); - } else if (!m_xmlPackages.equals(other.m_xmlPackages)) return XmlSuite.f(); + if (other.m_xmlPackages != null) { + return XmlSuite.f(); + } + } else if (!m_xmlPackages.equals(other.m_xmlPackages)) { + return XmlSuite.f(); + } return true; } diff --git a/testng-core/src/main/java/org/testng/Converter.java b/testng-core/src/main/java/org/testng/Converter.java index 333be9eee..2a150e1d5 100644 --- a/testng-core/src/main/java/org/testng/Converter.java +++ b/testng-core/src/main/java/org/testng/Converter.java @@ -47,7 +47,9 @@ private void run(String[] args) throws IOException { try { jc.parse(args); File f = new File(m_outputDirectory); - if (!f.exists()) f.mkdir(); + if (!f.exists()) { + f.mkdir(); + } for (String file : m_files) { Set allSuites = Sets.newHashSet(); diff --git a/testng-core/src/main/java/org/testng/JarFileUtils.java b/testng-core/src/main/java/org/testng/JarFileUtils.java index 377ee3f70..e5a626a28 100644 --- a/testng-core/src/main/java/org/testng/JarFileUtils.java +++ b/testng-core/src/main/java/org/testng/JarFileUtils.java @@ -139,7 +139,9 @@ private boolean testngXmlExistsInJar(File jarFile, List classes) throws private void delete(File f) throws IOException { if (f.isDirectory()) { - for (File c : Objects.requireNonNull(f.listFiles())) delete(c); + for (File c : Objects.requireNonNull(f.listFiles())) { + delete(c); + } } Files.deleteIfExists(f.toPath()); } diff --git a/testng-core/src/main/java/org/testng/SuiteRunner.java b/testng-core/src/main/java/org/testng/SuiteRunner.java index 452e57112..e0c35f7c3 100644 --- a/testng-core/src/main/java/org/testng/SuiteRunner.java +++ b/testng-core/src/main/java/org/testng/SuiteRunner.java @@ -256,7 +256,7 @@ private void setOutputDir(String outputdir) { outputdir = DEFAULT_OUTPUT_DIR; } - outputDir = (null != outputdir) ? new File(outputdir).getAbsolutePath() : null; + outputDir = null != outputdir ? new File(outputdir).getAbsolutePath() : null; } private ITestRunnerFactory buildRunnerFactory(Comparator comparator) { diff --git a/testng-core/src/main/java/org/testng/TestRunner.java b/testng-core/src/main/java/org/testng/TestRunner.java index eb82eea3c..bf56948fb 100644 --- a/testng-core/src/main/java/org/testng/TestRunner.java +++ b/testng-core/src/main/java/org/testng/TestRunner.java @@ -810,10 +810,9 @@ public List> createWorkers(List methods) { .testContext(this) .listeners(this.m_classListeners.values()) .build(); - List> result = - AbstractParallelWorker.newWorker(m_xmlTest.getParallel(), m_xmlTest.getGroupByInstances()) - .createWorkers(args); - return result; + return AbstractParallelWorker.newWorker( + m_xmlTest.getParallel(), m_xmlTest.getGroupByInstances()) + .createWorkers(args); } private void afterRun() { diff --git a/testng-core/src/main/java/org/testng/internal/ClassBasedWrapper.java b/testng-core/src/main/java/org/testng/internal/ClassBasedWrapper.java index 7c43793f4..924cfb74c 100644 --- a/testng-core/src/main/java/org/testng/internal/ClassBasedWrapper.java +++ b/testng-core/src/main/java/org/testng/internal/ClassBasedWrapper.java @@ -20,8 +20,12 @@ public T unWrap() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } ClassBasedWrapper wrapper = (ClassBasedWrapper) o; return object.getClass().equals(wrapper.object.getClass()); } diff --git a/testng-core/src/main/java/org/testng/internal/IObject.java b/testng-core/src/main/java/org/testng/internal/IObject.java index 04c04946f..ac1bab6ed 100644 --- a/testng-core/src/main/java/org/testng/internal/IObject.java +++ b/testng-core/src/main/java/org/testng/internal/IObject.java @@ -102,8 +102,12 @@ public Object getInstance() { @Override public boolean equals(Object object) { - if (this == object) return true; - if (object == null || getClass() != object.getClass()) return false; + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } IdentifiableObject that = (IdentifiableObject) object; return Objects.equals(instanceId, that.instanceId); } diff --git a/testng-core/src/main/java/org/testng/internal/MethodHelper.java b/testng-core/src/main/java/org/testng/internal/MethodHelper.java index fe14680e8..a476547d0 100644 --- a/testng-core/src/main/java/org/testng/internal/MethodHelper.java +++ b/testng-core/src/main/java/org/testng/internal/MethodHelper.java @@ -230,7 +230,8 @@ private static Method findMethodByName(ITestNGMethod testngMethod, String regExp } regExp = regExp.replace("\\$", "$"); int lastDot = regExp.lastIndexOf('.'); - String className, methodName; + String className; + String methodName; if (lastDot == -1) { className = testngMethod.getConstructorOrMethod().getDeclaringClass().getCanonicalName(); methodName = regExp; @@ -543,7 +544,7 @@ public static void dumpInvokedMethodInfoToConsole(ITestNGMethod[] methods, int c } else { return; } - System.out.println("" + im); + System.out.println(String.valueOf(im)); }); System.out.println("====="); } diff --git a/testng-core/src/main/java/org/testng/internal/MethodInstance.java b/testng-core/src/main/java/org/testng/internal/MethodInstance.java index e8535ef28..34ef65534 100644 --- a/testng-core/src/main/java/org/testng/internal/MethodInstance.java +++ b/testng-core/src/main/java/org/testng/internal/MethodInstance.java @@ -57,8 +57,12 @@ public int compare(IMethodInstance o1, IMethodInstance o2) { // This can happen if these classes came from a @Factory, in which case, they // don't have an associated XmlClass if (class1 == null || class2 == null) { - if (class1 != null) return -1; - if (class2 != null) return 1; + if (class1 != null) { + return -1; + } + if (class2 != null) { + return 1; + } return 0; } 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 2b1b8487d..d3481ca1f 100644 --- a/testng-core/src/main/java/org/testng/internal/Parameters.java +++ b/testng-core/src/main/java/org/testng/internal/Parameters.java @@ -577,19 +577,18 @@ private static IDataProvidable merge(ITestAnnotation methodLevel, ITestAnnotatio } String dataProvider = - (Strings.isNullOrEmpty(methodLevel.getDataProvider()) - && Strings.isNotNullAndNotEmpty(classLevel.getDataProvider())) + Strings.isNullOrEmpty(methodLevel.getDataProvider()) + && Strings.isNotNullAndNotEmpty(classLevel.getDataProvider()) ? classLevel.getDataProvider() : methodLevel.getDataProvider(); Class dataProviderClass = - (isDataProviderClassEmpty(methodLevel) && !isDataProviderClassEmpty(classLevel)) + isDataProviderClassEmpty(methodLevel) && !isDataProviderClassEmpty(classLevel) ? classLevel.getDataProviderClass() : methodLevel.getDataProviderClass(); String dataProviderDynamicClass = - (isDynamicDataProviderClassEmpty(methodLevel) - && !isDynamicDataProviderClassEmpty(classLevel)) + isDynamicDataProviderClassEmpty(methodLevel) && !isDynamicDataProviderClassEmpty(classLevel) ? classLevel.getDataProviderDynamicClass() : methodLevel.getDataProviderDynamicClass(); diff --git a/testng-core/src/main/java/org/testng/internal/TestNGClassFinder.java b/testng-core/src/main/java/org/testng/internal/TestNGClassFinder.java index b8d00d888..cd9c152a4 100644 --- a/testng-core/src/main/java/org/testng/internal/TestNGClassFinder.java +++ b/testng-core/src/main/java/org/testng/internal/TestNGClassFinder.java @@ -96,7 +96,7 @@ private void processClass( } List allInstances = instanceMap.get(cls); IObject.IdentifiableObject thisInstance = - (allInstances != null && !allInstances.isEmpty()) ? allInstances.get(0) : null; + allInstances != null && !allInstances.isEmpty() ? allInstances.get(0) : null; // If annotation class and instances are abstract, skip them if ((null == thisInstance) && Modifier.isAbstract(cls.getModifiers())) { @@ -264,7 +264,7 @@ private ITestObjectFactory createObjectFactory( } private static boolean isNotTestNGClass(Class c, IAnnotationFinder annotationFinder) { - return (!isTestNGClass(c, annotationFinder)); + return !isTestNGClass(c, annotationFinder); } /** diff --git a/testng-core/src/main/java/org/testng/internal/WrappedTestNGMethod.java b/testng-core/src/main/java/org/testng/internal/WrappedTestNGMethod.java index 7700d33fb..e4cd64311 100644 --- a/testng-core/src/main/java/org/testng/internal/WrappedTestNGMethod.java +++ b/testng-core/src/main/java/org/testng/internal/WrappedTestNGMethod.java @@ -26,7 +26,7 @@ public class WrappedTestNGMethod implements ITestNGMethod, IInstanceIdentity { public WrappedTestNGMethod(ITestNGMethod testNGMethod) { this.testNGMethod = testNGMethod; uuid = - (testNGMethod instanceof BaseTestMethod) + testNGMethod instanceof BaseTestMethod ? ((BaseTestMethod) testNGMethod).getInstanceId() : UUID.randomUUID(); } diff --git a/testng-core/src/main/java/org/testng/internal/XmlMethodSelector.java b/testng-core/src/main/java/org/testng/internal/XmlMethodSelector.java index 0a1b76842..4d45a96b7 100644 --- a/testng-core/src/main/java/org/testng/internal/XmlMethodSelector.java +++ b/testng-core/src/main/java/org/testng/internal/XmlMethodSelector.java @@ -121,7 +121,7 @@ private boolean includeMethodFromIncludeExclude(ITestNGMethod tm, boolean isTest // Check if groups was involved or not. If groups was not involved then we should not be // involving the size of the list for evaluation of "isIncluded" - noGroupsSpecified = (m_includedGroups.isEmpty() && m_excludedGroups.isEmpty()); + noGroupsSpecified = m_includedGroups.isEmpty() && m_excludedGroups.isEmpty(); // Iterate through all the classes so we can gather all the included and // excluded methods @@ -316,7 +316,7 @@ private static void log(String s) { } public void setScript(XmlScript script) { - scriptSelector = (script == null) ? null : ScriptSelectorFactory.getScriptSelector(script); + scriptSelector = script == null ? null : ScriptSelectorFactory.getScriptSelector(script); } @Override diff --git a/testng-core/src/main/java/org/testng/internal/Yaml.java b/testng-core/src/main/java/org/testng/internal/Yaml.java index da3d21413..9e67dc9e8 100644 --- a/testng-core/src/main/java/org/testng/internal/Yaml.java +++ b/testng-core/src/main/java/org/testng/internal/Yaml.java @@ -226,7 +226,7 @@ private static void toYaml(StringBuilder result, XmlTest t) { private static void toYaml(StringBuilder result, String sp2, XmlClass xc) { List im = xc.getIncludedMethods(); List em = xc.getExcludedMethods(); - String name = (im.isEmpty() && em.isEmpty()) ? "" : "name: "; + String name = im.isEmpty() && em.isEmpty() ? "" : "name: "; result.append(sp2).append("- ").append(name).append(xc.getName()).append("\n"); if (!im.isEmpty()) { @@ -320,7 +320,7 @@ public Object construct(Node node) { if (node.getType().equals(org.testng.xml.XmlMethodSelector.class)) { final XmlScript xmlScript = new XmlScript(); org.testng.xml.XmlMethodSelector selector = new org.testng.xml.XmlMethodSelector(); - MappingNode mappingNode = ((MappingNode) node); + MappingNode mappingNode = (MappingNode) node; List tuples = mappingNode.getValue(); for (NodeTuple tuple : tuples) { setValue(tuple, "expression", xmlScript::setExpression); diff --git a/testng-core/src/main/java/org/testng/internal/annotations/AnnotationHelper.java b/testng-core/src/main/java/org/testng/internal/annotations/AnnotationHelper.java index 2488bca55..f49bd717e 100644 --- a/testng-core/src/main/java/org/testng/internal/annotations/AnnotationHelper.java +++ b/testng-core/src/main/java/org/testng/internal/annotations/AnnotationHelper.java @@ -285,7 +285,7 @@ && isAnnotationPresent(annotationFinder, cls, ITestAnnotation.class)) { } if (Arrays.stream(m.getAnnotations()) - .anyMatch(a -> a.annotationType().getName().equals("groovy.transform.Internal"))) { + .anyMatch(a -> "groovy.transform.Internal".equals(a.annotationType().getName()))) { Utils.log( "", 2, "Method " + m + " is being skipped since it a Groovy internal method."); continue; diff --git a/testng-core/src/main/java/org/testng/internal/collections/Pair.java b/testng-core/src/main/java/org/testng/internal/collections/Pair.java index 146a23216..a7072b3f8 100644 --- a/testng-core/src/main/java/org/testng/internal/collections/Pair.java +++ b/testng-core/src/main/java/org/testng/internal/collections/Pair.java @@ -23,9 +23,8 @@ public B second() { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((first == null) ? 0 : first.hashCode()); - result = prime * result + ((second == null) ? 0 : second.hashCode()); - return result; + result = prime * result + (first == null ? 0 : first.hashCode()); + return prime * result + (second == null ? 0 : second.hashCode()); } @Override diff --git a/testng-core/src/main/java/org/testng/internal/invokers/ConfigInvoker.java b/testng-core/src/main/java/org/testng/internal/invokers/ConfigInvoker.java index 82054aae0..e55656f18 100644 --- a/testng-core/src/main/java/org/testng/internal/invokers/ConfigInvoker.java +++ b/testng-core/src/main/java/org/testng/internal/invokers/ConfigInvoker.java @@ -680,7 +680,7 @@ private boolean canIgnoreConfigFailure(IClass testClass, ITestNGMethod configMet if (!instanceMatch) { return false; } - ITestClass tc = ((ITestClass) testClass); + ITestClass tc = (ITestClass) testClass; ITestNGMethod[] methods = new ITestNGMethod[] {}; if (configMethod == null) { // We are dealing with a test method that is doing the checking // First check if there were any @BeforeMethods that had the isIgnoreFailure flag. diff --git a/testng-core/src/main/java/org/testng/internal/invokers/MethodRunner.java b/testng-core/src/main/java/org/testng/internal/invokers/MethodRunner.java index bccbcb8d0..cf194e284 100644 --- a/testng-core/src/main/java/org/testng/internal/invokers/MethodRunner.java +++ b/testng-core/src/main/java/org/testng/internal/invokers/MethodRunner.java @@ -70,7 +70,7 @@ public List runInSequence( } finally { boolean lastSuccess = false; if (tmpResultsIndex >= 0) { - lastSuccess = (tmpResults.get(tmpResultsIndex).getStatus() == ITestResult.SUCCESS); + lastSuccess = tmpResults.get(tmpResultsIndex).getStatus() == ITestResult.SUCCESS; } if (failure.instances.isEmpty() || lastSuccess) { result.addAll(tmpResults); diff --git a/testng-core/src/main/java/org/testng/internal/invokers/ParameterHandler.java b/testng-core/src/main/java/org/testng/internal/invokers/ParameterHandler.java index d159db2f0..c60484f48 100644 --- a/testng-core/src/main/java/org/testng/internal/invokers/ParameterHandler.java +++ b/testng-core/src/main/java/org/testng/internal/invokers/ParameterHandler.java @@ -124,9 +124,9 @@ boolean hasErrors() { } boolean runInParallel() { - return ((parameterHolder != null) + return (parameterHolder != null) && (parameterHolder.origin == ParameterHolder.ParameterOrigin.ORIGIN_DATA_PROVIDER - && parameterHolder.dataProviderHolder.isParallel())); + && parameterHolder.dataProviderHolder.isParallel()); } boolean isBubbleUpFailures() { diff --git a/testng-core/src/main/java/org/testng/internal/objects/GuiceHelper.java b/testng-core/src/main/java/org/testng/internal/objects/GuiceHelper.java index 9200d1a27..8d632d5a3 100644 --- a/testng-core/src/main/java/org/testng/internal/objects/GuiceHelper.java +++ b/testng-core/src/main/java/org/testng/internal/objects/GuiceHelper.java @@ -204,8 +204,7 @@ private List getModules(Guice guice, Injector parentInjector, Class t result = Lists.merge(result, CLASS_EQUALITY, Collections.singletonList(module)); } } - result = Lists.merge(result, CLASS_EQUALITY, LazyHolder.getSpiModules()); - return result; + return Lists.merge(result, CLASS_EQUALITY, LazyHolder.getSpiModules()); } private static final class LazyHolder { diff --git a/testng-core/src/main/java/org/testng/internal/objects/ObjectFactoryImpl.java b/testng-core/src/main/java/org/testng/internal/objects/ObjectFactoryImpl.java index 078505974..18c263908 100644 --- a/testng-core/src/main/java/org/testng/internal/objects/ObjectFactoryImpl.java +++ b/testng-core/src/main/java/org/testng/internal/objects/ObjectFactoryImpl.java @@ -48,7 +48,7 @@ private static T tryOtherConstructor(Class declaringClass) { String error = "Could not create an instance of class " + declaringClass - + ((message != null) ? (": " + message) : "") + + (message != null ? (": " + message) : "") + ".\nPlease make sure it has a constructor that accepts either a String or no parameter."; throw new TestNGException(error); } diff --git a/testng-core/src/main/java/org/testng/internal/reflect/ReflectionRecipes.java b/testng-core/src/main/java/org/testng/internal/reflect/ReflectionRecipes.java index 4b7eda5de..d1fbc4e82 100644 --- a/testng-core/src/main/java/org/testng/internal/reflect/ReflectionRecipes.java +++ b/testng-core/src/main/java/org/testng/internal/reflect/ReflectionRecipes.java @@ -97,7 +97,9 @@ public static boolean isOrImplementsInterface(final Class reference, final Cl final Class[] interfaces = clazz.getInterfaces(); for (final Class interfaceClazz : interfaces) { implementsInterface = interfaceClazz.equals(reference); - if (implementsInterface) break; + if (implementsInterface) { + break; + } } } } @@ -204,7 +206,9 @@ public static boolean matchArrayEnding(final Class[] classes, final Object[] } matching = ReflectionRecipes.isInstanceOf(clazz, args[i]); i++; - if (!matching) break; + if (!matching) { + break; + } } } else { matching = false; @@ -214,7 +218,9 @@ public static boolean matchArrayEnding(final Class[] classes, final Object[] final Class componentType = classes[classes.length - 1].getComponentType(); for (; i < args.length; i++) { matching = ReflectionRecipes.isInstanceOf(componentType, args[i]); - if (!matching) break; + if (!matching) { + break; + } } } @@ -245,7 +251,9 @@ public static boolean exactMatch(final Class[] classes, final Object[] args) for (final Class clazz : classes) { matching = ReflectionRecipes.isInstanceOf(clazz, args[i]); i++; - if (!matching) break; + if (!matching) { + break; + } } } else { matching = false; @@ -277,7 +285,9 @@ public static boolean lenientMatch(final Class[] classes, final Object[] args for (final Class clazz : classes) { matching = ReflectionRecipes.isInstanceOf(clazz, args[i]); i++; - if (!matching) break; + if (!matching) { + break; + } } return matching; } diff --git a/testng-core/src/main/java/org/testng/reporters/EmailableReporter2.java b/testng-core/src/main/java/org/testng/reporters/EmailableReporter2.java index e15bf7a30..5545870c3 100644 --- a/testng-core/src/main/java/org/testng/reporters/EmailableReporter2.java +++ b/testng-core/src/main/java/org/testng/reporters/EmailableReporter2.java @@ -1,6 +1,5 @@ package org.testng.reporters; -import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.file.Files.newBufferedWriter; import java.io.File; @@ -75,7 +74,7 @@ protected PrintWriter createWriter(String outdir) throws IOException { if (jvmArg != null && !jvmArg.trim().isEmpty()) { fileName = jvmArg; } - return new PrintWriter(newBufferedWriter(new File(outdir, fileName).toPath(), UTF_8)); + return new PrintWriter(newBufferedWriter(new File(outdir, fileName).toPath())); } protected void writeDocumentStart() { @@ -176,9 +175,9 @@ protected void writeSuiteSummary() { .append("") .toString()); writeTableData(integerFormat.format(passedTests), "num"); - writeTableData(integerFormat.format(skippedTests), (skippedTests > 0 ? "num attn" : "num")); - writeTableData(integerFormat.format(retriedTests), (retriedTests > 0 ? "num attn" : "num")); - writeTableData(integerFormat.format(failedTests), (failedTests > 0 ? "num attn" : "num")); + writeTableData(integerFormat.format(skippedTests), skippedTests > 0 ? "num attn" : "num"); + writeTableData(integerFormat.format(retriedTests), retriedTests > 0 ? "num attn" : "num"); + writeTableData(integerFormat.format(failedTests), failedTests > 0 ? "num attn" : "num"); writeTableData(decimalFormat.format(duration), "num"); writeTableData(testResult.getIncludedGroups()); writeTableData(testResult.getExcludedGroups()); @@ -209,11 +208,11 @@ protected void writeSuiteSummary() { writer.print("Total"); writeTableHeader(integerFormat.format(totalPassedTests), "num"); writeTableHeader( - integerFormat.format(totalSkippedTests), (totalSkippedTests > 0 ? "num attn" : "num")); + integerFormat.format(totalSkippedTests), totalSkippedTests > 0 ? "num attn" : "num"); writeTableHeader( - integerFormat.format(totalRetriedTests), (totalRetriedTests > 0 ? "num attn" : "num")); + integerFormat.format(totalRetriedTests), totalRetriedTests > 0 ? "num attn" : "num"); writeTableHeader( - integerFormat.format(totalFailedTests), (totalFailedTests > 0 ? "num attn" : "num")); + integerFormat.format(totalFailedTests), totalFailedTests > 0 ? "num attn" : "num"); writeTableHeader(decimalFormat.format(totalDuration), "num"); writer.print(""); writer.println(""); @@ -454,7 +453,7 @@ private void writeScenario(int scenarioIndex, String label, ITestResult result) // Write test parameters (if any) Object[] parameters = result.getParameters(); boolean hasRows = dumpParametersInfo("Factory Parameter", result.getFactoryParameters()); - int parameterCount = (parameters == null ? 0 : parameters.length); + int parameterCount = parameters == null ? 0 : parameters.length; hasRows = dumpParametersInfo("Parameter", result.getParameters()); dumpAttributesInfo(result.getMethod().getAttributes()); @@ -485,8 +484,7 @@ private void writeScenario(int scenarioIndex, String label, ITestResult result) writer.printf(" colspan=\"%d\"", parameterCount); } writer.print(">"); - writer.print( - (result.getStatus() == ITestResult.SUCCESS ? "Expected Exception" : "Exception")); + writer.print(result.getStatus() == ITestResult.SUCCESS ? "Expected Exception" : "Exception"); writer.print(""); writer.print(""); - writer.print("" + String.format("%02d.", (i++)) + ""); + writer.print("" + String.format("%02d.", i++) + ""); writer.print("" + attribute.name() + ""); writer.print("" + Utils.escapeHtml(Arrays.toString(attribute.values())) + ""); writer.print(""); diff --git a/testng-core/src/main/java/org/testng/reporters/JUnitReportReporter.java b/testng-core/src/main/java/org/testng/reporters/JUnitReportReporter.java index e00eeadd5..a2cbf7527 100644 --- a/testng-core/src/main/java/org/testng/reporters/JUnitReportReporter.java +++ b/testng-core/src/main/java/org/testng/reporters/JUnitReportReporter.java @@ -156,7 +156,7 @@ public void generateReport( // Add the full reporter output once as a child system-out element of testsuite. List output = Reporter.getOutput(); - if ((!output.isEmpty())) { + if (!output.isEmpty()) { putElement(xsb, XMLConstants.SYSTEM_OUT, new Properties(), true); xsb.addCDATA(String.join("\n", output)); xsb.pop(XMLConstants.SYSTEM_OUT); diff --git a/testng-core/src/main/java/org/testng/reporters/MethodInvocationKey.java b/testng-core/src/main/java/org/testng/reporters/MethodInvocationKey.java index 2b8497850..055118554 100644 --- a/testng-core/src/main/java/org/testng/reporters/MethodInvocationKey.java +++ b/testng-core/src/main/java/org/testng/reporters/MethodInvocationKey.java @@ -18,7 +18,9 @@ class MethodInvocationKey { @Override public boolean equals(Object o) { - if (o == null || getClass() != o.getClass()) return false; + if (o == null || getClass() != o.getClass()) { + return false; + } MethodInvocationKey that = (MethodInvocationKey) o; return currentInvocationCount == that.currentInvocationCount && Objects.equals(methodIdentity, that.methodIdentity) diff --git a/testng-core/src/main/java/org/testng/reporters/SuiteHTMLReporter.java b/testng-core/src/main/java/org/testng/reporters/SuiteHTMLReporter.java index 2a69cc9df..e25a165ab 100644 --- a/testng-core/src/main/java/org/testng/reporters/SuiteHTMLReporter.java +++ b/testng-core/src/main/java/org/testng/reporters/SuiteHTMLReporter.java @@ -469,7 +469,7 @@ private String td(String s) { prefix = AFTER; } - if (!s.equals(SP)) { + if (!SP.equals(s)) { result.append(""); int open = s.lastIndexOf("("); int start = s.substring(0, open).lastIndexOf("."); diff --git a/testng-core/src/main/java/org/testng/reporters/VerboseReporter.java b/testng-core/src/main/java/org/testng/reporters/VerboseReporter.java index 450c5525c..810f76ad7 100644 --- a/testng-core/src/main/java/org/testng/reporters/VerboseReporter.java +++ b/testng-core/src/main/java/org/testng/reporters/VerboseReporter.java @@ -34,7 +34,7 @@ private enum Status { FAILURE, SKIP, SUCCESS_PERCENTAGE_FAILURE, - STARTED; + STARTED } /** diff --git a/testng-core/src/main/java/org/testng/reporters/jq/Model.java b/testng-core/src/main/java/org/testng/reporters/jq/Model.java index 2f8afd4b8..2ba7e87e0 100644 --- a/testng-core/src/main/java/org/testng/reporters/jq/Model.java +++ b/testng-core/src/main/java/org/testng/reporters/jq/Model.java @@ -146,7 +146,9 @@ public static String getTestResultName(ITestResult tr) { result.append("("); StringBuilder p = new StringBuilder(); for (int i = 0; i < parameters.length; i++) { - if (i > 0) p.append(", "); + if (i > 0) { + p.append(", "); + } p.append(Utils.toString(parameters[i])); } if (p.length() > 100) { diff --git a/testng-core/src/main/java/org/testng/reporters/jq/NavigatorPanel.java b/testng-core/src/main/java/org/testng/reporters/jq/NavigatorPanel.java index 28c107349..9f63c6b76 100644 --- a/testng-core/src/main/java/org/testng/reporters/jq/NavigatorPanel.java +++ b/testng-core/src/main/java/org/testng/reporters/jq/NavigatorPanel.java @@ -203,7 +203,7 @@ private class ResultsByStatus extends BaseResultProvider { private final Predicate condition; public ResultsByStatus(ISuite suite, String type, int status) { - this(suite, type, status, (result) -> true); + this(suite, type, status, result -> true); } public ResultsByStatus( diff --git a/testng-core/src/main/java/org/testng/reporters/jq/TestNgXmlPanel.java b/testng-core/src/main/java/org/testng/reporters/jq/TestNgXmlPanel.java index 926eb56aa..615c2320b 100644 --- a/testng-core/src/main/java/org/testng/reporters/jq/TestNgXmlPanel.java +++ b/testng-core/src/main/java/org/testng/reporters/jq/TestNgXmlPanel.java @@ -32,7 +32,9 @@ public String getContent(ISuite suite, XMLStringBuffer main) { @Override public String getNavigatorLink(ISuite suite) { String fqName = suite.getXmlSuite().getFileName(); - if (fqName == null) fqName = "/[unset file name]"; + if (fqName == null) { + fqName = "/[unset file name]"; + } return fqName.substring(fqName.lastIndexOf("/") + 1); } } diff --git a/testng-core/src/main/java/org/testng/xml/TestNGContentHandler.java b/testng-core/src/main/java/org/testng/xml/TestNGContentHandler.java index a1f64c005..93dacb28b 100644 --- a/testng-core/src/main/java/org/testng/xml/TestNGContentHandler.java +++ b/testng-core/src/main/java/org/testng/xml/TestNGContentHandler.java @@ -76,9 +76,9 @@ public class TestNGContentHandler extends DefaultHandler { HttpURLConnection conn = (HttpURLConnection) urlConnection; int status = conn.getResponseCode(); - if ((status == HttpURLConnection.HTTP_MOVED_TEMP + if (status == HttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_MOVED_PERM - || status == HttpURLConnection.HTTP_SEE_OTHER)) { + || status == HttpURLConnection.HTTP_SEE_OTHER) { String newUrl = conn.getHeaderField("Location"); conn = (HttpURLConnection) new URL(newUrl).openConnection(); @@ -160,7 +160,7 @@ private static boolean isMalformedFileSystemBasedSystemId(String systemId) { try { URL url = new URL(URLDecoder.decode(systemId, StandardCharsets.UTF_8).trim()); - if (url.getProtocol().equals("file")) { + if ("file".equals(url.getProtocol())) { File file = new File(url.getFile()); boolean isDirectory = file.isDirectory(); boolean fileExists = file.exists(); @@ -180,7 +180,7 @@ private static boolean isUnsecuredUrl(String str) { throw new RuntimeException(e); } // scheme is null for local uri - return uri.getScheme() != null && uri.getScheme().equals("http"); + return "http".equals(uri.getScheme()); } private InputStream loadDtdUsingClassLoader() { @@ -850,6 +850,5 @@ private static void warnSinceJUnitDetected() { + " https://github.com/junit-team/testng-engine which is now maintained by the JUnit team"; // Intentionally logging this to the error console so that it's visible to the user. System.err.println(msg); - ; } } 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 06daa522d..e4a0dc158 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 @@ -521,17 +521,17 @@ public boolean equals(Object o) { } ITestNGMethod that = (ITestNGMethod) o; - boolean value = - realClass.equals(that.getRealClass()) - && qualifiedName.equals(that.getQualifiedName()) - && equalParamTypes(parameterTypes, that.getParameterTypes()); - return value; + return realClass.equals(that.getRealClass()) + && qualifiedName.equals(that.getQualifiedName()) + && equalParamTypes(parameterTypes, that.getParameterTypes()); } boolean equalParamTypes(Class[] params1, Class[] params2) { if (params1.length == params2.length) { for (int i = 0; i < params1.length; i++) { - if (params1[i] != params2[i]) return false; + if (params1[i] != params2[i]) { + return false; + } } return true; } From 56c7bac5f08cee23541502606dc7158c83f07fdb Mon Sep 17 00:00:00 2001 From: Julien Herr Date: Wed, 29 Jul 2026 14:52:17 +0200 Subject: [PATCH 5/6] docs: document the OpenRewrite workflow Describe rewriteDryRun/rewriteRun in CONTRIBUTING.md, stress that autostyleApply must run afterwards as a separate Gradle invocation, give the exact command that reproduces the CI gate, point at rewrite.yml as the recipe list, and note the configuration-cache incompatibility. Add a CHANGES.txt entry. --- .github/CONTRIBUTING.md | 34 ++++++++++++++++++++++++++++++++++ CHANGES.txt | 1 + 2 files changed, 35 insertions(+) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 4b51b1ff6..54301dd49 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -99,3 +99,37 @@ exit $RESULT This will cause git to trigger the code styling automatically right before commiting your changes locally. After that you can quickly check if there were any formatting that was applied using `git status` + +### Automated refactoring with OpenRewrite + +The codebase makes use of [OpenRewrite](https://docs.openrewrite.org/) for automated refactoring. +It is a maintenance tool you run on purpose; it is never part of `check` or `build`, so a normal +build never invokes it. + +To see what the recipes would change without touching your working tree, run +`./gradlew rewriteDryRun`. It writes a patch to `build/reports/rewrite/rewrite.patch`. **Read that +patch before applying it** -- recipes are not always semantics-preserving, and at least one had to +be dropped from our list because it silently broke a `NaN` comparison. + +To apply the recipes run `./gradlew rewriteRun`, and then **always** run `./gradlew autostyleApply` +afterwards, as two separate commands: + +``` +./gradlew rewriteRun +./gradlew autostyleApply +``` + +OpenRewrite does not emit google-java-format output, so Autostyle has to have the last word or +`autostyleCheck` will fail. Do not combine the two into a single Gradle invocation: task ordering +between them is not constrained and Gradle may interleave them. + +CI runs `./gradlew rewriteDryRun -PfailOnRewriteDryRun=true`, which fails when the recipes still +have work to do. That exact command reproduces the check locally. + +The active recipes are listed in [`rewrite.yml`](../rewrite.yml) at the root of the repository. It +is a hand-picked list rather than one of OpenRewrite's bundled composite recipes; the file explains +why. If you want to add a recipe, add it there and include the dry-run patch in your pull request. + +**Note:** the OpenRewrite tasks are not compatible with Gradle's configuration cache +([rewrite-gradle-plugin#366](https://github.com/openrewrite/rewrite-gradle-plugin/issues/366)). If +you have it enabled, add `--no-configuration-cache` to the commands above. diff --git a/CHANGES.txt b/CHANGES.txt index 4f20cc6dd..55ae2df31 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ Current (7.13.0) +New: Added OpenRewrite to the build with a hand-picked recipe list (see rewrite.yml), and applied it to the main sources (Julien Herr) Update: Dependency refresh: Guice 6.0.0, JCommander 2.0, snakeyaml 2.6, slf4j-api 2.0.18. Guice 7 and JCommander 3 were skipped: they require jakarta.inject and Java 17 respectively Fixed: GITHUB-3242: use-global-thread-pool no longer refuses to start a suite when the number of data-driven tests reaches thread-count (Krishnan Mahadevan) New: GITHUB-3290: Support data providers that return Stream or Stream; the stream is consumed lazily and closed once its rows have been consumed (Krishnan Mahadevan) From c04c23c81bb1939538dc7fd8acc7bad2fd75decb Mon Sep 17 00:00:00 2001 From: Julien Herr Date: Wed, 29 Jul 2026 15:52:20 +0200 Subject: [PATCH 6/6] ci: restrict the OpenRewrite job to read-only repository access The job only checks out the repository and uploads an artifact, so grant it contents: read explicitly rather than letting it inherit the workflow default. Other workflows here already declare permissions (combine-prs, label-commenter); test.yml did not. Also label the shell block added to CONTRIBUTING.md, matching the bash fence the file already uses for its other command block. --- .github/CONTRIBUTING.md | 2 +- .github/workflows/test.yml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 54301dd49..8112369f4 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -114,7 +114,7 @@ be dropped from our list because it silently broke a `NaN` comparison. To apply the recipes run `./gradlew rewriteRun`, and then **always** run `./gradlew autostyleApply` afterwards, as two separate commands: -``` +```bash ./gradlew rewriteRun ./gradlew autostyleApply ``` diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 83398d3a0..2ce9c0f1e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,6 +40,8 @@ jobs: rewrite: name: 'OpenRewrite' runs-on: ubuntu-latest + permissions: + contents: read steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: