generated from kpavlov/awesome-kotlin-maven-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved code readability and maintainability of BaseWiremock by applying renaming, method extraction, field moving, and constant extraction refactorings.
- Loading branch information
Showing
15 changed files
with
217 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
-Dkotlin.compiler.incremental=true | ||
-Dmaven.install.skip=true | ||
-T12C |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
build: | ||
mvn clean verify site | ||
lint: | ||
# brew install ktlint | ||
ktlint --format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
style: | ||
active: true | ||
MethodName: | ||
active: true | ||
ignoreOverriddenFunctions: true | ||
excludeAnnotatedMethodsOrClasses: | ||
- "org.junit.jupiter.api.Test" | ||
ignoreTestFiles: true |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>me.kpavlov.finchly</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<relativePath>../parent/pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>wiremock</artifactId> | ||
<name>Finchly :: Wiremock</name> | ||
|
||
<dependencies> | ||
<!-- https://mvnrepository.com/artifact/org.wiremock/wiremock-standalone --> | ||
<dependency> | ||
<groupId>org.wiremock</groupId> | ||
<artifactId>wiremock-standalone</artifactId> | ||
<version>${wiremock.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
69 changes: 69 additions & 0 deletions
69
wiremock/src/main/kotlin/me/kpavlov/finchly/wiremock/BaseWiremock.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package me.kpavlov.finchly.wiremock | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer | ||
import com.github.tomakehurst.wiremock.client.VerificationException | ||
|
||
/** | ||
* Base class for managing a WireMock server instance. | ||
* | ||
* The server is started upon initialization. | ||
* Provides utility methods for managing stub mappings and verifying unmatched requests. | ||
* | ||
* @param mock The WireMock server instance to manage. | ||
*/ | ||
public abstract class BaseWiremock( | ||
protected val mock: WireMockServer, | ||
) { | ||
init { | ||
mock.start() | ||
} | ||
|
||
/** | ||
* Retrieves the port number on which the WireMock server instance is running. | ||
* | ||
* @return the port number on which the WireMock server instance is listening. | ||
*/ | ||
public fun port(): Int = mock.port() | ||
|
||
/** | ||
* Removes a specific stub mapping from the WireMock server. | ||
* | ||
* @param mapping The stub mapping to remove. | ||
*/ | ||
public fun resetStub(mapping: com.github.tomakehurst.wiremock.stubbing.StubMapping) { | ||
mock.removeStub(mapping) | ||
} | ||
|
||
/** | ||
* Resets all the stub mappings in the WireMock server instance. | ||
* | ||
* This function clears all the stub mappings that have been set up in the WireMock server. | ||
* After calling this method, the server will no longer have any of the previously configured stubs. | ||
*/ | ||
public fun resetAllStubs() { | ||
mock.resetAll() | ||
} | ||
|
||
/** | ||
* Verifies that there are no unmatched requests for the WireMock server. | ||
* | ||
* This function checks the WireMock server for any requests that were not matched against | ||
* any stub mappings. If there are unmatched requests, it will find near misses and throw an | ||
* appropriate `VerificationException`. | ||
* | ||
* @throws VerificationException if there are unmatched requests or near misses. | ||
*/ | ||
public fun verifyNoUnmatchedRequests() { | ||
val unmatchedRequests = mock.findAllUnmatchedRequests() | ||
if (unmatchedRequests.isEmpty()) { | ||
return | ||
} | ||
println("Unmatched requests: $unmatchedRequests") | ||
val nearMisses = mock.findNearMissesForAllUnmatchedRequests() | ||
if (nearMisses.isEmpty()) { | ||
throw VerificationException.forUnmatchedRequests(unmatchedRequests) | ||
} else { | ||
throw VerificationException.forUnmatchedNearMisses(nearMisses) | ||
} | ||
} | ||
} |
Oops, something went wrong.