diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 3e794861..ff6c739d 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -61,6 +61,7 @@ toc::[] * `allowedRecursiveTypes`, since it is no longer needed due to the new spy invocation * `allowInterfacesOnKmock`, use allowInterfaces instead * `allowInterfacesOnKspy`, use allowInterfaces instead +* old experimental ProxyAssertion family, use `assertProxy` or `verify` instead === Fixed diff --git a/kmock/src/commonMain/kotlin/tech/antibytes/kmock/Annotation.kt b/kmock/src/commonMain/kotlin/tech/antibytes/kmock/Annotation.kt index 8ba6ee79..3069e0d0 100644 --- a/kmock/src/commonMain/kotlin/tech/antibytes/kmock/Annotation.kt +++ b/kmock/src/commonMain/kotlin/tech/antibytes/kmock/Annotation.kt @@ -72,7 +72,7 @@ annotation class Relaxer @RequiresOptIn( level = RequiresOptIn.Level.WARNING, - message = "This API is experimental. It may be removed or changed in future releases." + message = "This API is experimental. It may be removed or changed in future releases." ) @Target( AnnotationTarget.CLASS, diff --git a/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/ProxyAssertion.kt b/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/ProxyAssertion.kt deleted file mode 100644 index d94849fe..00000000 --- a/kmock/src/commonMain/kotlin/tech/antibytes/kmock/verification/ProxyAssertion.kt +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2022 Matthias Geisler (bitPogo) / All rights reserved. - * - * Use of this source code is governed by Apache v2.0 - */ - -package tech.antibytes.kmock.verification - -import tech.antibytes.kmock.KMockContract -import tech.antibytes.kmock.KMockContract.ArgumentConstraint -import tech.antibytes.kmock.KMockContract.FunProxy -import tech.antibytes.kmock.KMockExperimental - -/** - * Asserts that invocations of a FunProxy happened. - * @param exactly how often the Proxy was invoked. - * @throws AssertionError if the amount of calls does not match the expected amount. - * @see FunProxy - * @see verify - * @author Matthias Geisler - */ -@KMockExperimental -fun FunProxy<*, *>.assertHasBeenCalled( - exactly: Int, -) { - val proxy = this - verify(exactly = exactly) { - proxy.hasBeenCalledWith() - } -} - -/** - * Asserts that invocations of a FunProxy happened which has no Arguments. - * @param exactly how often the Proxy was invoked. - * @throws AssertionError if the amount of calls does not match the expected amount. - * @see FunProxy - * @see verify - * @author Matthias Geisler - */ -@KMockExperimental -fun FunProxy<*, *>.assertHasBeenCalledWithVoid( - exactly: Int, -) { - val proxy = this - verify(exactly = exactly) { - proxy.hasBeenCalledWithVoid() - } -} - -/** - * Asserts that invocations of a FunProxy with the given arguments happened. - * @param exactly how often the Proxy was invoked. - * @param arguments or constraints which follow the order of the mocked/stubbed function but can contain gaps and do not need to all arguments/constraints. - * @throws AssertionError if the amount of calls does not match the expected amount. - * @see FunProxy - * @see verify - * @see ArgumentConstraint - * @author Matthias Geisler - */ -@KMockExperimental -fun FunProxy<*, *>.assertHasBeenCalledWith( - exactly: Int, - vararg arguments: Any? -) { - val proxy = this - verify(exactly = exactly) { - proxy.hasBeenCalledWith(*arguments) - } -} - -/** - * Asserts that invocations of a FunProxy with the given arguments happened. - * @param exactly how often the Proxy was invoked. - * @param arguments or constraints which follow the order of the mocked/stubbed function and need to contain all arguments/constraints. - * @throws AssertionError if the amount of calls does not match the expected amount. - * @see FunProxy - * @see verify - * @see ArgumentConstraint - * @author Matthias Geisler - */ -@KMockExperimental -fun FunProxy<*, *>.assertHasBeenCalledStrictlyWith( - exactly: Int, - vararg arguments: Any? -) { - val proxy = this - verify(exactly = exactly) { - proxy.hasBeenStrictlyCalledWith(*arguments) - } -} - -/** - * Asserts that invocations of a FunProxy did not happened. - * @throws AssertionError if the amount of calls does not match the expected amount. - * @see FunProxy - * @see verify - * @author Matthias Geisler - */ -@KMockExperimental -fun FunProxy<*, *>.assertHasNotBeenCalled() { - val proxy = this - verify(exactly = 0) { - proxy.hasBeenCalledWith() - } -} - -/** - * Asserts that invocations of a FunProxy happened without given parameter. - * @param illegal unordered arguments/constraints. - * @throws AssertionError if at least one call contains a given argument. - * @see FunProxy - * @see verify - * @see ArgumentConstraint - * @author Matthias Geisler - */ -@KMockExperimental -fun FunProxy<*, *>.assertHasBeenCalledWithout( - vararg illegal: Any? -) { - val proxy = this - verify(atMost = Int.MAX_VALUE) { - proxy.hasBeenCalledWithout(*illegal) - } -} - -/** - * Asserts that the getter of a PropertyProxy was invoked. - * @param exactly how often the Proxy was invoked. - * @throws AssertionError if at least one call contains a given argument. - * @see FunProxy - * @see verify - * @author Matthias Geisler - */ -@KMockExperimental -fun KMockContract.PropertyProxy<*>.assertWasGotten(exactly: Int) { - val proxy = this - verify(exactly = exactly) { proxy.wasGotten() } -} - -/** - * Asserts that the setter of a PropertyProxy was invoked. - * @param exactly how often the Proxy was invoked. - * @throws AssertionError if at least one call contains a given argument. - * @see FunProxy - * @see verify - * @author Matthias Geisler - */ -@KMockExperimental -fun KMockContract.PropertyProxy<*>.assertWasSet(exactly: Int) { - val proxy = this - verify(exactly = exactly) { proxy.wasSet() } -} - -/** - * Asserts that the setter of a PropertyProxy was invoked with the given value. - * @param exactly how often the Proxy was invoked. - * @param value or constraint of the expected value. - * @throws AssertionError if at least one call contains a given argument. - * @see FunProxy - * @see verify - * @see ArgumentConstraint - * @author Matthias Geisler - */ -@KMockExperimental -fun KMockContract.PropertyProxy<*>.assertWasSetTo(exactly: Int, value: Any?) { - val proxy = this - verify(exactly = exactly) { proxy.wasSetTo(value) } -} diff --git a/kmock/src/commonTest/kotlin/tech/antibytes/kmock/verification/ProxyAssertionSpec.kt b/kmock/src/commonTest/kotlin/tech/antibytes/kmock/verification/ProxyAssertionSpec.kt deleted file mode 100644 index 0b4c632e..00000000 --- a/kmock/src/commonTest/kotlin/tech/antibytes/kmock/verification/ProxyAssertionSpec.kt +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright (c) 2022 Matthias Geisler (bitPogo) / All rights reserved. - * - * Use of this source code is governed by Apache v2.0 - */ - -package tech.antibytes.kmock.verification - -import tech.antibytes.kmock.KMockContract -import tech.antibytes.kmock.KMockExperimental -import tech.antibytes.mock.PropertyProxyStub -import tech.antibytes.mock.SyncFunProxyStub -import tech.antibytes.util.test.fixture.fixture -import tech.antibytes.util.test.fixture.kotlinFixture -import tech.antibytes.util.test.fixture.listFixture -import kotlin.js.JsName -import kotlin.test.Test -import kotlin.test.assertFailsWith - -class ProxyAssertionSpec { - private val fixture = kotlinFixture() - - @OptIn(KMockExperimental::class) - @Test - @JsName("fn0") - fun `Given assertHasBeenCalled fails if the amount of calls does not match the criteria`() { - // Given - val values = fixture.listFixture(size = 2).toTypedArray() - val proxy = SyncFunProxyStub(fixture.fixture(), 5) - - proxy.getArgumentsForCall = { values } - - // Then - assertFailsWith { - // When - proxy.assertHasBeenCalled(exactly = 1) - } - } - - @OptIn(KMockExperimental::class) - @Test - @JsName("fn1") - fun `Given assertHasBeenCalled accepts if the amount of calls match the criteria`() { - // Given - val values = fixture.listFixture(size = 2).toTypedArray() - val proxy = SyncFunProxyStub(fixture.fixture(), 1) - - proxy.getArgumentsForCall = { values } - - // When - proxy.assertHasBeenCalled(exactly = 1) - } - - @OptIn(KMockExperimental::class) - @Test - @JsName("fn2") - fun `Given assertHasBeenCalledWithVoid fails if the amount of calls does not match the criteria`() { - // Given - val values = arrayOf() - val proxy = SyncFunProxyStub(fixture.fixture(), 5) - - proxy.getArgumentsForCall = { values } - - // Then - assertFailsWith { - // When - proxy.assertHasBeenCalledWithVoid(exactly = 1) - } - } - - @OptIn(KMockExperimental::class) - @Test - @JsName("fn3") - fun `Given assertHasBeenCalledWith accepts if the amount of calls match the criteria`() { - // Given - val values = arrayOf() - val proxy = SyncFunProxyStub(fixture.fixture(), 1) - - proxy.getArgumentsForCall = { values } - - // When - proxy.assertHasBeenCalledWithVoid(exactly = 1) - } - - @OptIn(KMockExperimental::class) - @Test - @JsName("fn4") - fun `Given assertHasBeenCalledWith fails if the amount of calls does not match the criteria`() { - // Given - val values = fixture.listFixture(size = 2).toTypedArray() - val proxy = SyncFunProxyStub(fixture.fixture(), 1) - - proxy.getArgumentsForCall = { values } - - // Then - assertFailsWith { - // When - proxy.assertHasBeenCalledWith( - exactly = 1, - arguments = fixture.listFixture().toTypedArray() - ) - } - } - - @OptIn(KMockExperimental::class) - @Test - @JsName("fn5") - fun `Given assertHasBeenCalledWith accepts if the amount of calls does match the criteria`() { - // Given - val values = fixture.listFixture(size = 2).toTypedArray() - val proxy = SyncFunProxyStub(fixture.fixture(), 1) - - proxy.getArgumentsForCall = { values } - // When - proxy.assertHasBeenCalledWith( - exactly = 1, - values[0] - ) - } - - @OptIn(KMockExperimental::class) - @Test - @JsName("fn6") - fun `Given assertHasBeenCalledStrictlyWith fails if the amount of calls does not match the criteria`() { - // Given - val values = fixture.listFixture(size = 2).toTypedArray() - val proxy = SyncFunProxyStub(fixture.fixture(), 1) - - proxy.getArgumentsForCall = { values } - - // Then - assertFailsWith { - // When - proxy.assertHasBeenCalledStrictlyWith( - exactly = 1, - values[0] - ) - } - } - - @OptIn(KMockExperimental::class) - @Test - @JsName("fn7") - fun `Given assertHasBeenCalledStrictlyWith accepts if the amount of calls does match the criteria`() { - // Given - val values = fixture.listFixture(size = 2).toTypedArray() - val proxy = SyncFunProxyStub(fixture.fixture(), 1) - - proxy.getArgumentsForCall = { values } - - // When - proxy.assertHasBeenCalledStrictlyWith( - exactly = 1, - arguments = values - ) - } - - @OptIn(KMockExperimental::class) - @Test - @JsName("fn8") - fun `Given assertHadNotBeenCalled fails if the amount of calls does not match the criteria`() { - // Given - val values = fixture.listFixture(size = 2).toTypedArray() - val proxy = SyncFunProxyStub(fixture.fixture(), 1) - - proxy.getArgumentsForCall = { values } - - // Then - assertFailsWith { - // When - proxy.assertHasNotBeenCalled() - } - } - - @OptIn(KMockExperimental::class) - @Test - @JsName("fn9") - fun `Given assertHadNotBeenCalled accepts if the amount of calls does match the criteria`() { - // Given - val values = fixture.listFixture(size = 2).toTypedArray() - val proxy = SyncFunProxyStub(fixture.fixture(), 0) - - proxy.getArgumentsForCall = { values } - - // When - proxy.assertHasNotBeenCalled() - } - - @OptIn(KMockExperimental::class) - @Test - @JsName("fn10") - fun `Given assertHasBeenCalledWithout fails if the amount of calls does not match the criteria`() { - // Given - val values = fixture.listFixture(size = 2).toTypedArray() - val proxy = SyncFunProxyStub(fixture.fixture(), 2) - - proxy.getArgumentsForCall = { values } - - // Then - assertFailsWith { - // When - proxy.assertHasBeenCalledWithout(values[0]) - } - } - - @OptIn(KMockExperimental::class) - @Test - @JsName("fn11") - fun `Given assertHasBeenCalledWithout accepts if the amount of calls does match the criteria`() { - // Given - val values = fixture.listFixture(size = 2).toTypedArray() - val proxy = SyncFunProxyStub(fixture.fixture(), 2) - - proxy.getArgumentsForCall = { values } - - // When - proxy.assertHasBeenCalledWithout(fixture.fixture()) - } - - @OptIn(KMockExperimental::class) - @Test - @JsName("fn12") - fun `Given assertWasGotten fails if the amount of calls does not match the criteria`() { - // Given - val proxy = PropertyProxyStub(fixture.fixture(), 2) - - proxy.getArgumentsForCall = { KMockContract.GetOrSet.Get } - - // Then - assertFailsWith { - // When - proxy.assertWasGotten(1) - } - } - - @OptIn(KMockExperimental::class) - @Test - @JsName("fn13") - fun `Given assertWasGotten accepts if the amount of calls does match the criteria`() { - // Given - val proxy = PropertyProxyStub(fixture.fixture(), 1) - - proxy.getArgumentsForCall = { KMockContract.GetOrSet.Get } - - // When - proxy.assertWasGotten(1) - } - - @OptIn(KMockExperimental::class) - @Test - @JsName("fn14") - fun `Given assertWasSet fails if the amount of calls does not match the criteria`() { - // Given - val proxy = PropertyProxyStub(fixture.fixture(), 2) - - proxy.getArgumentsForCall = { KMockContract.GetOrSet.Set(null) } - - // Then - assertFailsWith { - // When - proxy.assertWasSet(1) - } - } - - @OptIn(KMockExperimental::class) - @Test - @JsName("fn15") - fun `Given assertWasSet accepts if the amount of calls does match the criteria`() { - // Given - val proxy = PropertyProxyStub(fixture.fixture(), 1) - - proxy.getArgumentsForCall = { KMockContract.GetOrSet.Set(null) } - - // When - proxy.assertWasSet(1) - } - - @OptIn(KMockExperimental::class) - @Test - @JsName("fn16") - fun `Given assertWasSetTo fails if the amount of calls does not match the criteria`() { - // Given - val proxy = PropertyProxyStub(fixture.fixture(), 2) - - proxy.getArgumentsForCall = { KMockContract.GetOrSet.Set(fixture.fixture()) } - - // Then - assertFailsWith { - // When - proxy.assertWasSetTo(1, fixture.fixture()) - } - } - - @OptIn(KMockExperimental::class) - @Test - @JsName("fn17") - fun `Given assertWasSetTo accepts if the amount of calls does match the criteria`() { - // Given - val value: Any = fixture.fixture() - val proxy = PropertyProxyStub(fixture.fixture(), 1) - - proxy.getArgumentsForCall = { KMockContract.GetOrSet.Set(value) } - - // When - proxy.assertWasSetTo(1, value) - } -}