Skip to content

Commit

Permalink
chore: Cleanup compiler warmings
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Dec 2, 2024
1 parent 0bb9790 commit 78d3735
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ abstract class HttpPart: IHttpPart {
contentType.isBinaryType() || contentType.isMultipart() -> try {
OptionalBody.body(decoder.decode(body), contentType)
} catch (ex: IllegalArgumentException) {
logger.warn(ex) { "Expected body for content type $contentType to be base64 encoded" }
logger.warn { "Expected body for content type $contentType to be base64 encoded: ${ex.message}" }
OptionalBody.body(body.toByteArray(contentType.asCharset()), contentType)
}
else -> OptionalBody.body(body.toByteArray(contentType.asCharset()), contentType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import au.com.dius.pact.provider.VerificationResult
import groovy.lang.Binding
import groovy.lang.Closure
import groovy.lang.GroovyShell
import io.github.oshai.kotlinlogging.KLogging
import io.github.oshai.kotlinlogging.KotlinLogging
import org.apache.commons.lang3.StringUtils
import org.hamcrest.Matchers.anything
import org.springframework.http.HttpHeaders
Expand All @@ -39,6 +39,8 @@ import javax.mail.internet.ContentDisposition
import javax.mail.internet.MimeMultipart
import javax.mail.util.ByteArrayDataSource

private val logger = KotlinLogging.logger {}

/**
* Verifies the providers against the defined consumers using Spring MockMvc
*/
Expand All @@ -60,8 +62,9 @@ open class MvcProviderVerifier(private val debugRequestResponse: Boolean = false
val expectedResponse = interaction.response
val actualResponse = handleResponse(mvcResult.response)

// TODO: Add any plugin configuration here
verifyRequestResponsePact(expectedResponse, actualResponse, interactionMessage, failures,
interaction.interactionId.orEmpty(), false)
interaction.interactionId.orEmpty(), false, emptyMap())
} catch (e: Exception) {
failures[interactionMessage] = e
reporters.forEach {
Expand Down Expand Up @@ -98,7 +101,7 @@ open class MvcProviderVerifier(private val debugRequestResponse: Boolean = false
} else {
MockMvcRequestBuilders.request(HttpMethod.valueOf(request.method), requestUriString(request))
.headers(mapHeaders(request, true))
.content(body.value)
.content(body.value ?: ByteArray(0))
}
} else {
MockMvcRequestBuilders.request(HttpMethod.valueOf(request.method), requestUriString(request))
Expand Down Expand Up @@ -188,13 +191,16 @@ open class MvcProviderVerifier(private val debugRequestResponse: Boolean = false

val headers = mutableMapOf<String, List<String>>()
httpResponse.headerNames.forEach { headerName ->
headers[headerName] = listOf(httpResponse.getHeader(headerName))
val header = httpResponse.getHeader(headerName)
if (header != null) {
headers[headerName] = listOf(header)
}
}

val contentType = if (httpResponse.contentType.isNullOrEmpty()) {
ContentType.JSON
} else {
ContentType.fromString(httpResponse.contentType.toString())
ContentType.fromString(httpResponse.contentType!!.toString())
}

val response = ProviderResponse(httpResponse.status, headers, contentType,
Expand All @@ -204,6 +210,4 @@ open class MvcProviderVerifier(private val debugRequestResponse: Boolean = false

return response
}

companion object : KLogging()
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@ import org.springframework.core.env.Environment
class SpringEnvironmentResolver(private val environment: Environment) : ValueResolver {
override fun resolveValue(property: String?): String? {
val tuple = SystemPropertyResolver.PropertyValueTuple(property).invoke()
return environment.getProperty(tuple.propertyName, tuple.defaultValue)
return if (tuple.propertyName != null)
environment.getProperty(tuple.propertyName!!, tuple.defaultValue.orEmpty())
else null
}

override fun resolveValue(property: String?, default: String?): String? {
return environment.getProperty(property, default)
return if (property != null)
environment.getProperty(property, default.orEmpty())
else null
}

override fun propertyDefined(property: String): Boolean {
val tuple = SystemPropertyResolver.PropertyValueTuple(property).invoke()
return environment.containsProperty(tuple.propertyName)
return if (tuple.propertyName != null)
environment.containsProperty(tuple.propertyName!!)
else false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import javax.mail.internet.ContentDisposition
import javax.mail.internet.MimeMultipart
import javax.mail.util.ByteArrayDataSource

val logger = KotlinLogging.logger {}
private val logger = KotlinLogging.logger {}

class WebFluxProviderVerifier : ProviderVerifier() {

Expand Down

0 comments on commit 78d3735

Please sign in to comment.