Skip to content

Commit

Permalink
Wire new VerificationChain in
Browse files Browse the repository at this point in the history
  • Loading branch information
bitPogo committed Mar 22, 2022
1 parent 83cc97c commit ca7e519
Show file tree
Hide file tree
Showing 32 changed files with 538 additions and 1,205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class SampleController(
val objc = remoteRepository.find(ref.get())

localRepository.fetch(objc.id)
localRepository.fetch(objc.id)

remoteRepository.find(ref.get())

objc.id = "23"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import tech.antibytes.kmock.example.contract.SampleLocalRepositoryMock
import tech.antibytes.kmock.example.contract.SampleRemoteRepositoryMock
import tech.antibytes.kmock.verification.NonfreezingVerifier
import tech.antibytes.kmock.verification.Verifier
import tech.antibytes.kmock.verification.hasBeenCalled
import tech.antibytes.kmock.verification.hasBeenCalledWith
import tech.antibytes.kmock.verification.hasBeenCalledWithout
import tech.antibytes.kmock.verification.hasBeenStrictlyCalledWith
Expand Down Expand Up @@ -150,14 +151,17 @@ class SampleControllerAutoSpyFactorySpec {
delay(20)

verify(exactly = 1) { local._contains.hasBeenStrictlyCalledWith(idOrg) }
verify(exactly = 1) { local._fetch.hasBeenCalledWith() }
verify(exactly = 1) { remote._find.hasBeenStrictlyCalledWith(idOrg) }
verify(exactly = 2) { local._fetch.hasBeenCalledWith() }
verify(exactly = 2) { remote._find.hasBeenStrictlyCalledWith(idOrg) }

verifier.verifyStrictOrder {
local._contains.hasBeenStrictlyCalledWith(idOrg)
remote._find.hasBeenStrictlyCalledWith(idOrg)
domainObject._id.wasGotten()
local._fetch.hasBeenCalledWith()
local._fetch.hasBeenCalled()
domainObject._id.wasGotten()
local._fetch.hasBeenCalled()
remote._find.hasBeenStrictlyCalledWith(idOrg)
domainObject._id.wasSet()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,24 @@ class SampleControllerAutoStubFactorySpec {

// Then
verify(exactly = 1) { local._contains.hasBeenStrictlyCalledWith(idOrg) }
verify(exactly = 1) { local._fetch.hasBeenStrictlyCalledWith(id) }
verify(exactly = 1) { remote._find.hasBeenStrictlyCalledWith(idOrg) }
verify(exactly = 2) { local._fetch.hasBeenStrictlyCalledWith(id) }
verify(exactly = 2) { remote._find.hasBeenStrictlyCalledWith(idOrg) }

verifier.verifyStrictOrder {
local._contains.hasBeenStrictlyCalledWith(idOrg)
remote._find.hasBeenStrictlyCalledWith(idOrg)
domainObject._id.wasGotten()
local._fetch.hasBeenStrictlyCalledWith(id)
domainObject._id.wasGotten()
local._fetch.hasBeenStrictlyCalledWith(id)
remote._find.hasBeenStrictlyCalledWith(idOrg)
domainObject._id.wasSet()
}

verifier.verifyOrder {
local._contains.hasBeenCalledWithout("abc")
remote._find.hasBeenStrictlyCalledWith(idOrg)
remote._find.hasBeenStrictlyCalledWith(idOrg)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class SampleControllerAutoStubRelaxedSpec {
val idOrg = fixture.fixture<String>()
val id = fixture.fixture<String>()

// domainObject._id.get = id
domainObject._id.get = id

remote._find.returnValue = domainObject
local._contains.sideEffect = { true }
Expand All @@ -158,19 +158,24 @@ class SampleControllerAutoStubRelaxedSpec {
delay(20)

verify(exactly = 1) { local._contains.hasBeenStrictlyCalledWith(idOrg) }
verify(exactly = 1) { local._fetch.hasBeenCalled() }
verify(exactly = 1) { remote._find.hasBeenStrictlyCalledWith(idOrg) }
verify(exactly = 2) { local._fetch.hasBeenStrictlyCalledWith(id) }
verify(exactly = 2) { remote._find.hasBeenStrictlyCalledWith(idOrg) }

verifier.verifyStrictOrder {
local._contains.hasBeenStrictlyCalledWith(idOrg)
remote._find.hasBeenStrictlyCalledWith(idOrg)
domainObject._id.wasGotten()
local._fetch.hasBeenCalled()
local._fetch.hasBeenStrictlyCalledWith(id)
domainObject._id.wasGotten()
local._fetch.hasBeenStrictlyCalledWith(id)
remote._find.hasBeenStrictlyCalledWith(idOrg)
domainObject._id.wasSet()
}

verifier.verifyOrder {
local._contains.hasBeenCalledWithout("abc")
remote._find.hasBeenStrictlyCalledWith(idOrg)
remote._find.hasBeenStrictlyCalledWith(idOrg)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,24 @@ class SampleControllerAutoStubSpec {
delay(20)

verify(exactly = 1) { local._contains.hasBeenStrictlyCalledWith(idOrg) }
verify(exactly = 1) { local._fetch.hasBeenStrictlyCalledWith(id) }
verify(exactly = 1) { remote._find.hasBeenStrictlyCalledWith(idOrg) }
verify(exactly = 2) { local._fetch.hasBeenStrictlyCalledWith(id) }
verify(exactly = 2) { remote._find.hasBeenStrictlyCalledWith(idOrg) }

verifier.verifyStrictOrder {
local._contains.hasBeenStrictlyCalledWith(idOrg)
remote._find.hasBeenStrictlyCalledWith(idOrg)
domainObject._id.wasGotten()
local._fetch.hasBeenStrictlyCalledWith(id)
domainObject._id.wasGotten()
local._fetch.hasBeenStrictlyCalledWith(id)
remote._find.hasBeenStrictlyCalledWith(idOrg)
domainObject._id.wasSet()
}

verifier.verifyOrder {
local._contains.hasBeenCalledWithout("abc")
remote._find.hasBeenStrictlyCalledWith(idOrg)
remote._find.hasBeenStrictlyCalledWith(idOrg)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,17 @@ class SampleControllerSpec {
delay(20)

local.contains.assertHasBeenCalledStrictlyWith(1, idOrg)
local.fetch.assertHasBeenCalledStrictlyWith(1, id)
remote.find.assertHasBeenCalledStrictlyWith(1, idOrg)
local.fetch.assertHasBeenCalledStrictlyWith(2, id)
remote.find.assertHasBeenCalledStrictlyWith(2, idOrg)

verifier.verifyStrictOrder {
local.contains.hasBeenStrictlyCalledWith(idOrg)
remote.find.hasBeenStrictlyCalledWith(idOrg)
domainObject.propId.wasGotten()
local.fetch.hasBeenStrictlyCalledWith(id)
domainObject.propId.wasGotten()
local.fetch.hasBeenStrictlyCalledWith(id)
remote.find.hasBeenStrictlyCalledWith(idOrg)
domainObject.propId.wasSet()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,24 @@ class SampleControllerAutoStubFactoryJsSpec {
delay(20)

verify(exactly = 1) { local._contains.hasBeenStrictlyCalledWith(idOrg) }
verify(exactly = 1) { local._fetch.hasBeenStrictlyCalledWith(id) }
verify(exactly = 1) { remote._find.hasBeenStrictlyCalledWith(idOrg) }
verify(exactly = 2) { local._fetch.hasBeenStrictlyCalledWith(id) }
verify(exactly = 2) { remote._find.hasBeenStrictlyCalledWith(idOrg) }

verifier.verifyStrictOrder {
local._contains.hasBeenStrictlyCalledWith(idOrg)
remote._find.hasBeenStrictlyCalledWith(idOrg)
domainObject._id.wasGotten()
local._fetch.hasBeenStrictlyCalledWith(id)
domainObject._id.wasGotten()
local._fetch.hasBeenStrictlyCalledWith(id)
remote._find.hasBeenStrictlyCalledWith(idOrg)
domainObject._id.wasSet()
}

verifier.verifyOrder {
local._contains.hasBeenCalledWithout("abc")
remote._find.hasBeenStrictlyCalledWith(idOrg)
remote._find.hasBeenStrictlyCalledWith(idOrg)
}
}
}
Expand Down
38 changes: 15 additions & 23 deletions kmock/src/commonMain/kotlin/tech/antibytes/kmock/KMockContract.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object KMockContract {
* Reference to its correspondent VerificationChain. This Property is intended for internal use only!
* @suppress
*/
var verificationBuilderReference: VerificationChainBuilder?
var verificationChain: VerificationChain?

/**
* Resolves given arguments of an invocation.
Expand Down Expand Up @@ -690,7 +690,7 @@ object KMockContract {
* Meant for internal usage only!
* @author Matthias Geisler
*/
interface VerificationHandle {
interface Expectation {
/**
* Reference of the Proxy.
*/
Expand Down Expand Up @@ -750,28 +750,24 @@ object KMockContract {
}

/**
* Builder for a VerificationChain.
* Meant for internal usage only!
* VerificationChain in order to verify over multiple Handles.
* Meant for internal purpose only!
* @author Matthias Geisler
*/
interface VerificationChainBuilder {
interface VerificationChain {
/**
* Adds a VerificationHandle to the Chain.
* Meant for internal usage only!
* @param handle a VerificationHandle which will be used for verification
* Propagates the expected invocation to the Chain and asserts it against the actual values.
* @param expected the expected Invocation.
* @throws AssertionError if the expected value does not match the actual value.
*/
fun add(handle: VerificationHandle)
@Throws(AssertionError::class)
fun propagate(expected: Expectation)

/**
* Transforms the chain into a list.
* Meant for internal usage only!
* @return a List of VerificationHandle.
* 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.
*/
fun toList(): List<VerificationHandle>
}

interface VerificationChain {
fun propagate(expected: VerificationHandle)
@Throws(AssertionError::class)
fun ensureAllReferencesAreEvaluated()
}

Expand Down Expand Up @@ -803,10 +799,6 @@ object KMockContract {
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."
internal const val NOTHING_TO_STRICTLY_VERIFY = "The given verification chain (has %0 items) does not match the captured calls (%1 were captured)."
internal const val NOTHING_TO_VERIFY = "The given verification chain (has %0 items) is exceeding the captured calls (%1 were captured)."
internal const val NO_MATCHING_CALL_IDX = "The captured calls of %0 exceeds the captured calls."
internal const val MISMATCHING_FUNCTION = "Excepted '%0', but got '%1'."
internal const val MISMATCHING_CALL_IDX = "Excepted the %0 call of %1, but the %2 was referenced."
internal const val CALL_NOT_FOUND = "Last referred invocation of %0 was not found."

internal const val NOT_PART_OF_CHAIN = "The given proxy %0 is not part of this VerificationChain."
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import tech.antibytes.kmock.KMockContract.Collector
import tech.antibytes.kmock.KMockContract.ParameterizedRelaxer
import tech.antibytes.kmock.KMockContract.Relaxer
import tech.antibytes.kmock.KMockContract.SideEffectChainBuilder
import tech.antibytes.kmock.KMockContract.VerificationChain
import tech.antibytes.kmock.error.MockError
import kotlin.math.max

Expand All @@ -26,7 +27,7 @@ import kotlin.math.max
abstract class FunProxy<ReturnValue, SideEffect : Function<ReturnValue>>(
override val id: String,
override val ignorableForVerification: Boolean,
collector: Collector = Collector { _, _ -> Unit },
collector: Collector = NoopCollector,
relaxer: Relaxer<ReturnValue>?,
unitFunRelaxer: Relaxer<ReturnValue?>?,
buildInRelaxer: ParameterizedRelaxer<Any?, ReturnValue>?,
Expand Down Expand Up @@ -65,10 +66,9 @@ abstract class FunProxy<ReturnValue, SideEffect : Function<ReturnValue>>(

private val buildInRelaxer: AtomicRef<ParameterizedRelaxer<Any?, ReturnValue>?> = atomic(buildInRelaxer)

private val _verificationBuilder: AtomicRef<KMockContract.VerificationChainBuilder?> = atomic(null)
private val _verificationBuilderFreezing: KMockContract.VerificationChainBuilder? = null
private val _verificationChain: AtomicRef<VerificationChain?> = atomic(null)

override var verificationBuilderReference: KMockContract.VerificationChainBuilder? by _verificationBuilder
override var verificationChain: VerificationChain? by _verificationChain

protected enum class Provider(val value: Int) {
NO_PROVIDER(0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import tech.antibytes.kmock.KMockContract
import tech.antibytes.kmock.KMockContract.Collector
import tech.antibytes.kmock.KMockContract.GetOrSet
import tech.antibytes.kmock.KMockContract.Relaxer
import tech.antibytes.kmock.KMockContract.VerificationChain
import tech.antibytes.kmock.error.MockError
import kotlin.math.max

Expand Down Expand Up @@ -66,8 +67,8 @@ class PropertyProxy<Value>(
private val arguments: IsoMutableList<GetOrSet> = sharedMutableListOf()
private val relaxer: AtomicRef<Relaxer<Value>?> = atomic(relaxer)

private val _verificationBuilder: AtomicRef<KMockContract.VerificationChainBuilder?> = atomic(null)
override var verificationBuilderReference: KMockContract.VerificationChainBuilder? by _verificationBuilder
private val _verificationChain: AtomicRef<VerificationChain?> = atomic(null)
override var verificationChain: VerificationChain? by _verificationChain

private enum class Provider(val value: Int) {
NO_PROVIDER(0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,3 @@ internal fun String.format(vararg args: Any?): String {
formatParts(parts, args)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import tech.antibytes.kmock.KMockContract.Proxy
* Meant for internal usage only!
* @author Matthias Geisler
*/
data class VerificationHandle(
data class Expectation(
override val proxy: Proxy<*, *>,
override val callIndices: List<Int>
) : KMockContract.VerificationHandle
) : KMockContract.Expectation
Loading

0 comments on commit ca7e519

Please sign in to comment.