Skip to content

Commit

Permalink
Merge pull request #117 from bitPogo/feature/add-assertion-context
Browse files Browse the repository at this point in the history
Change VerificationChain
  • Loading branch information
bitPogo authored Apr 26, 2022
2 parents 7fce4f3 + dce7446 commit f3bab83
Show file tree
Hide file tree
Showing 21 changed files with 1,583 additions and 459 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ toc::[]
* `allowInterfaces`, which combines `allowInterfacesOnKmock` and `allowInterfacesOnKspy`
* `disableFactories` in order to disable the generation of `kmock` and `kspy` if needed
* `customAnnotationsForMeta` to provide a hook for the usage of customized annotation for meta/shared sources
* `assertOrder` in order to make the names more consistent
* `assertOrder` in order to make the names more consistent and preserves the old behaviour of `verifyStrictOrder`

=== Changed

Expand All @@ -48,11 +48,12 @@ toc::[]
* `kmock` and `kspy` are using now a shared function to improve compile time
* Non intrusive behaviour (spy & relaxation) is now resolved by proxy invocation rather then by proxy initialisation in order to cover edge cases
* Assertion-/VerificationChain is not coupled any longer directly to proxies and provide improved error messages
* Expectation-methods do not bleed into the global context any longer
* `verifyStrictOrder` is now used for total order of certain Proxies but allows partial order between different Proxies

=== Deprecated

* `uselessPrefixes` in the Gradle Extension
* `verifyStrictOrder` use `assertOrder` instead

=== Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ import tech.antibytes.kmock.example.contract.SampleRemoteRepositoryMock
import tech.antibytes.kmock.verification.Asserter
import tech.antibytes.kmock.verification.NonFreezingAsserter
import tech.antibytes.kmock.verification.assertOrder
import tech.antibytes.kmock.verification.hasBeenCalledWith
import tech.antibytes.kmock.verification.hasBeenCalledWithout
import tech.antibytes.kmock.verification.hasBeenStrictlyCalledWith
import tech.antibytes.kmock.verification.verify
import tech.antibytes.kmock.verification.verifyOrder
import tech.antibytes.kmock.verification.wasSetTo
import tech.antibytes.util.test.coroutine.AsyncTestReturnValue
import tech.antibytes.util.test.coroutine.clearBlockingTest
import tech.antibytes.util.test.coroutine.defaultTestContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ import tech.antibytes.kmock.example.contract.SampleLocalRepositoryMock
import tech.antibytes.kmock.example.contract.SampleRemoteRepositoryMock
import tech.antibytes.kmock.verification.Asserter
import tech.antibytes.kmock.verification.assertOrder
import tech.antibytes.kmock.verification.hasBeenCalledWith
import tech.antibytes.kmock.verification.hasBeenCalledWithout
import tech.antibytes.kmock.verification.hasBeenStrictlyCalledWith
import tech.antibytes.kmock.verification.verify
import tech.antibytes.kmock.verification.verifyOrder
import tech.antibytes.kmock.verification.wasSetTo
import tech.antibytes.util.test.coroutine.AsyncTestReturnValue
import tech.antibytes.util.test.coroutine.clearBlockingTest
import tech.antibytes.util.test.coroutine.defaultTestContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@ import tech.antibytes.kmock.example.contract.SampleLocalRepositoryMock
import tech.antibytes.kmock.example.contract.SampleRemoteRepositoryMock
import tech.antibytes.kmock.verification.Asserter
import tech.antibytes.kmock.verification.assertOrder
import tech.antibytes.kmock.verification.hasBeenCalledWith
import tech.antibytes.kmock.verification.hasBeenCalledWithout
import tech.antibytes.kmock.verification.hasBeenStrictlyCalledWith
import tech.antibytes.kmock.verification.verify
import tech.antibytes.kmock.verification.verifyOrder
import tech.antibytes.kmock.verification.wasSet
import tech.antibytes.kmock.verification.wasSetTo
import tech.antibytes.util.test.coroutine.AsyncTestReturnValue
import tech.antibytes.util.test.coroutine.clearBlockingTest
import tech.antibytes.util.test.coroutine.defaultTestContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ import tech.antibytes.kmock.example.contract.SampleLocalRepositoryMock
import tech.antibytes.kmock.example.contract.SampleRemoteRepositoryMock
import tech.antibytes.kmock.verification.Asserter
import tech.antibytes.kmock.verification.assertOrder
import tech.antibytes.kmock.verification.hasBeenCalledWith
import tech.antibytes.kmock.verification.hasBeenCalledWithout
import tech.antibytes.kmock.verification.hasBeenStrictlyCalledWith
import tech.antibytes.kmock.verification.verify
import tech.antibytes.kmock.verification.verifyOrder
import tech.antibytes.kmock.verification.wasSetTo
import tech.antibytes.util.test.coroutine.AsyncTestReturnValue
import tech.antibytes.util.test.coroutine.clearBlockingTest
import tech.antibytes.util.test.coroutine.defaultTestContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ import tech.antibytes.kmock.example.contract.SampleLocalRepositoryMock
import tech.antibytes.kmock.example.contract.SampleRemoteRepositoryMock
import tech.antibytes.kmock.verification.Asserter
import tech.antibytes.kmock.verification.assertOrder
import tech.antibytes.kmock.verification.hasBeenCalledWith
import tech.antibytes.kmock.verification.hasBeenCalledWithout
import tech.antibytes.kmock.verification.hasBeenStrictlyCalledWith
import tech.antibytes.kmock.verification.verify
import tech.antibytes.kmock.verification.verifyOrder
import tech.antibytes.kmock.verification.wasSetTo
import tech.antibytes.util.test.coroutine.AsyncTestReturnValue
import tech.antibytes.util.test.coroutine.clearBlockingTest
import tech.antibytes.util.test.coroutine.defaultTestContext
Expand Down
75 changes: 66 additions & 9 deletions kmock/src/commonMain/kotlin/tech/antibytes/kmock/KMockContract.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1253,25 +1253,21 @@ object KMockContract {

/**
* Asserts that a FunProxy was called with n-parameter.
* The arguments do not need to be complete.
* @param arguments the expected arguments.
* @param arguments or constraints which calls must match. The arguments/constraints must follow the order of the mocked/stubbed function but can contain gaps and do not need to all arguments.
* @throws AssertionError if the assertion fails
*/
fun FunProxy<*, *>.hasBeenCalledWith(vararg arguments: Any?)

/**
* Asserts that a FunProxy was called with n-parameter.
* The arguments must be complete.
* @param arguments the expected arguments.
* @param arguments or constraints which calls must match. The arguments/constraints must follow the order of the mocked/stubbed function and need to contain all arguments/constraints.
* @throws AssertionError if the assertion fails
*/
fun FunProxy<*, *>.hasBeenStrictlyCalledWith(vararg arguments: Any?)

/**
* Asserts that a FunProxy was without called n-parameter.
* The arguments do not need to be complete.
* @param proxy the actual proxy.
* @param illegal the forbidden arguments.
* @param illegal arguments or constraints which calls is not allowed not match.
* @throws AssertionError if the assertion fails
*/
fun FunProxy<*, *>.hasBeenCalledWithout(vararg illegal: Any?)
Expand All @@ -1296,13 +1292,73 @@ object KMockContract {
fun PropertyProxy<*>.wasSetTo(value: Any?)
}

/**
* Provider for Verification.
* @author Matthias Geisler
*/
interface VerificationContext {
/**
* Collects all invocation of a FunProxy.
* @return Expectation
*/
fun FunProxy<*, *>.hasBeenCalled(): Expectation

/**
* Collects all invocation of a FunProxy which contain no Arguments.
* @return Expectation
*/
fun FunProxy<*, *>.hasBeenCalledWithVoid(): Expectation

/**
* Collects all invocation of an FunProxy which matches the given Arguments.
* @param arguments or constraints which calls must match. The arguments/constraints must follow the order of the mocked/stubbed function but can contain gaps and do not need to all arguments.
* @return Expectation
* @see ArgumentConstraint
*/
fun FunProxy<*, *>.hasBeenCalledWith(vararg arguments: Any?): Expectation

/**
* Collects all invocation of an FunProxy which matches the given Arguments.
* @param arguments or constraints which calls must match. The arguments/constraints must follow the order of the mocked/stubbed function and need to contain all arguments/constraints.
* @return Expectation
* @see ArgumentConstraint
*/
fun FunProxy<*, *>.hasBeenStrictlyCalledWith(vararg arguments: Any?): Expectation

/**
* Collects all invocation of an FunProxy which matches the given Arguments.
* @param illegal arguments or constraints which calls is not allowed not match.
* @return Expectation
* @see ArgumentConstraint
*/
fun FunProxy<*, *>.hasBeenCalledWithout(vararg illegal: Any?): Expectation

/**
* Collects all invocation of an PropertyProxy Getter.
*/
fun PropertyProxy<*>.wasGotten(): Expectation

/**
* Collects all invocation of an PropertyProxy Setter.
*/
fun PropertyProxy<*>.wasSet(): Expectation

/**
* Collects all invocation of an PropertyProxy Setter with the given Value.
* @return Expectation
* @param value argument/constraint which calls must match.
* @see ArgumentConstraint
*/
fun PropertyProxy<*>.wasSetTo(value: Any?): Expectation
}

/**
* Insurance that given Proxies are covered by the AssertionChain.
* @author Matthias Geisler
*/
fun interface AssertionInsurance {
/**
* Ensures that given Proxies are covered by the AssertionChain. Use this method with caution!
* Ensures that given Proxies are covered by the AssertionChain.
* @throws IllegalStateException if a given Proxy is not covered by a AssertionChain.
*/
fun ensureVerificationOf(vararg proxies: Proxy<*, *>)
Expand Down Expand Up @@ -1351,6 +1407,7 @@ object KMockContract {

internal const val MISSING_INVOCATION = "Expected %0th call of %1 was not made."
internal const val MISMATCH = "Expected <%0> got actual <%1>."
internal const val CALL_WITH_ARGS_NOT_FOUND = "Expected %0 to be invoked with %1, but no matching call was found."
internal const val HAD_BEEN_CALLED_NO_MATCHER = "The given matcher %0 has not been found."
internal const val MISMATCHING_SIZE = "Expected <%0> arguments got actual <%1>."
internal const val ILLEGAL_VALUE = "Illegal value <%0> detected."
Expand All @@ -1363,5 +1420,5 @@ object KMockContract {
internal const val TOO_LESS_CALLS = "Expected at least %0 calls, but found only %1."
internal const val TOO_MANY_CALLS = "Expected at most %0 calls, but exceeded with %1."

internal const val NOT_PART_OF_CHAIN = "The given proxy %0 is not part of this AssertionChain."
internal const val NOT_PART_OF_CHAIN = "The given proxy %0 is not part of this chain."
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Asserter(coverAllInvocations: Boolean = false) : AsserterBase(coverAllInvo
}

/**
*
* Alias to Asserter.
* @author Matthias Geisler
*/
typealias Verifier = Asserter

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class NonFreezingAsserter(coverAllInvocations: Boolean = false) : AsserterBase(c
}

/**
*
* Alias to NonFreezingAsserter.
* @author Matthias Geisler
*/
typealias NonFreezingVerifier = NonFreezingAsserter
Loading

0 comments on commit f3bab83

Please sign in to comment.