Skip to content

Commit

Permalink
chore(pact-jvm-server): Fixed CodeNarc violations
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Nov 20, 2024
1 parent 393c22e commit 9fccb2b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'() {
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'
}
Expand All @@ -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()
}

Expand All @@ -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'
}
Expand All @@ -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()
}

Expand All @@ -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'() {
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand Down
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 9fccb2b

Please sign in to comment.