From 84bd88f3213a2bc0e163793346ac6bc5c8bc11f0 Mon Sep 17 00:00:00 2001 From: Ronald Holshausen Date: Thu, 21 Nov 2024 14:14:05 +1100 Subject: [PATCH] chore: Upgrade Kotlin to 2.0.21 --- README.md | 12 +- buildSrc/build.gradle | 6 +- ...dius.pact.kotlin-common-conventions.gradle | 9 +- config/detekt-config.yml | 192 +++++++++---- .../pact/consumer/dsl/DslJsonBodyBuilder.kt | 2 +- .../com/dius/pact/consumer/dsl/PactBuilder.kt | 3 +- .../dius/pact/consumer/dsl/PactDslJsonBody.kt | 256 ++++++++++++------ 7 files changed, 316 insertions(+), 164 deletions(-) diff --git a/README.md b/README.md index 57f8aaa69..632da882a 100644 --- a/README.md +++ b/README.md @@ -46,12 +46,12 @@ and in the [Pact-JVM wiki](https://github.com/pact-foundation/pact-jvm/wiki). [S ## Supported JDK and specification versions: -| Branch | Specification | JDK | Kotlin Version | Latest Version | Notes | -|-----------------------------------------------------------------------------------|---------------|------------|----------------|----------------|-------| -| [4.7.x](https://github.com/pact-foundation/pact-jvm/blob/v4.7.x/README.md) | V4 + plugins | 17-19 | 1.8.22 | 4.7.0-beta.0 | | -| [4.6.x](https://github.com/pact-foundation/pact-jvm/blob/v4.6.x/README.md) master | V4 + plugins | 17-18 | 1.8.22 | 4.6.15 | | -| [4.5.x](https://github.com/pact-foundation/pact-jvm/blob/v4.5.x/README.md) | V4 + plugins | 11+/17+(1) | 1.7.20 | 4.5.13 | | -| [4.1.x](https://github.com/pact-foundation/pact-jvm/blob/v4.1.x/README.md) | V3 | 8-12 | 1.3.72 | 4.1.43 | | +| Branch | Specification | JDK | Kotlin Version | Latest Version | Notes | +|-----------------------------------------------------------------------------------|---------------|-----------------------|----------------|----------------|-------| +| [4.7.x](https://github.com/pact-foundation/pact-jvm/blob/v4.7.x/README.md) | V4 + plugins | 17+ (tested up to 23) | 2.0.21 | 4.7.0-beta.0 | | +| [4.6.x](https://github.com/pact-foundation/pact-jvm/blob/v4.6.x/README.md) master | V4 + plugins | 17-18 | 1.8.22 | 4.6.15 | | +| [4.5.x](https://github.com/pact-foundation/pact-jvm/blob/v4.5.x/README.md) | V4 + plugins | 11+/17+(1) | 1.7.20 | 4.5.13 | | +| [4.1.x](https://github.com/pact-foundation/pact-jvm/blob/v4.1.x/README.md) | V3 | 8-12 | 1.3.72 | 4.1.43 | | **Notes:** * **1:** Spring6 support library requires JDK 17+. The rest of Pact-JVM 4.5.x libs require 11+. diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index d9f3f26e8..2f0acd54f 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -10,8 +10,8 @@ repositories { } dependencies { - implementation 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.22' - implementation 'io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.21.0' - implementation 'org.jetbrains.dokka:dokka-gradle-plugin:1.8.20' + implementation 'org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21' + implementation 'io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.7' + implementation 'org.jetbrains.dokka:dokka-gradle-plugin:1.9.20' implementation 'org.apache.commons:commons-text:1.5' } diff --git a/buildSrc/src/main/groovy/au.com.dius.pact.kotlin-common-conventions.gradle b/buildSrc/src/main/groovy/au.com.dius.pact.kotlin-common-conventions.gradle index d21650c73..1a0347220 100644 --- a/buildSrc/src/main/groovy/au.com.dius.pact.kotlin-common-conventions.gradle +++ b/buildSrc/src/main/groovy/au.com.dius.pact.kotlin-common-conventions.gradle @@ -35,7 +35,7 @@ dependencies { api 'org.apache.tika:tika-core:2.9.1' api 'io.github.oshai:kotlin-logging-jvm:5.1.4' - implementation 'org.jetbrains.kotlin:kotlin-stdlib' + implementation 'org.jetbrains.kotlin:kotlin-stdlib:2.0.21' implementation 'org.apache.commons:commons-lang3:3.12.0' implementation 'org.apache.commons:commons-text:1.10.0' implementation 'org.apache.commons:commons-collections4:4.4' @@ -70,11 +70,11 @@ dependencies { } // Align versions of all Kotlin components - implementation platform('org.jetbrains.kotlin:kotlin-bom') + implementation platform('org.jetbrains.kotlin:kotlin-bom:2.0.21') // Use the Kotlin JDK 8 standard library. - implementation 'org.jetbrains.kotlin:kotlin-stdlib' - implementation 'org.jetbrains.kotlin:kotlin-reflect' + implementation 'org.jetbrains.kotlin:kotlin-stdlib:2.0.21' + implementation 'org.jetbrains.kotlin:kotlin-reflect:2.0.21' codenarc('org.codenarc:CodeNarc:3.5.0-groovy-4.0') codenarc('org.apache.groovy:groovy:4.0.23') @@ -112,6 +112,5 @@ codenarcTest { } detekt { - failFast = false config = files(rootProject.file("config/detekt-config.yml")) } diff --git a/config/detekt-config.yml b/config/detekt-config.yml index 46d34e261..33dcf4839 100755 --- a/config/detekt-config.yml +++ b/config/detekt-config.yml @@ -10,6 +10,7 @@ build: config: validation: true warningsAsErrors: false + checkExhaustiveness: false # when writing own rules with new properties, exclude the property path e.g.: 'my_rule_set,.*>.*>[my_property]' excludes: '' @@ -47,6 +48,7 @@ output-reports: # - 'XmlOutputReport' # - 'HtmlOutputReport' # - 'MdOutputReport' + # - 'SarifOutputReport' comments: active: true @@ -65,7 +67,7 @@ comments: endOfSentenceFormat: '([.?!][ \t\n\r\f<])|([.?!:]$)' KDocReferencesNonPublicProperty: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] OutdatedDocumentation: active: false matchTypeParameters: true @@ -73,20 +75,26 @@ comments: allowParamOnConstructorProperties: false UndocumentedPublicClass: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] searchInNestedClass: true searchInInnerClass: true searchInInnerObject: true searchInInnerInterface: true + searchInProtectedClass: false UndocumentedPublicFunction: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] + searchProtectedFunction: false UndocumentedPublicProperty: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] + searchProtectedProperty: false complexity: active: true + CognitiveComplexMethod: + active: false + threshold: 15 ComplexCondition: active: true threshold: 4 @@ -95,7 +103,8 @@ complexity: threshold: 10 includeStaticDeclarations: false includePrivateDeclarations: false - ComplexMethod: + ignoreOverloaded: false + CyclomaticComplexMethod: active: true threshold: 15 ignoreSingleWhenExpression: false @@ -150,14 +159,14 @@ complexity: active: false StringLiteralDuplication: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] threshold: 3 ignoreAnnotation: true excludeStringsWithLessThan5Characters: true ignoreStringsRegex: '$^' TooManyFunctions: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] thresholdInFiles: 20 thresholdInClasses: 20 thresholdInInterfaces: 20 @@ -166,6 +175,7 @@ complexity: ignoreDeprecated: false ignorePrivate: false ignoreOverridden: false + ignoreAnnotatedFunctions: [] coroutines: active: true @@ -181,6 +191,8 @@ coroutines: active: true SleepInsteadOfDelay: active: true + SuspendFunSwallowedCancellation: + active: false SuspendFunWithCoroutineScopeReceiver: active: false SuspendFunWithFlowReturnType: @@ -232,7 +244,7 @@ exceptions: - 'toString' InstanceOfCheckForException: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] NotImplementedDeclaration: active: false ObjectExtendsThrowable: @@ -258,7 +270,7 @@ exceptions: active: false ThrowingExceptionsWithoutMessageOrCause: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] exceptions: - 'ArrayIndexOutOfBoundsException' - 'Exception' @@ -273,7 +285,7 @@ exceptions: active: true TooGenericExceptionCaught: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] exceptionNames: - 'ArrayIndexOutOfBoundsException' - 'Error' @@ -297,7 +309,6 @@ naming: BooleanPropertyNaming: active: false allowedPattern: '^(is|has|are)' - ignoreOverridden: true ClassNaming: active: true classPattern: '[A-Z][a-zA-Z0-9]*' @@ -306,7 +317,6 @@ naming: parameterPattern: '[a-z][A-Za-z0-9]*' privateParameterPattern: '[a-z][A-Za-z0-9]*' excludeClassPattern: '$^' - ignoreOverridden: true EnumNaming: active: true enumEntryPattern: '[A-Z][_a-zA-Z0-9]*' @@ -321,15 +331,13 @@ naming: minimumFunctionNameLength: 3 FunctionNaming: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] functionPattern: '[a-z][a-zA-Z0-9]*' excludeClassPattern: '$^' - ignoreOverridden: true FunctionParameterNaming: active: true parameterPattern: '_?[a-z][A-Za-z0-9]*' excludeClassPattern: '$^' - ignoreOverridden: true InvalidPackageDeclaration: active: true rootPackage: '' @@ -371,7 +379,6 @@ naming: variablePattern: '[a-z][A-Za-z0-9]*' privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*' excludeClassPattern: '$^' - ignoreOverridden: true performance: active: true @@ -382,10 +389,12 @@ performance: threshold: 3 ForEachOnRange: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] SpreadOperator: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] + UnnecessaryPartOfBinaryExpression: + active: false UnnecessaryTemporaryInstantiation: active: true @@ -395,6 +404,8 @@ potential-bugs: active: true forbiddenTypePatterns: - 'kotlin.String' + CastNullableToNonNullableType: + active: false CastToNullableType: active: false Deprecation: @@ -412,10 +423,9 @@ potential-bugs: - 'java.util.HashSet' - 'java.util.LinkedHashMap' - 'java.util.HashMap' - DuplicateCaseInWhenExpression: - active: true ElseCaseInsteadOfExhaustiveWhen: active: false + ignoredSubjectTypes: [] EqualsAlwaysReturnsTrueOrFalse: active: true EqualsWithHashCodeExist: @@ -428,12 +438,19 @@ potential-bugs: active: true IgnoredReturnValue: active: true - restrictToAnnotatedMethods: true + restrictToConfig: true returnValueAnnotations: + - 'CheckResult' - '*.CheckResult' + - 'CheckReturnValue' - '*.CheckReturnValue' ignoreReturnValueAnnotations: + - 'CanIgnoreReturnValue' - '*.CanIgnoreReturnValue' + returnValueTypes: + - 'kotlin.sequences.Sequence' + - 'kotlinx.coroutines.flow.*Flow' + - 'java.util.stream.*Stream' ignoreFunctionCall: [] ImplicitDefaultLocale: active: false @@ -448,24 +465,23 @@ potential-bugs: active: true LateinitUsage: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] ignoreOnClassesPattern: '' MapGetWithNotNullAssertionOperator: active: true MissingPackageDeclaration: active: false excludes: ['**/*.kts'] - MissingWhenCase: - active: true - allowElseExpression: true NullCheckOnMutableProperty: active: false NullableToStringCall: active: false - RedundantElseInWhen: - active: true + PropertyUsedBeforeDeclaration: + active: false UnconditionalJumpStatementInLoop: active: false + UnnecessaryNotNullCheck: + active: false UnnecessaryNotNullOperator: active: true UnnecessarySafeCall: @@ -476,7 +492,7 @@ potential-bugs: active: true UnsafeCallOnNullableType: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] UnsafeCast: active: true UnusedUnaryOperator: @@ -488,6 +504,16 @@ potential-bugs: style: active: true + AlsoCouldBeApply: + active: false + BracesOnIfStatements: + active: false + singleLine: 'never' + multiLine: 'always' + BracesOnWhenStatements: + active: false + singleLine: 'necessary' + multiLine: 'consistent' CanBeNonNullable: active: false CascadingCallWrapping: @@ -499,12 +525,24 @@ style: active: false DataClassContainsFunctions: active: false - conversionFunctionPrefix: 'to' + conversionFunctionPrefix: + - 'to' + allowOperators: false DataClassShouldBeImmutable: active: false DestructuringDeclarationWithTooManyEntries: - active: false - maxDestructuringEntries: 3 + active: true + maxDestructuringEntries: 9 + DoubleNegativeLambda: + active: false + negativeFunctions: + - reason: 'Use `takeIf` instead.' + value: 'takeUnless' + - reason: 'Use `all` instead.' + value: 'none' + negativeFunctionNameParts: + - 'not' + - 'non' EqualsNullCall: active: true EqualsOnSignatureLine: @@ -516,13 +554,33 @@ style: ExpressionBodySyntax: active: false includeLineWrapping: false + ForbiddenAnnotation: + active: false + annotations: + - reason: 'it is a java annotation. Use `Suppress` instead.' + value: 'java.lang.SuppressWarnings' + - reason: 'it is a java annotation. Use `kotlin.Deprecated` instead.' + value: 'java.lang.Deprecated' + - reason: 'it is a java annotation. Use `kotlin.annotation.MustBeDocumented` instead.' + value: 'java.lang.annotation.Documented' + - reason: 'it is a java annotation. Use `kotlin.annotation.Target` instead.' + value: 'java.lang.annotation.Target' + - reason: 'it is a java annotation. Use `kotlin.annotation.Retention` instead.' + value: 'java.lang.annotation.Retention' + - reason: 'it is a java annotation. Use `kotlin.annotation.Repeatable` instead.' + value: 'java.lang.annotation.Repeatable' + - reason: 'Kotlin does not support @Inherited annotation, see https://youtrack.jetbrains.com/issue/KT-22265' + value: 'java.lang.annotation.Inherited' ForbiddenComment: - active: false - values: - - 'FIXME:' - - 'STOPSHIP:' + active: true + comments: + - reason: 'Forbidden FIXME todo marker in comment, please fix the problem.' + value: 'FIXME:' + - reason: 'Forbidden STOPSHIP todo marker in comment, please address the problem before shipping the code.' + value: 'STOPSHIP:' +# - reason: 'Forbidden TODO todo marker in comment, please do the changes.' +# value: 'TODO:' allowedPatterns: '' - customMessage: '' ForbiddenImport: active: false imports: [] @@ -530,14 +588,10 @@ style: ForbiddenMethodCall: active: false methods: - - 'kotlin.io.print' - - 'kotlin.io.println' - ForbiddenPublicDataClass: - active: true - excludes: ['**'] - ignorePackages: - - '*.internal' - - '*.internal.*' + - reason: 'print does not allow you to configure the output stream. Use a logger instead.' + value: 'kotlin.io.print' + - reason: 'println does not allow you to configure the output stream. Use a logger instead.' + value: 'kotlin.io.println' ForbiddenSuppress: active: false rules: [] @@ -549,19 +603,13 @@ style: active: true ignoreOverridableFunction: true ignoreActualFunction: true - excludedFunctions: '' - LibraryCodeMustSpecifyReturnType: - active: true - excludes: ['**'] - LibraryEntitiesShouldNotBePublic: - active: true - excludes: ['**'] + excludedFunctions: [] LoopWithTooManyJumpStatements: active: true maxJumpCount: 1 MagicNumber: active: false - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**', '**/*.kts'] + excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**', '**/*.kts'] ignoreNumbers: - '-1' - '0' @@ -577,8 +625,6 @@ style: ignoreEnums: false ignoreRanges: false ignoreExtensionFunctions: true - MandatoryBracesIfStatements: - active: false MandatoryBracesLoops: active: false MaxChainedCallsOnSameLine: @@ -590,12 +636,19 @@ style: excludePackageStatements: true excludeImportStatements: true excludeCommentStatements: false + excludeRawStrings: true MayBeConst: active: true ModifierOrder: active: true MultilineLambdaItParameter: active: false + MultilineRawStringIndentation: + active: false + indentSize: 4 + trimmingMethods: + - 'trimIndent' + - 'trimMargin' NestedClassesVisibility: active: true NewLineAtEndOfFile: @@ -610,8 +663,6 @@ style: active: true OptionalUnit: active: false - OptionalWhenBraces: - active: false PreferToOverPairSyntax: active: false ProtectedMemberInFinalClass: @@ -625,7 +676,8 @@ style: ReturnCount: active: true max: 2 - excludedFunctions: 'equals' + excludedFunctions: + - 'equals' excludeLabeled: false excludeReturnFromLambda: true excludeGuardClauses: false @@ -635,12 +687,21 @@ style: active: true SpacingBetweenPackageAndImports: active: false + StringShouldBeRawString: + active: false + maxEscapedCharacterCount: 2 + ignoredCharacters: [] ThrowsCount: active: true max: 2 excludeGuardClauses: false TrailingWhitespace: active: false + TrimMultilineRawString: + active: false + trimmingMethods: + - 'trimIndent' + - 'trimMargin' UnderscoresInNumericLiterals: active: false acceptableLength: 4 @@ -653,6 +714,8 @@ style: active: true UnnecessaryBackticks: active: false + UnnecessaryBracesAroundTrailingLambda: + active: false UnnecessaryFilter: active: true UnnecessaryInheritance: @@ -663,15 +726,22 @@ style: active: false UnnecessaryParentheses: active: false + allowForUnclearPrecedence: false UntilInsteadOfRangeTo: active: false UnusedImports: active: false + UnusedParameter: + active: true + allowedNames: 'ignored|expected' UnusedPrivateClass: active: true UnusedPrivateMember: active: true - allowedNames: '(_|ignored|expected|serialVersionUID)' + allowedNames: '' + UnusedPrivateProperty: + active: true + allowedNames: '_|ignored|expected|serialVersionUID' UseAnyOrNoneInsteadOfFind: active: true UseArrayLiteralsInAnnotations: @@ -689,14 +759,19 @@ style: active: false UseIfInsteadOfWhen: active: false + ignoreWhenContainingVariableDeclaration: false UseIsNullOrEmpty: active: true + UseLet: + active: false UseOrEmpty: active: true UseRequire: active: true UseRequireNotNull: active: true + UseSumOfInsteadOfFlatMapSize: + active: false UselessCallOnNotNull: active: true UtilityClassWithPublicConstructor: @@ -706,6 +781,5 @@ style: ignoreLateinitVar: false WildcardImport: active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] excludeImports: - 'java.util.*' diff --git a/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/DslJsonBodyBuilder.kt b/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/DslJsonBodyBuilder.kt index 0ef13256b..2c55d841d 100644 --- a/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/DslJsonBodyBuilder.kt +++ b/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/DslJsonBodyBuilder.kt @@ -100,4 +100,4 @@ class DslJsonBodyBuilder { } } } -} \ No newline at end of file +} diff --git a/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/PactBuilder.kt b/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/PactBuilder.kt index 6585b436a..005bcddea 100644 --- a/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/PactBuilder.kt +++ b/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/PactBuilder.kt @@ -24,7 +24,8 @@ import au.com.dius.pact.core.model.generators.Generators import au.com.dius.pact.core.model.matchingrules.MatchingRulesImpl import au.com.dius.pact.core.model.v4.MessageContents import au.com.dius.pact.core.support.Json.toJson -import au.com.dius.pact.core.support.Result.* +import au.com.dius.pact.core.support.Result.Ok +import au.com.dius.pact.core.support.Result.Err import au.com.dius.pact.core.support.deepMerge import au.com.dius.pact.core.support.isNotEmpty import au.com.dius.pact.core.support.json.JsonValue diff --git a/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/PactDslJsonBody.kt b/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/PactDslJsonBody.kt index 82f1cf945..9ab32cf66 100755 --- a/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/PactDslJsonBody.kt +++ b/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/PactDslJsonBody.kt @@ -53,7 +53,7 @@ import java.util.regex.Pattern */ @Suppress("LargeClass", "TooManyFunctions", "SpreadOperator") open class PactDslJsonBody : DslPart { - override var body: JsonValue + override var body: JsonValue = JsonValue.Object() /** * Constructs a new body as a root @@ -176,10 +176,14 @@ open class PactDslJsonBody : DslPart { require(values.isNotEmpty()) { "At least one example value is required" } - if (body is JsonValue.Object && values.size > 1) { - throw IllegalArgumentException("You provided multiple example values (${values.size}) but only one was expected") - } else if (body is JsonValue.Array && body.size() < values.size) { - throw IllegalArgumentException("You provided ${values.size} example values but ${body.size()} was expected") + if (body is JsonValue.Object) { + require(values.size == 1) { + "You provided multiple example values (${values.size}) but only one was expected" + } + } else if (body is JsonValue.Array) { + require(body.size() >= values.size) { + "You provided ${values.size} example values but ${body.size()} was expected" + } } when (val body = body) { @@ -214,10 +218,14 @@ open class PactDslJsonBody : DslPart { require(values.isNotEmpty()) { "At least one example value is required" } - if (body is JsonValue.Object && values.size > 1) { - throw IllegalArgumentException("You provided multiple example values (${values.size}) but only one was expected") - } else if (body is JsonValue.Array && body.size() < values.size) { - throw IllegalArgumentException("You provided ${values.size} example values but ${body.size()} was expected") + if (body is JsonValue.Object) { + require(values.size == 1) { + "You provided multiple example values (${values.size}) but only one was expected" + } + } else if (body is JsonValue.Array) { + require(body.size() >= values.size) { + "You provided ${values.size} example values but ${body.size()} was expected" + } } when (val body = body) { @@ -245,10 +253,14 @@ open class PactDslJsonBody : DslPart { require(values.none { it == null }) { "Example values can not be null" } - if (body is JsonValue.Object && values.size > 1) { - throw IllegalArgumentException("You provided multiple example values (${values.size}) but only one was expected") - } else if (body is JsonValue.Array && body.size() < values.size) { - throw IllegalArgumentException("You provided ${values.size} example values but ${body.size()} was expected") + if (body is JsonValue.Object) { + require(values.size == 1) { + "You provided multiple example values (${values.size}) but only one was expected" + } + } else if (body is JsonValue.Array) { + require(body.size() >= values.size) { + "You provided ${values.size} example values but ${body.size()} was expected" + } } when (val body = body) { @@ -272,12 +284,14 @@ open class PactDslJsonBody : DslPart { require(examples.isNotEmpty()) { "At least one example value is required" } - if (body is JsonValue.Object && examples.size > 1) { - throw IllegalArgumentException( - "You provided multiple example examples (${examples.size}) but only one was expected" - ) - } else if (body is JsonValue.Array && body.size() < examples.size) { - throw IllegalArgumentException("You provided ${examples.size} example values but ${body.size()} was expected") + if (body is JsonValue.Object) { + require(examples.size == 1) { + "You provided multiple example values (${examples.size}) but only one was expected" + } + } else if (body is JsonValue.Array) { + require(body.size() >= examples.size) { + "You provided ${examples.size} example values but ${body.size()} was expected" + } } when (val body = body) { @@ -337,12 +351,14 @@ open class PactDslJsonBody : DslPart { require(examples.none { it == null }) { "Example values can not be null" } - if (body is JsonValue.Object && examples.size > 1) { - throw IllegalArgumentException( + if (body is JsonValue.Object) { + require(examples.size == 1) { "You provided multiple example values (${examples.size}) but only one was expected" - ) - } else if (body is JsonValue.Array && body.size() < examples.size) { - throw IllegalArgumentException("You provided ${examples.size} example values but ${body.size()} was expected") + } + } else if (body is JsonValue.Array) { + require(body.size() >= examples.size) { + "You provided ${examples.size} example values but ${body.size()} was expected" + } } when (val body = body) { @@ -398,10 +414,14 @@ open class PactDslJsonBody : DslPart { require(numbers.none { it == null }) { "Example values can not be null" } - if (body is JsonValue.Object && numbers.size > 1) { - throw IllegalArgumentException("You provided multiple example values (${numbers.size}) but only one was expected") - } else if (body is JsonValue.Array && body.size() < numbers.size) { - throw IllegalArgumentException("You provided ${numbers.size} example values but ${body.size()} was expected") + if (body is JsonValue.Object) { + require(numbers.size == 1) { + "You provided multiple example values (${numbers.size}) but only one was expected" + } + } else if (body is JsonValue.Array) { + require(body.size() >= numbers.size) { + "You provided ${numbers.size} example values but ${body.size()} was expected" + } } when (val body = body) { @@ -457,10 +477,14 @@ open class PactDslJsonBody : DslPart { require(numbers.none { it == null }) { "Example values can not be null" } - if (body is JsonValue.Object && numbers.size > 1) { - throw IllegalArgumentException("You provided multiple example values (${numbers.size}) but only one was expected") - } else if (body is JsonValue.Array && body.size() < numbers.size) { - throw IllegalArgumentException("You provided ${numbers.size} example values but ${body.size()} was expected") + if (body is JsonValue.Object) { + require(numbers.size == 1) { + "You provided multiple example values (${numbers.size}) but only one was expected" + } + } else if (body is JsonValue.Array) { + require(body.size() >= numbers.size) { + "You provided ${numbers.size} example values but ${body.size()} was expected" + } } when (val body = body) { @@ -490,10 +514,14 @@ open class PactDslJsonBody : DslPart { require(numbers.none { it == null }) { "Example values can not be null" } - if (body is JsonValue.Object && numbers.size > 1) { - throw IllegalArgumentException("You provided multiple example values (${numbers.size}) but only one was expected") - } else if (body is JsonValue.Array && body.size() < numbers.size) { - throw IllegalArgumentException("You provided ${numbers.size} example values but ${body.size()} was expected") + if (body is JsonValue.Object) { + require(numbers.size == 1) { + "You provided multiple example values (${numbers.size}) but only one was expected" + } + } else if (body is JsonValue.Array) { + require(body.size() >= numbers.size) { + "You provided ${numbers.size} example values but ${body.size()} was expected" + } } when (val body = body) { @@ -549,10 +577,14 @@ open class PactDslJsonBody : DslPart { require(numbers.none { it == null }) { "Example values can not be null" } - if (body is JsonValue.Object && numbers.size > 1) { - throw IllegalArgumentException("You provided multiple example values (${numbers.size}) but only one was expected") - } else if (body is JsonValue.Array && body.size() < numbers.size) { - throw IllegalArgumentException("You provided ${numbers.size} example values but ${body.size()} was expected") + if (body is JsonValue.Object) { + require(numbers.size == 1) { + "You provided multiple example values (${numbers.size}) but only one was expected" + } + } else if (body is JsonValue.Array) { + require(body.size() >= numbers.size) { + "You provided ${numbers.size} example values but ${body.size()} was expected" + } } when (val body = body) { @@ -582,10 +614,14 @@ open class PactDslJsonBody : DslPart { require(numbers.none { it == null }) { "Example values can not be null" } - if (body is JsonValue.Object && numbers.size > 1) { - throw IllegalArgumentException("You provided multiple example values (${numbers.size}) but only one was expected") - } else if (body is JsonValue.Array && body.size() < numbers.size) { - throw IllegalArgumentException("You provided ${numbers.size} example values but ${body.size()} was expected") + if (body is JsonValue.Object) { + require(numbers.size == 1) { + "You provided multiple example values (${numbers.size}) but only one was expected" + } + } else if (body is JsonValue.Array) { + require(body.size() >= numbers.size) { + "You provided ${numbers.size} example values but ${body.size()} was expected" + } } when (val body = body) { @@ -721,12 +757,14 @@ open class PactDslJsonBody : DslPart { require(examples.none { it == null }) { "Example values can not be null" } - if (body is JsonValue.Object && examples.size > 1) { - throw IllegalArgumentException( + if (body is JsonValue.Object) { + require(examples.size == 1) { "You provided multiple example values (${examples.size}) but only one was expected" - ) - } else if (body is JsonValue.Array && body.size() < examples.size) { - throw IllegalArgumentException("You provided ${examples.size} example values but ${body.size()} was expected") + } + } else if (body is JsonValue.Array) { + require(body.size() >= examples.size) { + "You provided ${examples.size} example values but ${body.size()} was expected" + } } when (val body = body) { @@ -758,10 +796,14 @@ open class PactDslJsonBody : DslPart { require(values.none { it == null }) { "Example values can not be null" } - if (body is JsonValue.Object && values.size > 1) { - throw IllegalArgumentException("You provided multiple example values (${values.size}) but only one was expected") - } else if (body is JsonValue.Array && body.size() < values.size) { - throw IllegalArgumentException("You provided ${values.size} example values but ${body.size()} was expected") + if (body is JsonValue.Object) { + require(values.size == 1) { + "You provided multiple example values (${values.size}) but only one was expected" + } + } else if (body is JsonValue.Array) { + require(body.size() >= values.size) { + "You provided ${values.size} example values but ${body.size()} was expected" + } } val re = Regex(regex) @@ -880,10 +922,14 @@ open class PactDslJsonBody : DslPart { require(examples.isNotEmpty()) { "At least one example value is required" } - if (body is JsonValue.Object && examples.size > 1) { - throw IllegalArgumentException("You provided multiple example values ${examples.size} but only one was expected") - } else if (body is JsonValue.Array && body.size() < examples.size) { - throw IllegalArgumentException("You provided ${examples.size} example values but ${body.size()} was expected") + if (body is JsonValue.Object) { + require(examples.size == 1) { + "You provided multiple example values (${examples.size}) but only one was expected" + } + } else if (body is JsonValue.Array) { + require(body.size() >= examples.size) { + "You provided ${examples.size} example values but ${body.size()} was expected" + } } val formatter = DateTimeFormatter.ofPattern(format).withZone(timeZone.toZoneId()) @@ -936,10 +982,14 @@ open class PactDslJsonBody : DslPart { require(examples.isNotEmpty()) { "At least one example value is required" } - if (body is JsonValue.Object && examples.size > 1) { - throw IllegalArgumentException("You provided multiple example values ${examples.size} but only one was expected") - } else if (body is JsonValue.Array && body.size() < examples.size) { - throw IllegalArgumentException("You provided ${examples.size} example values but ${body.size()} was expected") + if (body is JsonValue.Object) { + require(examples.size == 1) { + "You provided multiple example values (${examples.size}) but only one was expected" + } + } else if (body is JsonValue.Array) { + require(body.size() >= examples.size) { + "You provided ${examples.size} example values but ${body.size()} was expected" + } } val formatter = DateTimeFormatter.ofPattern(format).withZone(timeZone.toZoneId()) @@ -1038,10 +1088,14 @@ open class PactDslJsonBody : DslPart { require(examples.isNotEmpty()) { "At least one example value is required" } - if (body is JsonValue.Object && examples.size > 1) { - throw IllegalArgumentException("You provided multiple example values ${examples.size} but only one was expected") - } else if (body is JsonValue.Array && body.size() < examples.size) { - throw IllegalArgumentException("You provided ${examples.size} example values but ${body.size()} was expected") + if (body is JsonValue.Object) { + require(examples.size == 1) { + "You provided multiple example values (${examples.size}) but only one was expected" + } + } else if (body is JsonValue.Array) { + require(body.size() >= examples.size) { + "You provided ${examples.size} example values but ${body.size()} was expected" + } } val instance = FastDateFormat.getInstance(format, timeZone) @@ -1070,10 +1124,14 @@ open class PactDslJsonBody : DslPart { require(examples.isNotEmpty()) { "At least one example value is required" } - if (body is JsonValue.Object && examples.size > 1) { - throw IllegalArgumentException("You provided multiple example values ${examples.size} but only one was expected") - } else if (body is JsonValue.Array && body.size() < examples.size) { - throw IllegalArgumentException("You provided ${examples.size} example values but ${body.size()} was expected") + if (body is JsonValue.Object) { + require(examples.size == 1) { + "You provided multiple example values (${examples.size}) but only one was expected" + } + } else if (body is JsonValue.Array) { + require(body.size() >= examples.size) { + "You provided ${examples.size} example values but ${body.size()} was expected" + } } val formatter = DateTimeFormatter.ofPattern(format) @@ -1176,10 +1234,14 @@ open class PactDslJsonBody : DslPart { require(examples.isNotEmpty()) { "At least one example value is required" } - if (body is JsonValue.Object && examples.size > 1) { - throw IllegalArgumentException("You provided multiple example values ${examples.size} but only one was expected") - } else if (body is JsonValue.Array && body.size() < examples.size) { - throw IllegalArgumentException("You provided ${examples.size} example values but ${body.size()} was expected") + if (body is JsonValue.Object) { + require(examples.size == 1) { + "You provided multiple example values (${examples.size}) but only one was expected" + } + } else if (body is JsonValue.Array) { + require(body.size() >= examples.size) { + "You provided ${examples.size} example values but ${body.size()} was expected" + } } val instance = FastDateFormat.getInstance(format, timeZone) @@ -1604,10 +1666,14 @@ open class PactDslJsonBody : DslPart { require(examples.isNotEmpty()) { "At least one example value is required" } - if (body is JsonValue.Object && examples.size > 1) { - throw IllegalArgumentException("You provided multiple example values ${examples.size} but only one was expected") - } else if (body is JsonValue.Array && body.size() < examples.size) { - throw IllegalArgumentException("You provided ${examples.size} example values but ${body.size()} was expected") + if (body is JsonValue.Object) { + require(examples.size == 1) { + "You provided multiple example values (${examples.size}) but only one was expected" + } + } else if (body is JsonValue.Array) { + require(body.size() >= examples.size) { + "You provided ${examples.size} example values but ${body.size()} was expected" + } } when (val body = body) { @@ -1643,10 +1709,14 @@ open class PactDslJsonBody : DslPart { require(examples.isNotEmpty()) { "At least one example value is required" } - if (body is JsonValue.Object && examples.size > 1) { - throw IllegalArgumentException("You provided multiple example values ${examples.size} but only one was expected") - } else if (body is JsonValue.Array && body.size() < examples.size) { - throw IllegalArgumentException("You provided ${examples.size} example values but ${body.size()} was expected") + if (body is JsonValue.Object) { + require(examples.size == 1) { + "You provided multiple example values (${examples.size}) but only one was expected" + } + } else if (body is JsonValue.Array) { + require(body.size() >= examples.size) { + "You provided ${examples.size} example values but ${body.size()} was expected" + } } when (val body = body) { @@ -1701,10 +1771,14 @@ open class PactDslJsonBody : DslPart { require(examples.isNotEmpty()) { "At least one example value is required" } - if (body is JsonValue.Object && examples.size > 1) { - throw IllegalArgumentException("You provided multiple example values ${examples.size} but only one was expected") - } else if (body is JsonValue.Array && body.size() < examples.size) { - throw IllegalArgumentException("You provided ${examples.size} example values but ${body.size()} was expected") + if (body is JsonValue.Object) { + require(examples.size == 1) { + "You provided multiple example values (${examples.size}) but only one was expected" + } + } else if (body is JsonValue.Array) { + require(body.size() >= examples.size) { + "You provided ${examples.size} example values but ${body.size()} was expected" + } } when (val body = body) { @@ -1915,10 +1989,14 @@ open class PactDslJsonBody : DslPart { require(examples.isNotEmpty()) { "At least one example value is required" } - if (body is JsonValue.Object && examples.size > 1) { - throw IllegalArgumentException("You provided multiple example values ${examples.size} but only one was expected") - } else if (body is JsonValue.Array && body.size() < examples.size) { - throw IllegalArgumentException("You provided ${examples.size} example values but ${body.size()} was expected") + if (body is JsonValue.Object) { + require(examples.size == 1) { + "You provided multiple example values (${examples.size}) but only one was expected" + } + } else if (body is JsonValue.Array) { + require(body.size() >= examples.size) { + "You provided ${examples.size} example values but ${body.size()} was expected" + } } when (val body = body) {