Skip to content

Commit

Permalink
Change docs on Assertion-/VerificationChain changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bitPogo committed Apr 25, 2022
1 parent 872aede commit 9c5ce4c
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 65 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ toc::[]
=== Added

* `or` ArgumentConstraint
* `not` ArgumentConstraint
* `spiesOnly` in the Gradle extension, in order to tell the processor to only create `kspy`, while adding all known mocks
* `vararg` is now supported by Mocks
* `freezeOnDefault` in the Gradle extension, which sets a default freeze value for `kspy` and `kmock`
Expand All @@ -38,17 +39,20 @@ 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

=== Changed

* Generated mocks don't contain runtime logic any longer
* Mutable properties of Proxies now separate froze/unfrozen state is cleaner to improve Runtime
* `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

=== Deprecated

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

=== Removed

Expand All @@ -67,6 +71,7 @@ toc::[]

* KotlinPoet 1.10.2 -> 1.11.0
* Gradle 7.4.1 -> 7.4.2
* Android Gradle Plugin 7.1.2 -> 7.1.3


== https://github.com/bitPogo/kmock/compare/v0.1.0\...v0.1.1[0.1.1]
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Gradle
org.gradle.jvmargs=-Xmx2048m
org.gradle.parallel=true
org.gradle.parallel=false
org.gradle.dependency.verification.console=verbose
# Kotlin
kotlin.incremental.multiplatform=true
Expand Down
117 changes: 84 additions & 33 deletions kmock/src/commonMain/kotlin/tech/antibytes/kmock/KMockContract.kt
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ object KMockContract {
*/
interface FunProxy<ReturnValue, SideEffect : Function<ReturnValue>> : Proxy<ReturnValue, Array<out Any?>> {
/**
* Marks the proxy as ignore during verification (e.g. build-in methods). Meant for internal usage only!
* Marks the proxy as ignore during verification (e.g. build-in methods). Intended for internal usage only!
*/
val ignorableForVerification: Boolean

Expand Down Expand Up @@ -1050,7 +1050,7 @@ object KMockContract {
*/
fun interface Collector {
/**
* Collects a invocation of a Proxy. Meant for internal use only.
* Collects a invocation of a Proxy. Intended for internal use only.
* @param referredProxy the proxy it is referring to.
* @param referredCall the invocation index of the Proxy it refers to.
* @suppress
Expand All @@ -1060,7 +1060,7 @@ object KMockContract {

/**
* Handle with the aggregated information of a Proxy invocation.
* Meant for internal usage only!
* Intended for internal usage only!
* @author Matthias Geisler
*/
interface Expectation {
Expand Down Expand Up @@ -1094,23 +1094,27 @@ object KMockContract {
}

/**
*
* Wrapper for Arguments-Constraints
*/
internal interface ArgumentConstraintWrapper {
/**
*
* Wraps a arbitrary value to eq-Constraint if it is not a Arguments-Constraints.
* @param value a arbitrary value.
* @return ArgumentConstraint
*/
fun wrapValue(value: Any?): ArgumentConstraint

/**
*
* Wraps a arbitrary value to eq-Constraint if it is not a Arguments-Constraints and wraps that into a not-Constraint.
* @param value a arbitrary value.
* @return ArgumentConstraint the resulting not-Constraint.
*/
fun wrapNegatedValue(value: Any?): ArgumentConstraint
}

/**
* Reference to a Proxy invocation.
* Meant for internal usage only!
* Intended for internal usage only!
* @author Matthias Geisler
*/
data class Reference(
Expand All @@ -1126,27 +1130,39 @@ object KMockContract {
)

/**
*
* Internal Executor of Assertions.
* @author Matthias Geisler
*/
internal interface Assertions {
/**
*
* Asserts that a FunProxy was called.
* @param proxy the actual proxy.
* @param callIndex the index of the invocation from the proxy.
* @throws AssertionError if the assertion fails.
*/
fun hasBeenCalledAtIndex(
proxy: FunProxy<*, *>,
callIndex: Int
)

/**
*
* Asserts that a FunProxy was called without any parameter.
* @param proxy the actual proxy.
* @param callIndex the index of the invocation from the proxy.
* @throws AssertionError if the assertion fails.
*/
fun hasBeenCalledWithVoidAtIndex(
proxy: FunProxy<*, *>,
callIndex: Int
)

/**
*
* Asserts that a FunProxy was called with n-parameter.
* The arguments do not need to be complete.
* @param proxy the actual proxy.
* @param callIndex the index of the invocation from the proxy.
* @param arguments the expected arguments.
* @throws AssertionError if the assertion fails
*/
fun hasBeenCalledWithAtIndex(
proxy: FunProxy<*, *>,
Expand All @@ -1155,7 +1171,12 @@ object KMockContract {
)

/**
*
* Asserts that a FunProxy was called with n-parameter.
* The arguments must be complete.
* @param proxy the actual proxy.
* @param callIndex the index of the invocation from the proxy.
* @param arguments the expected arguments.
* @throws AssertionError if the assertion fails
*/
fun hasBeenStrictlyCalledWithAtIndex(
proxy: FunProxy<*, *>,
Expand All @@ -1164,7 +1185,12 @@ object KMockContract {
)

/**
*
* Asserts that a FunProxy was without called n-parameter.
* The arguments do not need to be complete.
* @param proxy the actual proxy.
* @param callIndex the index of the invocation from the proxy.
* @param illegal the forbidden arguments.
* @throws AssertionError if the assertion fails
*/
fun hasBeenCalledWithoutAtIndex(
proxy: FunProxy<*, *>,
Expand All @@ -1173,23 +1199,33 @@ object KMockContract {
)

/**
*
* Asserts that a PropertyProxy was invoked as a Getter.
* @param proxy the actual proxy.
* @param callIndex the index of the invocation from the proxy.
* @throws AssertionError if the assertion fails.
*/
fun wasGottenAtIndex(
proxy: PropertyProxy<*>,
callIndex: Int
)

/**
*
* Asserts that a PropertyProxy was invoked as a Setter.
* @param proxy the actual proxy.
* @param callIndex the index of the invocation from the proxy.
* @throws AssertionError if the assertion fails.
*/
fun wasSetAtIndex(
proxy: PropertyProxy<*>,
callIndex: Int
)

/**
*
* Asserts that a PropertyProxy was invoked as a Setter with a given value.
* @param proxy the actual proxy.
* @param callIndex the index of the invocation from the proxy.
* @param value the expected value.
* @throws AssertionError if the assertion fails.
*/
fun wasSetToAtIndex(
proxy: PropertyProxy<*>,
Expand All @@ -1199,46 +1235,63 @@ object KMockContract {
}

/**
*
* Provider for Assertion.
* @author Matthias Geisler
*/
interface AssertionContext {
/**
*
* Asserts that a FunProxy was called.
* @throws AssertionError if the assertion fails.
*/
fun FunProxy<*, *>.hasBeenCalled()

/**
*
* Asserts that a FunProxy was called without any parameter.
* @throws AssertionError if the assertion fails.
*/
fun FunProxy<*, *>.hasBeenCalledWithVoid()

/**
*
* Asserts that a FunProxy was called with n-parameter.
* The arguments do not need to be complete.
* @param arguments the expected 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.
* @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.
* @throws AssertionError if the assertion fails
*/
fun FunProxy<*, *>.hasBeenCalledWithout(vararg illegal: Any?)

/**
*
* Asserts that a PropertyProxy was invoked as a Getter.
* @throws AssertionError if the assertion fails.
*/
fun PropertyProxy<*>.wasGotten()

/**
*
* Asserts that a PropertyProxy was invoked as a Setter.
* @throws AssertionError if the assertion fails.
*/
fun PropertyProxy<*>.wasSet()

/**
*
* Asserts that a PropertyProxy was invoked as a Setter with a given value.
* @param value the expected value.
* @throws AssertionError if the assertion fails.
*/
fun PropertyProxy<*>.wasSetTo(value: Any?)
}
Expand All @@ -1256,16 +1309,18 @@ object KMockContract {
}

/**
*
* Combination of AssertionInsurance and AssertionContext
* @see AssertionInsurance
* @see AssertionContext
*/
interface Assert : AssertionInsurance, AssertionContext
interface ChainedAssertion : AssertionInsurance, AssertionContext

/**
* AssertionChain in order to verify over multiple Handles.
* Meant for internal purpose only!
* Intended for internal purpose only!
* @author Matthias Geisler
*/
interface AssertionChain {
internal interface AssertionChain {
/**
* Ensures that all expected or actual values are covered depending on the context.
* @throws AssertionError if the context needs to be exhaustive and not all expected or actual values are covered.
Expand All @@ -1292,8 +1347,6 @@ object KMockContract {

internal const val CALL_NOT_FOUND = "Expected %0 to be invoked, but no further calls were captured."
internal const val STRICT_CALL_NOT_MATCH = "Expected %0 to be invoked, but %1 was called."
internal const val STRICT_CALL_IDX_NOT_FOUND = "Expected %0th call of %1 was not made."
internal const val STRICT_CALL_IDX_NOT_MATCH = "Expected %0th call of %1, but it refers to the %2th call."
internal const val STRICT_MISSING_EXPECTATION = "The given verification chain covers %0 items, but only %1 were expected (%2 were referenced)."

internal const val MISSING_INVOCATION = "Expected %0th call of %1 was not made."
Expand All @@ -1306,8 +1359,6 @@ object KMockContract {
internal const val NOT_GET = "Expected a getter and got a setter."
internal const val NOT_SET = "Expected a setter and got a getter."

internal const val NON_STRICT_CALL_NOT_FOUND = "Expected %0 to be invoked, but no call was captured with the given arguments."

internal const val NOT_CALLED = "Call not found."
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."
Expand Down
Loading

0 comments on commit 9c5ce4c

Please sign in to comment.