From 9fccb2bcbfd1a00e60ceba378d9e66522b72c4c9 Mon Sep 17 00:00:00 2001 From: Ronald Holshausen Date: Thu, 21 Nov 2024 10:55:38 +1100 Subject: [PATCH] chore(pact-jvm-server): Fixed CodeNarc violations --- .../com/dius/pact/server/CompleteSpec.groovy | 22 +++++++++---------- .../dius/pact/server/PactSessionSpec.groovy | 3 ++- .../com/dius/pact/server/PublishSpec.groovy | 13 ++++++----- .../dius/pact/server/RequestRouterSpec.groovy | 2 ++ settings.gradle | 1 - 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/pact-jvm-server/src/test/groovy/au/com/dius/pact/server/CompleteSpec.groovy b/pact-jvm-server/src/test/groovy/au/com/dius/pact/server/CompleteSpec.groovy index 2743ec4ca..5f9652962 100644 --- a/pact-jvm-server/src/test/groovy/au/com/dius/pact/server/CompleteSpec.groovy +++ b/pact-jvm-server/src/test/groovy/au/com/dius/pact/server/CompleteSpec.groovy @@ -20,11 +20,11 @@ class CompleteSpec extends Specification { input | result null | null - "null" | null + 'null' | null [:] | null - [a: "b"] | null - [port: "1234"] | "1234" - [port: 1234] | "1234" + [a: 'b'] | null + [port: '1234'] | '1234' + [port: 1234] | '1234' } def 'apply returns an error if the port is not in the request body'() { @@ -43,7 +43,7 @@ class CompleteSpec extends Specification { given: def request = new Request() request.body = OptionalBody.body('{"port": "1234"}') - def state = new ServerState(["45454": Mock(StatefulMockProvider)]) + def state = new ServerState(['45454': Mock(StatefulMockProvider)]) when: def result = Complete.apply(request, state) @@ -60,7 +60,7 @@ class CompleteSpec extends Specification { getPact() >> null getSession() >> PactSession.empty } - def state = new ServerState(["1234": mockProvider]) + def state = new ServerState(['1234': mockProvider]) when: def result = Complete.apply(request, state) @@ -79,7 +79,7 @@ class CompleteSpec extends Specification { getSession() >> PactSession.empty getConfig() >> new MockProviderConfig('localhost', 1234) } - def state = new ServerState(["1234": mockProvider]) + def state = new ServerState(['1234': mockProvider]) when: Complete.apply(request, state) @@ -102,7 +102,7 @@ class CompleteSpec extends Specification { getSession() >> session getConfig() >> new MockProviderConfig('localhost', 1234) } - def state = new ServerState(["1234": mockProvider]) + def state = new ServerState(['1234': mockProvider]) def mockWriter = Mock(PactWriter) Complete.INSTANCE.pactWriter = mockWriter @@ -112,7 +112,7 @@ class CompleteSpec extends Specification { then: 1 * mockWriter.writePact(_, pact, _) result.response.status == 200 - result.newState.state.isEmpty() + result.newState.state.empty cleanup: Complete.INSTANCE.pactWriter = DefaultPactWriter.INSTANCE @@ -132,7 +132,7 @@ class CompleteSpec extends Specification { getSession() >> session getConfig() >> new MockProviderConfig('localhost', 1234) } - def state = new ServerState(["1234": mockProvider]) + def state = new ServerState(['1234': mockProvider]) def mockWriter = Mock(PactWriter) Complete.INSTANCE.pactWriter = mockWriter @@ -142,7 +142,7 @@ class CompleteSpec extends Specification { then: 0 * mockWriter.writePact(_, pact, _) result.response.status == 400 - result.newState.state.isEmpty() + result.newState.state.empty cleanup: Complete.INSTANCE.pactWriter = DefaultPactWriter.INSTANCE diff --git a/pact-jvm-server/src/test/groovy/au/com/dius/pact/server/PactSessionSpec.groovy b/pact-jvm-server/src/test/groovy/au/com/dius/pact/server/PactSessionSpec.groovy index 8ba2dca8b..64ff2887f 100644 --- a/pact-jvm-server/src/test/groovy/au/com/dius/pact/server/PactSessionSpec.groovy +++ b/pact-jvm-server/src/test/groovy/au/com/dius/pact/server/PactSessionSpec.groovy @@ -9,12 +9,13 @@ import au.com.dius.pact.core.model.RequestResponsePact import spock.lang.Specification class PactSessionSpec extends Specification { + @SuppressWarnings('LineLength') def 'invalid request returns JSON response with details about the request'() { given: def session = PactSession.empty when: - def response = session.invalidRequest(new Request("GET", "/test")) + def response = session.invalidRequest(new Request('GET', '/test')) then: response.status == 500 diff --git a/pact-jvm-server/src/test/groovy/au/com/dius/pact/server/PublishSpec.groovy b/pact-jvm-server/src/test/groovy/au/com/dius/pact/server/PublishSpec.groovy index 33901b298..828b463ee 100644 --- a/pact-jvm-server/src/test/groovy/au/com/dius/pact/server/PublishSpec.groovy +++ b/pact-jvm-server/src/test/groovy/au/com/dius/pact/server/PublishSpec.groovy @@ -3,6 +3,7 @@ package au.com.dius.pact.server import au.com.dius.pact.core.model.OptionalBody import au.com.dius.pact.core.model.Request import au.com.dius.pact.core.pactbroker.IPactBrokerClient +import au.com.dius.pact.core.support.Result import spock.lang.Specification import spock.util.environment.RestoreSystemProperties @@ -189,7 +190,7 @@ class PublishSpec extends Specification { def result = Publish.INSTANCE.publishPact(consumer, consumerVersion, provider, broker, client, tags) then: - 1 * client.uploadPactFile(_, 'version', []) >> new au.com.dius.pact.core.support.Result.Ok('OK') + 1 * client.uploadPactFile(_, 'version', []) >> new Result.Ok('OK') result.status == 200 result.body.valueAsString() == 'OK' } @@ -209,7 +210,7 @@ class PublishSpec extends Specification { Publish.INSTANCE.publishPact(consumer, consumerVersion, provider, broker, client, tags) then: - 1 * client.uploadPactFile(_, 'version', []) >> new au.com.dius.pact.core.support.Result.Ok('OK') + 1 * client.uploadPactFile(_, 'version', []) >> new Result.Ok('OK') !pactFile.exists() } @@ -226,7 +227,7 @@ class PublishSpec extends Specification { def result = Publish.INSTANCE.publishPact(consumer, consumerVersion, provider, broker, client, tags) then: - 1 * client.uploadPactFile(_, 'version', []) >> new au.com.dius.pact.core.support.Result.Err(new RuntimeException('Boom')) + 1 * client.uploadPactFile(_, 'version', []) >> new Result.Err(new RuntimeException('Boom')) result.status == 500 result.body.valueAsString() == 'Boom' } @@ -246,7 +247,7 @@ class PublishSpec extends Specification { Publish.INSTANCE.publishPact(consumer, consumerVersion, provider, broker, client, tags) then: - 1 * client.uploadPactFile(_, 'version', []) >> new au.com.dius.pact.core.support.Result.Err(new RuntimeException('Boom')) + 1 * client.uploadPactFile(_, 'version', []) >> new Result.Err(new RuntimeException('Boom')) pactFile.exists() } @@ -263,7 +264,7 @@ class PublishSpec extends Specification { Publish.INSTANCE.publishPact(consumer, consumerVersion, provider, broker, client, tags) then: - 1 * client.uploadPactFile(_, 'version', ['a', 'b', 'c']) >> new au.com.dius.pact.core.support.Result.Ok('OK') + 1 * client.uploadPactFile(_, 'version', ['a', 'b', 'c']) >> new Result.Ok('OK') } def 'publishPact handles any IO exception'() { @@ -279,7 +280,7 @@ class PublishSpec extends Specification { def result = Publish.INSTANCE.publishPact(consumer, consumerVersion, provider, broker, client, tags) then: - 1 * client.uploadPactFile(_, 'version', []) >> { throw new IOException("Boom!") } + 1 * client.uploadPactFile(_, 'version', []) >> { throw new IOException('Boom!') } result.status == 500 } } diff --git a/pact-jvm-server/src/test/groovy/au/com/dius/pact/server/RequestRouterSpec.groovy b/pact-jvm-server/src/test/groovy/au/com/dius/pact/server/RequestRouterSpec.groovy index 235a46a88..6e539419a 100644 --- a/pact-jvm-server/src/test/groovy/au/com/dius/pact/server/RequestRouterSpec.groovy +++ b/pact-jvm-server/src/test/groovy/au/com/dius/pact/server/RequestRouterSpec.groovy @@ -255,6 +255,7 @@ class RequestRouterSpec extends Specification { response.response.status == 200 } + @SuppressWarnings('LineLength') def 'dispatch sends /publish requests to the Publish controller'() { given: def request = new Request('GET', '/publish') @@ -279,6 +280,7 @@ class RequestRouterSpec extends Specification { response.response.body.valueAsString() == '{"error" : "Broker url not correctly configured please run server with -b or --broker \'http://pact-broker.adomain.com\' option" }' } + @SuppressWarnings('LineLength') def 'dispatch sends /publish/* requests to the Publish controller'() { given: def request = new Request('GET', '/publish/other') diff --git a/settings.gradle b/settings.gradle index d9a8798b2..e5fdf45e6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -25,7 +25,6 @@ if (System.getenv('GITHUB_WORKFLOW') == null) { include 'provider:lein' } -// Scala does not support JDK 20+ include 'pact-jvm-server' include 'pact-specification-test' include 'pact-publish'