From 10341942ba3d78764e3348d8bd62b809d69e7d00 Mon Sep 17 00:00:00 2001 From: Eva Tatarka Date: Tue, 5 Dec 2023 12:41:20 -0800 Subject: [PATCH] reformat tests --- .../assertk/coroutines/assertions/AnyTest.kt | 9 +- .../assertk/coroutines/assertions/FlowTest.kt | 93 ++++--- .../kotlin/test/assertk/AssertAllTest.kt | 73 ++++-- .../kotlin/test/assertk/AssertFailureTest.kt | 9 +- .../kotlin/test/assertk/AssertLambdaTest.kt | 18 +- .../kotlin/test/assertk/AssertTest.kt | 21 +- .../kotlin/test/assertk/FailureTest.kt | 12 +- .../kotlin/test/assertk/NameTest.kt | 14 +- .../kotlin/test/assertk/TableTest.kt | 18 +- .../kotlin/test/assertk/assertions/AnyTest.kt | 230 ++++++++++++------ .../test/assertk/assertions/ArrayTest.kt | 141 +++++++---- .../test/assertk/assertions/BooleanTest.kt | 12 +- .../assertk/assertions/CharSequenceTest.kt | 135 ++++++---- .../test/assertk/assertions/CollectionTest.kt | 33 ++- .../test/assertk/assertions/ComparableTest.kt | 73 ++++-- .../test/assertk/assertions/IterableTest.kt | 192 ++++++++++----- .../test/assertk/assertions/ListTest.kt | 103 +++++--- .../kotlin/test/assertk/assertions/MapTest.kt | 108 +++++--- .../test/assertk/assertions/NumberTest.kt | 33 ++- .../test/assertk/assertions/PredicateTest.kt | 6 +- .../test/assertk/assertions/ResultTest.kt | 27 +- .../test/assertk/assertions/SequenceTest.kt | 204 ++++++++++------ .../test/assertk/assertions/ThrowableTest.kt | 48 ++-- .../assertions/support/ListDifferTest.kt | 21 +- .../assertk/assertions/support/SupportTest.kt | 102 +++++--- .../assertions/support/JsSupportTest.kt | 3 +- .../kotlin/test/assertk/JVMAssertAllTest.kt | 15 +- .../test/assertk/assertions/FileTest.kt | 94 ++++--- .../assertk/assertions/InputStreamTest.kt | 33 ++- .../test/assertk/assertions/JVMResultTest.kt | 3 +- .../test/assertk/assertions/JavaAnyTest.kt | 74 ++++-- .../assertions/JavaNullableStringTest.kt | 12 +- .../test/assertk/assertions/OptionalTest.kt | 18 +- .../test/assertk/assertions/PathTest.kt | 66 +++-- .../assertions/support/JavaSupportTest.kt | 15 +- .../test/assertk/NativeAssertAllTest.kt | 16 +- .../assertions/support/NativeSupportTest.kt | 3 +- .../assertions/FloatArrayContainsTest.kt | 108 +++++--- .../assertions/PrimativeArrayContainsTest.kt | 102 +++++--- .../assertk/assertions/PrimativeArrayTest.kt | 57 +++-- .../assertions/support/WasmJsSupportTest.kt | 3 +- 41 files changed, 1590 insertions(+), 767 deletions(-) diff --git a/assertk-coroutines/src/commonTest/kotlin/test/assertk/coroutines/assertions/AnyTest.kt b/assertk-coroutines/src/commonTest/kotlin/test/assertk/coroutines/assertions/AnyTest.kt index b04b4dd5..065d95b1 100644 --- a/assertk-coroutines/src/commonTest/kotlin/test/assertk/coroutines/assertions/AnyTest.kt +++ b/assertk-coroutines/src/commonTest/kotlin/test/assertk/coroutines/assertions/AnyTest.kt @@ -13,18 +13,21 @@ import kotlinx.coroutines.test.runTest class AnyTest { val subject = BasicObject("test") - @Test fun suspendCall_passes() = runTest { + @Test + fun suspendCall_passes() = runTest { assertThat(subject).suspendCall("str") { it.str() }.isEqualTo("test") } - @Test fun suspendCall_includes_name_in_failure_message() = runTest { + @Test + fun suspendCall_includes_name_in_failure_message() = runTest { val error = assertFailsWith { assertThat(subject).suspendCall("str") { it.str() }.isEmpty() } assertEquals("expected [str] to be empty but was:<\"test\"> (test)", error.message) } - @Test fun nested_suspendCall_include_names_in_failure_message() = runTest { + @Test + fun nested_suspendCall_include_names_in_failure_message() = runTest { val error = assertFailsWith { assertThat(subject).suspendCall("other") { it.other() }.suspendCall("str") { it?.str() }.isNotNull() } diff --git a/assertk-coroutines/src/commonTest/kotlin/test/assertk/coroutines/assertions/FlowTest.kt b/assertk-coroutines/src/commonTest/kotlin/test/assertk/coroutines/assertions/FlowTest.kt index 9f8983e3..063ae8d9 100644 --- a/assertk-coroutines/src/commonTest/kotlin/test/assertk/coroutines/assertions/FlowTest.kt +++ b/assertk-coroutines/src/commonTest/kotlin/test/assertk/coroutines/assertions/FlowTest.kt @@ -13,18 +13,21 @@ import kotlinx.coroutines.test.runTest class FlowTest { //region isEmpty - @Test fun isEmpty_empty_passes() = runTest { + @Test + fun isEmpty_empty_passes() = runTest { assertThat(flowOf()).isEmpty() } - @Test fun isEmpty_non_empty_fails() = runTest { + @Test + fun isEmpty_non_empty_fails() = runTest { val error = assertFailsWith { assertThat(flowOf(null)).isEmpty() } assertEquals("expected to be empty but received:", error.message) } - @Test fun isEmpty_non_empty_in_flow_that_doesnt_complete_fails() = runTest { + @Test + fun isEmpty_non_empty_in_flow_that_doesnt_complete_fails() = runTest { val error = assertFailsWith { assertThat(nonCompletingFlowOf(null)).isEmpty() } @@ -33,11 +36,13 @@ class FlowTest { //endregion //region isNotEmpty - @Test fun isNotEmpty_non_empty_passes() = runTest { + @Test + fun isNotEmpty_non_empty_passes() = runTest { assertThat(flowOf(null)).isNotEmpty() } - @Test fun isNotEmpty_empty_fails() = runTest { + @Test + fun isNotEmpty_empty_fails() = runTest { val error = assertFailsWith { assertThat(flowOf()).isNotEmpty() } @@ -46,11 +51,13 @@ class FlowTest { //endregion //region hasCount - @Test fun hasSize_correct_size_passes() = runTest { + @Test + fun hasSize_correct_size_passes() = runTest { assertThat(flowOf()).hasCount(0) } - @Test fun hasSize_wrong_size_fails() = runTest { + @Test + fun hasSize_wrong_size_fails() = runTest { val flow = flowOf() val error = assertFailsWith { assertThat(flow).hasCount(1) @@ -60,15 +67,18 @@ class FlowTest { //endregion //region contains - @Test fun contains_element_present_passes() = runTest { + @Test + fun contains_element_present_passes() = runTest { assertThat(flowOf(1, 2)).contains(2) } - @Test fun contains_element_present_in_flow_that_doesnt_complete_passes() = runTest { + @Test + fun contains_element_present_in_flow_that_doesnt_complete_passes() = runTest { assertThat(nonCompletingFlowOf(1, 2)).contains(2) } - @Test fun contains_element_missing_fails() = runTest { + @Test + fun contains_element_missing_fails() = runTest { val error = assertFailsWith { assertThat(flowOf()).contains(1) } @@ -77,18 +87,21 @@ class FlowTest { //endregion //region doesNotContain - @Test fun doesNotContain_element_missing_passes() = runTest { + @Test + fun doesNotContain_element_missing_passes() = runTest { assertThat(flowOf()).doesNotContain(1) } - @Test fun doesNotContain_element_present_fails() = runTest { + @Test + fun doesNotContain_element_present_fails() = runTest { val error = assertFailsWith { assertThat(flowOf(1, 2)).doesNotContain(2) } assertEquals("expected to not contain:<2> but received:<[1, 2]>", error.message) } - @Test fun doesNotContain_element_present_in_flow_that_doesnt_complete_fails() = runTest { + @Test + fun doesNotContain_element_present_in_flow_that_doesnt_complete_fails() = runTest { val error = assertFailsWith { assertThat(nonCompletingFlowOf(1, 2)).doesNotContain(2) } @@ -97,11 +110,13 @@ class FlowTest { //endregion //region containsNone - @Test fun containsNone_missing_elements_passes() = runTest { + @Test + fun containsNone_missing_elements_passes() = runTest { assertThat(flowOf()).containsNone(1) } - @Test fun containsNone_present_element_fails() = runTest { + @Test + fun containsNone_present_element_fails() = runTest { val error = assertFailsWith { assertThat(flowOf(1, 2)).containsNone(2, 3) } @@ -112,7 +127,8 @@ class FlowTest { ) } - @Test fun containsNone_present_element_in_flow_that_doesnt_complete_fails() = runTest { + @Test + fun containsNone_present_element_in_flow_that_doesnt_complete_fails() = runTest { val error = assertFailsWith { assertThat(nonCompletingFlowOf(1, 2)).containsNone(2, 3) } @@ -125,15 +141,18 @@ class FlowTest { //region //region containsAtLeast - @Test fun containsAtLeast_all_elements_passes() = runTest { + @Test + fun containsAtLeast_all_elements_passes() = runTest { assertThat(flowOf(1, 2)).containsAtLeast(2, 1) } - @Test fun containsAtLeast_all_elements_in_flow_that_doesnt_complete_passes() = runTest { + @Test + fun containsAtLeast_all_elements_in_flow_that_doesnt_complete_passes() = runTest { assertThat(nonCompletingFlowOf(1, 2)).containsAtLeast(2, 1) } - @Test fun containsAtLeast_some_elements_fails() = runTest { + @Test + fun containsAtLeast_some_elements_fails() = runTest { val error = assertFailsWith { assertThat(flowOf(1)).containsAtLeast(1, 2) } @@ -146,11 +165,13 @@ class FlowTest { //endregion //region containsOnly - @Test fun containsOnly_only_elements_passes() = runTest { + @Test + fun containsOnly_only_elements_passes() = runTest { assertThat(flowOf(1, 2)).containsOnly(2, 1) } - @Test fun containsOnly_more_elements_fails() = runTest { + @Test + fun containsOnly_more_elements_fails() = runTest { val error = assertFailsWith { assertThat(flowOf(1, 2, 3)).containsOnly(2, 1) } @@ -161,7 +182,8 @@ class FlowTest { ) } - @Test fun containsOnly_less_elements_fails() = runTest { + @Test + fun containsOnly_less_elements_fails() = runTest { val error = assertFailsWith { assertThat(flowOf(1, 2, 3)).containsOnly(2, 1, 3, 4) } @@ -173,7 +195,8 @@ class FlowTest { ) } - @Test fun containsOnly_different_elements_fails() = runTest { + @Test + fun containsOnly_different_elements_fails() = runTest { val error = assertFailsWith { assertThat(flowOf(1)).containsOnly(2) } @@ -188,11 +211,13 @@ class FlowTest { //endregion //region containsExactly - @Test fun containsExactly_all_elements_in_same_order_passes() = runTest { + @Test + fun containsExactly_all_elements_in_same_order_passes() = runTest { assertThat(flowOf(1, 2)).containsExactly(1, 2) } - @Test fun containsExactly_all_elements_in_different_order_fails() = runTest { + @Test + fun containsExactly_all_elements_in_different_order_fails() = runTest { val error = assertFailsWith { assertThat(flowOf(1, 2)).containsExactly(2, 1) } @@ -204,7 +229,8 @@ class FlowTest { ) } - @Test fun containsExactly_elements_in_different_order_fails2() = runTest { + @Test + fun containsExactly_elements_in_different_order_fails2() = runTest { val error = assertFailsWith { assertThat(flowOf("1", "2", "3")).containsExactly("2", "3", "1") } @@ -216,7 +242,8 @@ class FlowTest { ) } - @Test fun containsExactly_same_indexes_are_together() = runTest { + @Test + fun containsExactly_same_indexes_are_together() = runTest { val error = assertFailsWith { assertThat(flowOf(1, 1)).containsExactly(2, 2) } @@ -230,7 +257,8 @@ class FlowTest { ) } - @Test fun containsExactly_missing_element_fails() = runTest { + @Test + fun containsExactly_missing_element_fails() = runTest { val error = assertFailsWith { assertThat(flowOf(1, 2)).containsExactly(3) } @@ -243,7 +271,8 @@ class FlowTest { ) } - @Test fun containsExactly_extra_element_fails() = runTest { + @Test + fun containsExactly_extra_element_fails() = runTest { val error = assertFailsWith { assertThat(flowOf(1, 2)).containsExactly(1, 2, 3) } @@ -254,7 +283,8 @@ class FlowTest { ) } - @Test fun containsExactly_missing_element_in_middle_fails() = runTest { + @Test + fun containsExactly_missing_element_in_middle_fails() = runTest { val error = assertFailsWith { assertThat(flowOf(1, 3)).containsExactly(1, 2, 3) } @@ -265,7 +295,8 @@ class FlowTest { ) } - @Test fun containsExactly_extra_element_in_middle_fails() = runTest { + @Test + fun containsExactly_extra_element_in_middle_fails() = runTest { val error = assertFailsWith { assertThat(flowOf(1, 2, 3)).containsExactly(1, 3) } diff --git a/assertk/src/commonTest/kotlin/test/assertk/AssertAllTest.kt b/assertk/src/commonTest/kotlin/test/assertk/AssertAllTest.kt index fbe5d1c6..e1ca2395 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/AssertAllTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/AssertAllTest.kt @@ -18,14 +18,16 @@ import kotlin.test.assertTrue class AssertAllTest { //region all - @Test fun all_multiple_successful_passes() { + @Test + fun all_multiple_successful_passes() { assertThat("test").all { startsWith("t") endsWith("t") } } - @Test fun all_one_failure_fails() { + @Test + fun all_one_failure_fails() { val error = assertFailsWith { assertThat("test", name = "test").all { startsWith("t") @@ -38,7 +40,8 @@ class AssertAllTest { ) } - @Test fun all_both_failures_fails_with_both() { + @Test + fun all_both_failures_fails_with_both() { val error = assertFailsWith { assertThat("test", name = "test").all { startsWith("w") @@ -54,7 +57,8 @@ class AssertAllTest { ) } - @Test fun all_prioritizes_exceptions_thrown_in_block_over_soft_assertions() { + @Test + fun all_prioritizes_exceptions_thrown_in_block_over_soft_assertions() { val error = assertFailsWith { assertThat(1).all { isEqualTo(2) @@ -66,14 +70,16 @@ class AssertAllTest { //endregion //region assertAll - @Test fun assertAll_multiple_successful_passes() { + @Test + fun assertAll_multiple_successful_passes() { assertAll { assertThat("test1", name = "test1").isEqualTo("test1") assertThat("test2", name = "test2").isEqualTo("test2") } } - @Test fun assertAll_one_failure_fails() { + @Test + fun assertAll_one_failure_fails() { val error = assertFailsWith { assertAll { assertThat("test1", name = "test1").isEqualTo("wrong1") @@ -86,7 +92,8 @@ class AssertAllTest { ) } - @Test fun assertAll_both_failures_fails_with_both() { + @Test + fun assertAll_both_failures_fails_with_both() { val error = assertFailsWith { assertAll { assertThat("test1", name = "test1").isEqualTo("wrong1") @@ -102,7 +109,8 @@ class AssertAllTest { ) } - @Test fun leaves_soft_assert_scope_properly_on_exception() { + @Test + fun leaves_soft_assert_scope_properly_on_exception() { val error = assertFailsWith { @Suppress("SwallowedException") try { @@ -117,7 +125,8 @@ class AssertAllTest { assertEquals("Fail", error.message) } - @Test fun assertAll_fails_multiple_block_thrownError_assertions() { + @Test + fun assertAll_fails_multiple_block_thrownError_assertions() { val error = assertFailsWith { assertAll { assertThat(runCatching { 1 + 1 }).isFailure() @@ -133,7 +142,8 @@ class AssertAllTest { ) } - @Test fun assertAll_fails_multiple_block_returnedValue_assertions() { + @Test + fun assertAll_fails_multiple_block_returnedValue_assertions() { val error = assertFailsWith { assertAll { assertThat(runCatching { throw Exception("error1") }).isSuccess() @@ -144,11 +154,28 @@ class AssertAllTest { "The following assertions failed (2 failures)", error.message!!.lineSequence().first() ) - assertTrue(error.message!!.contains("\t${opentestPackageName}AssertionFailedError: expected success but was failure:${show(Exception("error1"))}")) - assertTrue(error.message!!.contains("\t${opentestPackageName}AssertionFailedError: expected success but was failure:${show(Exception("error2"))}")) + assertTrue( + error.message!!.contains( + "\t${opentestPackageName}AssertionFailedError: expected success but was failure:${ + show( + Exception("error1") + ) + }" + ) + ) + assertTrue( + error.message!!.contains( + "\t${opentestPackageName}AssertionFailedError: expected success but was failure:${ + show( + Exception("error2") + ) + }" + ) + ) } - @Test fun assertAll_fails_multiple_block_doesNotThrowAnyException_assertions() { + @Test + fun assertAll_fails_multiple_block_doesNotThrowAnyException_assertions() { val error = assertFailsWith { assertAll { assertThat(runCatching { throw Exception("error1") }).isSuccess() @@ -159,8 +186,24 @@ class AssertAllTest { "The following assertions failed (2 failures)".trimMargin(), error.message!!.lineSequence().first() ) - assertTrue(error.message!!.contains("\t${opentestPackageName}AssertionFailedError: expected success but was failure:${show(Exception("error1"))}")) - assertTrue(error.message!!.contains("\t${opentestPackageName}AssertionFailedError: expected success but was failure:${show(Exception("error2"))}")) + assertTrue( + error.message!!.contains( + "\t${opentestPackageName}AssertionFailedError: expected success but was failure:${ + show( + Exception("error1") + ) + }" + ) + ) + assertTrue( + error.message!!.contains( + "\t${opentestPackageName}AssertionFailedError: expected success but was failure:${ + show( + Exception("error2") + ) + }" + ) + ) } @Test diff --git a/assertk/src/commonTest/kotlin/test/assertk/AssertFailureTest.kt b/assertk/src/commonTest/kotlin/test/assertk/AssertFailureTest.kt index 38ab8c07..48882746 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/AssertFailureTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/AssertFailureTest.kt @@ -18,12 +18,14 @@ import kotlin.test.assertTrue class AssertFailureTest { - @Test fun failure_is_success() { + @Test + fun failure_is_success() { val expected = RuntimeException() assertSame(expected, assertFailure { throw expected }.valueOrFail) } - @Test fun failure_originating_subject_not_wrapped_in_result() { + @Test + fun failure_originating_subject_not_wrapped_in_result() { val t = assertFailsWith { assertFailure { throw RuntimeException("foo") } .message() @@ -33,7 +35,8 @@ class AssertFailureTest { assertFalse("Failure(" in t.message!!) } - @Test fun success_is_failure() { + @Test + fun success_is_failure() { val t = assertFailsWith { assertFailure { } } diff --git a/assertk/src/commonTest/kotlin/test/assertk/AssertLambdaTest.kt b/assertk/src/commonTest/kotlin/test/assertk/AssertLambdaTest.kt index 6ce0d26b..d3f32334 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/AssertLambdaTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/AssertLambdaTest.kt @@ -12,25 +12,31 @@ import kotlin.test.assertEquals @Suppress("DEPRECATION_ERROR") class AssertLambdaTest { - @Test fun successful_assert_lambda_returns_success() { + @Test + fun successful_assert_lambda_returns_success() { assertEquals(Result.success(2), assertThat { 1 + 1 }.valueOrFail) } - @Test fun successful_assert_lambda_returning_null_returns_success() { + @Test + fun successful_assert_lambda_returning_null_returns_success() { assertEquals(Result.success(null), assertThat { null }.valueOrFail) } - @Test fun failing_assert_lambda_returns_failure() { + @Test + fun failing_assert_lambda_returns_failure() { val e = Exception("error") assertEquals(Result.failure(e), assertThat { throw e }.valueOrFail) } - @Test fun returnedValue_works_in_coroutine_test() = runTest { + + @Test + fun returnedValue_works_in_coroutine_test() = runTest { assertThat { asyncReturnValue() }.isSuccess().isEqualTo(1) } - @Test fun returnedValue_exception_works_in_coroutine_test() = runTest { + @Test + fun returnedValue_exception_works_in_coroutine_test() = runTest { assertThat { asyncThrows() }.isFailure().hasMessage("test") @@ -43,6 +49,6 @@ class AssertLambdaTest { @Suppress("RedundantSuspendModifier") private suspend fun asyncThrows() { - throw Exception("test") + throw Exception("test") } } \ No newline at end of file diff --git a/assertk/src/commonTest/kotlin/test/assertk/AssertTest.kt b/assertk/src/commonTest/kotlin/test/assertk/AssertTest.kt index 93331cdb..224d37e9 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/AssertTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/AssertTest.kt @@ -8,7 +8,8 @@ import kotlin.test.* class AssertTest { //region transform - @Test fun transform_that_throws_always_fails_assertion() { + @Test + fun transform_that_throws_always_fails_assertion() { val error = assertFailsWith { assertAll { assertThat(0).transform { fail("error") }.isEqualTo(0) @@ -18,7 +19,8 @@ class AssertTest { assertEquals("error", error.message) } - @Test fun transform_does_not_run_after_throws() { + @Test + fun transform_does_not_run_after_throws() { var run = false val error = assertFailsWith { assertAll { @@ -30,7 +32,8 @@ class AssertTest { assertFalse(run) } - @Test fun transform_rethrows_thrown_exception() { + @Test + fun transform_rethrows_thrown_exception() { val error = assertFailsWith { assertAll { assertThat(0).transform { throw MyException("error") }.isEqualTo(0) @@ -42,7 +45,8 @@ class AssertTest { //endregion //region given - @Test fun given_rethrows_thrown_exception() { + @Test + fun given_rethrows_thrown_exception() { val error = assertFailsWith { assertAll { assertThat(0).given { throw MyException("error") } @@ -54,7 +58,8 @@ class AssertTest { //endregion //region assertThat - @Test fun assertThat_inherits_name_of_parent_assertion_by_default() { + @Test + fun assertThat_inherits_name_of_parent_assertion_by_default() { val error = assertFailsWith { assertThat(0, name = "test").assertThat(1).isEqualTo(2) } @@ -62,7 +67,8 @@ class AssertTest { assertEquals("expected [test]:<[2]> but was:<[1]> (0)", error.message) } - @Test fun assertThat_failing_transformed_assert_shows_original_by_displayActual_lambda() { + @Test + fun assertThat_failing_transformed_assert_shows_original_by_displayActual_lambda() { val error = assertFailsWith { assertThat(0, name = "test", displayActual = { "Number:${it}" }) .assertThat(1).isEqualTo(2) @@ -71,7 +77,8 @@ class AssertTest { assertEquals("expected [test]:<[2]> but was:<[1]> (Number:0)", error.message) } - @Test fun assertThat_on_failing_assert_is_ignored() { + @Test + fun assertThat_on_failing_assert_is_ignored() { val error = assertFailsWith { assertAll { assertThat(0, name = "test").transform { fail("error") }.assertThat(1, name = "ignored").isEqualTo(2) diff --git a/assertk/src/commonTest/kotlin/test/assertk/FailureTest.kt b/assertk/src/commonTest/kotlin/test/assertk/FailureTest.kt index 6ba3ef80..5ad3c55b 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/FailureTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/FailureTest.kt @@ -11,7 +11,8 @@ import kotlin.test.* class FailureTest { - @Test fun fail_throws_assertion_failed_error_with_actual_and_expected_present_and_defined() { + @Test + fun fail_throws_assertion_failed_error_with_actual_and_expected_present_and_defined() { val error = assertFailsWith { fail("message", "expected", "actual") } @@ -23,7 +24,8 @@ class FailureTest { assertNull(error.cause) } - @Test fun fail_throws_assertion_failed_error_with_actual_and_expected_not_defined() { + @Test + fun fail_throws_assertion_failed_error_with_actual_and_expected_not_defined() { val error = assertFailsWith { fail("message") } @@ -35,7 +37,8 @@ class FailureTest { assertNull(error.cause) } - @Test fun fail_cause_nonnull() { + @Test + fun fail_cause_nonnull() { val cause = RuntimeException() val error = assertFailsWith { fail("message", cause = cause) @@ -43,7 +46,8 @@ class FailureTest { assertSame(cause, error.cause) } - @Test fun fail_cause_null() { + @Test + fun fail_cause_null() { val error = assertFailsWith { fail("message", cause = null) } diff --git a/assertk/src/commonTest/kotlin/test/assertk/NameTest.kt b/assertk/src/commonTest/kotlin/test/assertk/NameTest.kt index 93509af1..dc361529 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/NameTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/NameTest.kt @@ -7,22 +7,26 @@ import kotlin.test.assertEquals import kotlin.test.assertFailsWith class NameTest { - @Test fun with_no_name_fails_with_default_error_message() { + @Test + fun with_no_name_fails_with_default_error_message() { val error = assertFailsWith { assertThat("yes").isEqualTo("no") } assertEquals("expected:<\"[no]\"> but was:<\"[yes]\">", error.message) } - @Test fun with_name_fails_with_name_prefixing_message() { + @Test + fun with_name_fails_with_name_prefixing_message() { val error = assertFailsWith { assertThat("yes", name = "test").isEqualTo("no") } assertEquals("expected [test]:<\"[no]\"> but was:<\"[yes]\">", error.message) } - @Test fun property_based_assertion_fails_with_getter_name_prefixing_message() { + @Test + fun property_based_assertion_fails_with_getter_name_prefixing_message() { data class Person(val name: String) + val p = Person("Yoda") val error = assertFailsWith { @@ -31,8 +35,10 @@ class NameTest { assertEquals("expected [name]:<\"[Darth]\"> but was:<\"[Yoda]\">", error.message) } - @Test fun property_based_assertion_fails_with_given_name_prefixing_message() { + @Test + fun property_based_assertion_fails_with_given_name_prefixing_message() { data class Person(val name: String) + val p = Person("Yoda") val error = assertFailsWith { diff --git a/assertk/src/commonTest/kotlin/test/assertk/TableTest.kt b/assertk/src/commonTest/kotlin/test/assertk/TableTest.kt index 7d462064..bc62282a 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/TableTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/TableTest.kt @@ -9,7 +9,8 @@ import kotlin.test.assertEquals import kotlin.test.assertFailsWith class TableTest { - @Test fun no_failures_runs_for_each_row_and_passes() { + @Test + fun no_failures_runs_for_each_row_and_passes() { var invokeCount = 0 tableOf("a", "b") .row(1, 1) @@ -22,7 +23,8 @@ class TableTest { assertEquals(2, invokeCount) } - @Test fun single_failure_fails_row() { + @Test + fun single_failure_fails_row() { var invokeCount = 0 val error = assertFailsWith { tableOf("a", "b") @@ -44,7 +46,8 @@ class TableTest { ) } - @Test fun multiple_failures_fails_with_all() { + @Test + fun multiple_failures_fails_with_all() { var invokeCount = 0 val error = assertFailsWith { tableOf("a", "b") @@ -69,7 +72,8 @@ class TableTest { ) } - @Test fun table_with_one_value_fails_row() { + @Test + fun table_with_one_value_fails_row() { var invokeCount = 0 val error = assertFailsWith { tableOf("a") @@ -90,7 +94,8 @@ class TableTest { ) } - @Test fun table_with_three_values_fails_row() { + @Test + fun table_with_three_values_fails_row() { var invokeCount = 0 val error = assertFailsWith { tableOf("a", "b", "c") @@ -111,7 +116,8 @@ class TableTest { ) } - @Test fun table_with_four_values_fails_row() { + @Test + fun table_with_four_values_fails_row() { var invokeCount = 0 val error = assertFailsWith { tableOf("a", "b", "c", "d") diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/AnyTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/AnyTest.kt index 29b650af..4b47762a 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/AnyTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/AnyTest.kt @@ -11,24 +11,29 @@ class AnyTest { val subject = BasicObject("test") val nullableSubject: BasicObject? = BasicObject("test") - @Test fun extracts_kClass() { + @Test + fun extracts_kClass() { assertEquals(BasicObject::class, assertThat(subject as TestObject).kClass().valueOrFail) } - @Test fun extracts_toStringFun() { + @Test + fun extracts_toStringFun() { assertEquals("test", assertThat(subject).toStringFun().valueOrFail) } - @Test fun extracts_hashCodeFun() { + @Test + fun extracts_hashCodeFun() { assertEquals(42, assertThat(subject).hashCodeFun().valueOrFail) } - @Test fun isEqualTo_equal_objects_passes() { + @Test + fun isEqualTo_equal_objects_passes() { val equal = BasicObject("test") assertThat(subject).isEqualTo(equal) } - @Test fun isEqualTo_non_equal_objects_fails() { + @Test + fun isEqualTo_non_equal_objects_fails() { val nonEqual = BasicObject("not test") val error = assertFailsWith { assertThat(subject).isEqualTo(nonEqual) @@ -36,7 +41,8 @@ class AnyTest { assertEquals("expected:<[not ]test> but was:<[]test>", error.message) } - @Test fun isEqualTo_will_compile_comparing_various_types() { + @Test + fun isEqualTo_will_compile_comparing_various_types() { assertThat(1).isEqualTo(1) assertThat(1 as Int?).isEqualTo(1) assertThat(1).isEqualTo(1 as Int?) @@ -49,26 +55,36 @@ class AnyTest { } } - @Test fun isEqualTo_will_report_different_types_with_the_same_display_representation() { + @Test + fun isEqualTo_will_report_different_types_with_the_same_display_representation() { val error = assertFailsWith { assertThat(Actual("test")).isEqualTo(Expected("test")) } - assertEquals("expected: with type:<${Expected::class}> but was type:<${Actual::class}> with the same string representation", error.message) + assertEquals( + "expected: with type:<${Expected::class}> but was type:<${Actual::class}> with the same string representation", + error.message + ) } - @Test fun isEqualTo_will_report_that_same_types_with_the_same_display_representation_do_not_compare_equal() { + @Test + fun isEqualTo_will_report_that_same_types_with_the_same_display_representation_do_not_compare_equal() { val error = assertFailsWith { assertThat(Actual("test")).isEqualTo(Actual("test")) } - assertEquals("expected: with type:<${Actual::class}> did not compare equal to the same type with the same string representation", error.message) + assertEquals( + "expected: with type:<${Actual::class}> did not compare equal to the same type with the same string representation", + error.message + ) } - @Test fun isNotEqualTo_non_equal_objects_passes() { + @Test + fun isNotEqualTo_non_equal_objects_passes() { val nonEqual = BasicObject("not test") assertThat(subject).isNotEqualTo(nonEqual) } - @Test fun isNotEqualTo_equal_objects_fails() { + @Test + fun isNotEqualTo_equal_objects_fails() { val equal = BasicObject("test") val error = assertFailsWith { assertThat(subject).isNotEqualTo(equal) @@ -76,11 +92,13 @@ class AnyTest { assertEquals("expected to not be equal to:", error.message) } - @Test fun isSameInstanceAs_same_objects_passes() { + @Test + fun isSameInstanceAs_same_objects_passes() { assertThat(subject).isSameInstanceAs(subject) } - @Test fun isSameInstanceAs_different_objects_fails() { + @Test + fun isSameInstanceAs_different_objects_fails() { val nonSame = BasicObject("test") val error = assertFails("") { assertThat(subject).isSameInstanceAs(nonSame) @@ -88,24 +106,28 @@ class AnyTest { assertEquals("expected: and: to refer to the same object", error.message) } - @Test fun isNotSameInstanceAs_non_same_objects_passes() { + @Test + fun isNotSameInstanceAs_non_same_objects_passes() { val nonSame = BasicObject("test") assertThat(subject).isNotSameInstanceAs(nonSame) } - @Test fun isNotSameInstanceAs_same_objects_fails() { + @Test + fun isNotSameInstanceAs_same_objects_fails() { val error = assertFailsWith { assertThat(subject).isNotSameInstanceAs(subject) } assertEquals("expected: to not refer to the same object", error.message) } - @Test fun isIn_one_equal_item_passes() { + @Test + fun isIn_one_equal_item_passes() { val isIn = BasicObject("test") assertThat(subject).isIn(isIn) } - @Test fun isIn_one_non_equal_item_fails() { + @Test + fun isIn_one_non_equal_item_fails() { val isOut1 = BasicObject("not test1") val error = assertFailsWith { assertThat(subject).isIn(isOut1) @@ -113,14 +135,16 @@ class AnyTest { assertEquals("expected:<[not test1]> to contain:", error.message) } - @Test fun isIn_one_equal_item_in_may_passes() { + @Test + fun isIn_one_equal_item_in_may_passes() { val isOut1 = BasicObject("not test1") val isIn = BasicObject("test") val isOut2 = BasicObject("not test2") assertThat(subject).isIn(isOut1, isIn, isOut2) } - @Test fun isIn_no_equal_items_in_may_fails() { + @Test + fun isIn_no_equal_items_in_may_fails() { val isOut1 = BasicObject("not test1") val isOut2 = BasicObject("not test2") val error = assertFailsWith { @@ -129,12 +153,14 @@ class AnyTest { assertEquals("expected:<[not test1, not test2]> to contain:", error.message) } - @Test fun isNotIn_one_non_equal_item_passes() { + @Test + fun isNotIn_one_non_equal_item_passes() { val isOut1 = BasicObject("not test1") assertThat(subject).isNotIn(isOut1) } - @Test fun isNotIn_one_equal_item_fails() { + @Test + fun isNotIn_one_equal_item_fails() { val isIn = BasicObject("test") val error = assertFailsWith { assertThat(subject).isNotIn(isIn) @@ -142,13 +168,15 @@ class AnyTest { assertEquals("expected:<[test]> to not contain:", error.message) } - @Test fun isNotIn_no_equal_items_in_many_passes() { + @Test + fun isNotIn_no_equal_items_in_many_passes() { val isOut1 = BasicObject("not test1") val isOut2 = BasicObject("not test2") assertThat(subject).isNotIn(isOut1, isOut2) } - @Test fun isNotIn_one_equal_item_in_many_fails() { + @Test + fun isNotIn_one_equal_item_in_many_fails() { val isOut1 = BasicObject("not test1") val isIn = BasicObject("test") val isOut2 = BasicObject("not test2") @@ -158,22 +186,26 @@ class AnyTest { assertEquals("expected:<[not test1, test, not test2]> to not contain:", error.message) } - @Test fun hasToString_equal_string_passes() { + @Test + fun hasToString_equal_string_passes() { assertThat(subject).hasToString("test") } - @Test fun hasToString_not_equal_string_fails() { + @Test + fun hasToString_not_equal_string_fails() { val error = assertFailsWith { assertThat(subject).hasToString("not test") } assertEquals("expected [toString]:<\"[not ]test\"> but was:<\"[]test\"> (test)", error.message) } - @Test fun hasHashCode_equal_value_passes() { + @Test + fun hasHashCode_equal_value_passes() { assertThat(subject).hasHashCode(42) } - @Test fun hasHashCode_not_equal_value_fails() { + @Test + fun hasHashCode_not_equal_value_fails() { val error = assertFailsWith { assertThat(subject).hasHashCode(1337) } @@ -183,13 +215,15 @@ class AnyTest { private val testObject = BasicObject("test", 99, 3.14) - @Test fun isEqualToWithGivenProperties_regular_equals_fail() { + @Test + fun isEqualToWithGivenProperties_regular_equals_fail() { assertFailsWith { assertThat(subject).isEqualTo(testObject) } } - @Test fun isEqualToWithGivenProperties_extract_prop_passes() { + @Test + fun isEqualToWithGivenProperties_extract_prop_passes() { assertThat(subject).isEqualToWithGivenProperties( testObject, BasicObject::str, @@ -198,7 +232,8 @@ class AnyTest { ) } - @Test fun isEqualToWithGivenProperties_extract_prop_includes_name_in_failure_message() { + @Test + fun isEqualToWithGivenProperties_extract_prop_includes_name_in_failure_message() { val error = assertFailsWith { assertThat(subject).isEqualToWithGivenProperties(testObject, BasicObject::int) } @@ -206,54 +241,63 @@ class AnyTest { } //region prop - @Test fun prop_passes() { + @Test + fun prop_passes() { assertThat(subject).prop("str") { it.str }.isEqualTo("test") } - @Test fun prop_includes_name_in_failure_message() { + @Test + fun prop_includes_name_in_failure_message() { val error = assertFailsWith { assertThat(subject).prop("str") { it.str }.isEmpty() } assertEquals("expected [str] to be empty but was:<\"test\"> (test)", error.message) } - @Test fun nested_prop_include_names_in_failure_message() { + @Test + fun nested_prop_include_names_in_failure_message() { val error = assertFailsWith { assertThat(subject).prop("other") { it.other }.prop("str") { it?.str }.isNotNull() } assertEquals("expected [other.str] to not be null (test)", error.message) } - @Test fun prop_property1_extract_prop_passes() { + @Test + fun prop_property1_extract_prop_passes() { assertThat(subject).prop(BasicObject::str).isEqualTo("test") } - @Test fun prop_property1_extract_prop_includes_name_in_failure_message() { + @Test + fun prop_property1_extract_prop_includes_name_in_failure_message() { val error = assertFailsWith { assertThat(subject).prop(BasicObject::str).isEmpty() } assertEquals("expected [str] to be empty but was:<\"test\"> (test)", error.message) } - @Test fun prop_property1_includes_error_message_when_fails() { + @Test + fun prop_property1_includes_error_message_when_fails() { val error = assertFails { assertThat(subject).prop(BasicObject::failing).isEmpty() } assertEquals("sorry!", error.message) } - @Test fun prop_callable_function_passes() { + @Test + fun prop_callable_function_passes() { assertThat(subject).prop(BasicObject::funcA).isEqualTo("A") } - @Test fun prop_callable_function_includes_name_in_failure_message() { + @Test + fun prop_callable_function_includes_name_in_failure_message() { val error = assertFailsWith { assertThat(subject).prop(BasicObject::funcA).isEqualTo(14) } assertEquals("expected [funcA]:<[14]> but was:<[\"A\"]> (test)", error.message) } - @Test fun nested_prop_callable_function_include_names_in_failure_message() { + @Test + fun nested_prop_callable_function_include_names_in_failure_message() { val error = assertFailsWith { assertThat(subject).prop(BasicObject::funcB).prop(BasicObject::funcA).isNull() } @@ -261,33 +305,39 @@ class AnyTest { } //endregion - @Test fun isNull_null_passes() { + @Test + fun isNull_null_passes() { assertThat(null as String?).isNull() } - @Test fun isNull_non_null_fails() { + @Test + fun isNull_non_null_fails() { val error = assertFailsWith { assertThat(nullableSubject).isNull() } assertEquals("expected to be null but was:", error.message) } - @Test fun isNotNull_non_null_passes() { + @Test + fun isNotNull_non_null_passes() { assertThat(nullableSubject).isNotNull() } - @Test fun isNotNull_null_fails() { + @Test + fun isNotNull_null_fails() { val error = assertFailsWith { assertThat(null as String?).isNotNull() } assertEquals("expected to not be null", error.message) } - @Test fun isNotNull_non_null_and_equal_object_passes() { + @Test + fun isNotNull_non_null_and_equal_object_passes() { assertThat(nullableSubject).isNotNull().isEqualTo(subject) } - @Test fun isNotNull_non_null_and_non_equal_object_fails() { + @Test + fun isNotNull_non_null_and_non_equal_object_fails() { val unequal = BasicObject("not test") val error = assertFailsWith { assertThat(nullableSubject).isNotNull().isEqualTo(unequal) @@ -295,22 +345,26 @@ class AnyTest { assertEquals("expected:<[not ]test> but was:<[]test>", error.message) } - @Test fun isNotNull_null_and_equal_object_fails() { + @Test + fun isNotNull_null_and_equal_object_fails() { val error = assertFailsWith { assertThat(null as String?).isNotNull().isEqualTo(null) } assertEquals("expected to not be null", error.message) } - @Test fun hasClass_same_class_passes() { + @Test + fun hasClass_same_class_passes() { assertThat(subject).hasClass(BasicObject::class) } - @Test fun hasClass_reified_same_class_passes() { + @Test + fun hasClass_reified_same_class_passes() { assertThat(subject).hasClass() } - @Test fun hasClass_parent_class_fails() { + @Test + fun hasClass_parent_class_fails() { val error = assertFailsWith { assertThat(subject).hasClass(TestObject::class) } @@ -320,7 +374,8 @@ class AnyTest { ) } - @Test fun hasClass_reified_parent_class_fails() { + @Test + fun hasClass_reified_parent_class_fails() { val error = assertFailsWith { assertThat(subject).hasClass() } @@ -330,45 +385,54 @@ class AnyTest { ) } - @Test fun doesNotHaveClass_parent_class_passes() { + @Test + fun doesNotHaveClass_parent_class_passes() { assertThat(subject).doesNotHaveClass(TestObject::class) } - @Test fun doesNotHaveClass_reified_parent_class_passes() { + @Test + fun doesNotHaveClass_reified_parent_class_passes() { assertThat(subject).doesNotHaveClass() } - @Test fun doesNotHaveClass_same_class_fails() { + @Test + fun doesNotHaveClass_same_class_fails() { val error = assertFailsWith { assertThat(subject).doesNotHaveClass(BasicObject::class) } assertEquals("expected to not have class:<${BasicObject::class}>", error.message) } - @Test fun doesNotHaveClass_reified_same_class_fails() { + @Test + fun doesNotHaveClass_reified_same_class_fails() { val error = assertFailsWith { assertThat(subject).doesNotHaveClass() } assertEquals("expected to not have class:<${BasicObject::class}>", error.message) } - @Test fun isInstanceOf_kclass_same_class_passes() { + @Test + fun isInstanceOf_kclass_same_class_passes() { assertThat(subject as TestObject).isInstanceOf(BasicObject::class) } - @Test fun isInstanceOf_reified_kclass_same_class_passes() { + @Test + fun isInstanceOf_reified_kclass_same_class_passes() { assertThat(subject as TestObject).isInstanceOf() } - @Test fun isInstanceOf_kclass_parent_class_passes() { + @Test + fun isInstanceOf_kclass_parent_class_passes() { assertThat(subject).isInstanceOf(TestObject::class) } - @Test fun isInstanceOf_reified_kclass_parent_class_passes() { + @Test + fun isInstanceOf_reified_kclass_parent_class_passes() { assertThat(subject).isInstanceOf() } - @Test fun isInstanceOf_kclass_different_class_fails() { + @Test + fun isInstanceOf_kclass_different_class_fails() { val error = assertFailsWith { assertThat(subject).isInstanceOf(DifferentObject::class) } @@ -378,7 +442,8 @@ class AnyTest { ) } - @Test fun isInstanceOf_reified_kclass_different_class_fails() { + @Test + fun isInstanceOf_reified_kclass_different_class_fails() { val error = assertFailsWith { assertThat(subject).isInstanceOf() } @@ -388,7 +453,8 @@ class AnyTest { ) } - @Test fun isInstanceOf_kclass_run_block_when_passes() { + @Test + fun isInstanceOf_kclass_run_block_when_passes() { val error = assertFailsWith { assertThat(subject as TestObject).isInstanceOf(BasicObject::class).prop("str", BasicObject::str) .isEqualTo("wrong") @@ -396,7 +462,8 @@ class AnyTest { assertEquals("expected [str]:<\"[wrong]\"> but was:<\"[test]\"> (test)", error.message) } - @Test fun isInstanceOf_reified_kclass_run_block_when_passes() { + @Test + fun isInstanceOf_reified_kclass_run_block_when_passes() { val error = assertFailsWith { assertThat(subject as TestObject).isInstanceOf().prop("str", BasicObject::str) .isEqualTo("wrong") @@ -404,7 +471,8 @@ class AnyTest { assertEquals("expected [str]:<\"[wrong]\"> but was:<\"[test]\"> (test)", error.message) } - @Test fun isInstanceOf_kclass_doesnt_run_block_when_fails() { + @Test + fun isInstanceOf_kclass_doesnt_run_block_when_fails() { val error = assertFailsWith { assertThat(subject as TestObject).isInstanceOf(DifferentObject::class).isNull() } @@ -414,7 +482,8 @@ class AnyTest { ) } - @Test fun isInstanceOf_reified_kclass_doesnt_run_block_when_fails() { + @Test + fun isInstanceOf_reified_kclass_doesnt_run_block_when_fails() { val error = assertFailsWith { assertThat(subject as TestObject).isInstanceOf().isNull() } @@ -424,58 +493,68 @@ class AnyTest { ) } - @Test fun isNotInstanceOf_kclass_different_class_passes() { + @Test + fun isNotInstanceOf_kclass_different_class_passes() { assertThat(subject).isNotInstanceOf(DifferentObject::class) } - @Test fun isNotInstanceOf_reified_kclass_different_class_passes() { + @Test + fun isNotInstanceOf_reified_kclass_different_class_passes() { assertThat(subject).isNotInstanceOf() } - @Test fun isNotInstanceOf_kclass_same_class_fails() { + @Test + fun isNotInstanceOf_kclass_same_class_fails() { val error = assertFailsWith { assertThat(subject).isNotInstanceOf(BasicObject::class) } assertEquals("expected to not be instance of:<${BasicObject::class}>", error.message) } - @Test fun isNotInstanceOf_reified_kclass_same_class_fails() { + @Test + fun isNotInstanceOf_reified_kclass_same_class_fails() { val error = assertFailsWith { assertThat(subject).isNotInstanceOf() } assertEquals("expected to not be instance of:<${BasicObject::class}>", error.message) } - @Test fun isNotInstanceOf_kclass_parent_class_fails() { + @Test + fun isNotInstanceOf_kclass_parent_class_fails() { val error = assertFailsWith { assertThat(subject).isNotInstanceOf(TestObject::class) } assertEquals("expected to not be instance of:<${TestObject::class}>", error.message) } - @Test fun isNotInstanceOf_reifeid_kclass_parent_class_fails() { + @Test + fun isNotInstanceOf_reifeid_kclass_parent_class_fails() { val error = assertFailsWith { assertThat(subject).isNotInstanceOf() } assertEquals("expected to not be instance of:<${TestObject::class}>", error.message) } - @Test fun corresponds_equivalent_passes() { + @Test + fun corresponds_equivalent_passes() { assertThat(subject).corresponds(BasicObject("different")) { _, _ -> true } } - @Test fun corresponds_not_equivalent_fails() { + @Test + fun corresponds_not_equivalent_fails() { val error = assertFailsWith { assertThat(subject).corresponds(BasicObject("test")) { _, _ -> false } } assertEquals("expected: but was:", error.message) } - @Test fun doesNotCorrespond_equivalent_passes() { + @Test + fun doesNotCorrespond_equivalent_passes() { assertThat(subject).doesNotCorrespond(BasicObject("different")) { _, _ -> false } } - @Test fun doesNotCorrespond_not_equivalent_fails() { + @Test + fun doesNotCorrespond_not_equivalent_fails() { val error = assertFailsWith { assertThat(subject).doesNotCorrespond(BasicObject("different")) { _, _ -> true } } @@ -509,6 +588,7 @@ class AnyTest { class Expected(val value: String) { override fun toString() = value } + class Actual(val value: String) { override fun toString() = value } diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/ArrayTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/ArrayTest.kt index fee171ac..23b096e4 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/ArrayTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/ArrayTest.kt @@ -9,11 +9,13 @@ import kotlin.test.assertFailsWith class ArrayTest { //region isEqualTo - @Test fun isEqualTo_same_contents_passes() { + @Test + fun isEqualTo_same_contents_passes() { assertThat(arrayOf("one")).isEqualTo(arrayOf("one")) } - @Test fun isEqualTo_different_contents_fails() { + @Test + fun isEqualTo_different_contents_fails() { val error = assertFailsWith { assertThat(arrayOf("one")).isEqualTo(arrayOf("two")) } @@ -22,11 +24,13 @@ class ArrayTest { //endregion //region isNotEqualTo - @Test fun isNotEqualTo_different_contents_passes() { + @Test + fun isNotEqualTo_different_contents_passes() { assertThat(arrayOf("one")).isNotEqualTo(arrayOf("two")) } - @Test fun isNotEqualTo_same_contents_fails() { + @Test + fun isNotEqualTo_same_contents_fails() { val error = assertFailsWith { assertThat(arrayOf("one")).isNotEqualTo(arrayOf("one")) } @@ -35,11 +39,13 @@ class ArrayTest { //endregion //region isEmpty - @Test fun isEmpty_empty_passes() { + @Test + fun isEmpty_empty_passes() { assertThat(emptyArray()).isEmpty() } - @Test fun isEmpty_non_empty_fails() { + @Test + fun isEmpty_non_empty_fails() { val error = assertFailsWith { assertThat(arrayOf(null)).isEmpty() } @@ -48,11 +54,13 @@ class ArrayTest { //endregion //region isNotEmpty - @Test fun isNotEmpty_non_empty_passes() { + @Test + fun isNotEmpty_non_empty_passes() { assertThat(arrayOf(null)).isNotEmpty() } - @Test fun isNotEmpty_empty_fails() { + @Test + fun isNotEmpty_empty_fails() { val error = assertFailsWith { assertThat(arrayOf()).isNotEmpty() } @@ -61,15 +69,18 @@ class ArrayTest { //endregion //region isNullOrEmpty - @Test fun isNullOrEmpty_null_passes() { + @Test + fun isNullOrEmpty_null_passes() { assertThat(null as Array?).isNullOrEmpty() } - @Test fun isNullOrEmpty_empty_passes() { + @Test + fun isNullOrEmpty_empty_passes() { assertThat(emptyArray()).isNullOrEmpty() } - @Test fun isNullOrEmpty_non_empty_fails() { + @Test + fun isNullOrEmpty_non_empty_fails() { val error = assertFailsWith { assertThat(arrayOf(null)).isNullOrEmpty() } @@ -78,11 +89,13 @@ class ArrayTest { //endregion //region hasSize - @Test fun hasSize_correct_size_passes() { + @Test + fun hasSize_correct_size_passes() { assertThat(emptyArray()).hasSize(0) } - @Test fun hasSize_wrong_size_fails() { + @Test + fun hasSize_wrong_size_fails() { val error = assertFailsWith { assertThat(emptyArray()).hasSize(1) } @@ -91,11 +104,13 @@ class ArrayTest { //endregion //region hasSameSizeAs - @Test fun hasSameSizeAs_equal_sizes_passes() { + @Test + fun hasSameSizeAs_equal_sizes_passes() { assertThat(emptyArray()).hasSameSizeAs(emptyArray()) } - @Test fun hasSameSizeAs_non_equal_sizes_fails() { + @Test + fun hasSameSizeAs_non_equal_sizes_fails() { val error = assertFailsWith { assertThat(emptyArray()).hasSameSizeAs(arrayOf(null)) } @@ -104,11 +119,13 @@ class ArrayTest { //endregion //region contains - @Test fun contains_element_present_passes() { + @Test + fun contains_element_present_passes() { assertThat(arrayOf(1, 2)).contains(2) } - @Test fun contains_element_missing_fails() { + @Test + fun contains_element_missing_fails() { val error = assertFailsWith { assertThat(emptyArray()).contains(1) } @@ -117,11 +134,13 @@ class ArrayTest { //endregion //region doesNotContain - @Test fun doesNotContain_element_missing_passes() { + @Test + fun doesNotContain_element_missing_passes() { assertThat(emptyArray()).doesNotContain(1) } - @Test fun doesNotContain_element_present_fails() { + @Test + fun doesNotContain_element_present_fails() { val error = assertFailsWith { assertThat(arrayOf(1, 2)).doesNotContain(2) } @@ -130,11 +149,13 @@ class ArrayTest { //endregion //region containsNone - @Test fun containsNone_missing_elements_passes() { + @Test + fun containsNone_missing_elements_passes() { assertThat(emptyArray()).containsNone(1) } - @Test fun containsNone_present_element_fails() { + @Test + fun containsNone_present_element_fails() { val error = assertFailsWith { assertThat(arrayOf(1, 2)).containsNone(2, 3) } @@ -147,15 +168,18 @@ class ArrayTest { //region //region containsAtLeast - @Test fun containsAtLeast_all_elements_passes() { + @Test + fun containsAtLeast_all_elements_passes() { assertThat(arrayOf(1, 2)).containsAtLeast(2, 1) } - @Test fun containsAtLeast_extra_elements_passes() { + @Test + fun containsAtLeast_extra_elements_passes() { assertThat(arrayOf(1, 2, 3)).containsAtLeast(1, 2) } - @Test fun containsAtLeast_some_elements_fails() { + @Test + fun containsAtLeast_some_elements_fails() { val error = assertFailsWith { assertThat(arrayOf(1)).containsAtLeast(1, 2) } @@ -168,11 +192,13 @@ class ArrayTest { //endregion //region containsOnly - @Test fun containsOnly_only_elements_passes() { + @Test + fun containsOnly_only_elements_passes() { assertThat(arrayOf(1, 2)).containsOnly(2, 1) } - @Test fun containsOnly_more_elements_fails() { + @Test + fun containsOnly_more_elements_fails() { val error = assertFailsWith { assertThat(arrayOf(1, 2, 3)).containsOnly(2, 1) } @@ -183,7 +209,8 @@ class ArrayTest { ) } - @Test fun containsOnly_less_elements_fails() { + @Test + fun containsOnly_less_elements_fails() { val error = assertFailsWith { assertThat(arrayOf(1, 2, 3)).containsOnly(2, 1, 3, 4) } @@ -195,7 +222,8 @@ class ArrayTest { ) } - @Test fun containsOnly_different_elements_fails() { + @Test + fun containsOnly_different_elements_fails() { val error = assertFailsWith { assertThat(arrayOf(1)).containsOnly(2) } @@ -210,11 +238,13 @@ class ArrayTest { //endregion //region containsExactly - @Test fun containsExactly_all_elements_in_same_order_passes() { + @Test + fun containsExactly_all_elements_in_same_order_passes() { assertThat(arrayOf(1, 2)).containsExactly(1, 2) } - @Test fun containsExactly_all_elements_in_different_order_fails() { + @Test + fun containsExactly_all_elements_in_different_order_fails() { val error = assertFailsWith { assertThat(arrayOf(1, 2)).containsExactly(2, 1) } @@ -226,7 +256,8 @@ class ArrayTest { ) } - @Test fun containsExactly_missing_element_fails() { + @Test + fun containsExactly_missing_element_fails() { val error = assertFailsWith { assertThat(arrayOf(1, 2)).containsExactly(3) } @@ -239,7 +270,8 @@ class ArrayTest { ) } - @Test fun containsExactly_same_indexes_are_together() { + @Test + fun containsExactly_same_indexes_are_together() { val error = assertFailsWith { assertThat(arrayOf(1, 1)).containsExactly(2, 2) } @@ -253,7 +285,8 @@ class ArrayTest { ) } - @Test fun containsExactly_extra_element_fails() { + @Test + fun containsExactly_extra_element_fails() { val error = assertFailsWith { assertThat(arrayOf(1, 2)).containsExactly(1, 2, 3) } @@ -264,7 +297,8 @@ class ArrayTest { ) } - @Test fun containsExactly_missing_element_in_middle_fails() { + @Test + fun containsExactly_missing_element_in_middle_fails() { val error = assertFailsWith { assertThat(arrayOf(1, 3)).containsExactly(1, 2, 3) } @@ -275,7 +309,8 @@ class ArrayTest { ) } - @Test fun containsExactly_extra_element_in_middle_fails() { + @Test + fun containsExactly_extra_element_in_middle_fails() { val error = assertFailsWith { assertThat(arrayOf(1, 2, 3)).containsExactly(1, 3) } @@ -288,15 +323,18 @@ class ArrayTest { //endregion //region each - @Test fun each_empty_list_passes() { + @Test + fun each_empty_list_passes() { assertThat(emptyArray()).each { it.isEqualTo(1) } } - @Test fun each_content_passes() { + @Test + fun each_content_passes() { assertThat(arrayOf(1, 2)).each { it.isGreaterThan(0) } } - @Test fun each_non_matching_content_fails() { + @Test + fun each_non_matching_content_fails() { val error = assertFailsWith { assertThat(arrayOf(1, 2, 3)).each { it.isLessThan(2) } } @@ -310,11 +348,13 @@ class ArrayTest { //endregion //region index - @Test fun index_successful_assertion_passes() { + @Test + fun index_successful_assertion_passes() { assertThat(arrayOf("one", "two"), name = "subject").index(0).isEqualTo("one") } - @Test fun index_unsuccessful_assertion_fails() { + @Test + fun index_unsuccessful_assertion_fails() { val error = assertFailsWith { assertThat(arrayOf("one", "two"), name = "subject").index(0).isEqualTo("wrong") } @@ -324,7 +364,8 @@ class ArrayTest { ) } - @Test fun index_out_of_range_fails() { + @Test + fun index_out_of_range_fails() { val error = assertFailsWith { assertThat(arrayOf("one", "two"), name = "subject").index(-1).isEqualTo(listOf("one")) } @@ -333,11 +374,13 @@ class ArrayTest { //endregion //region extracting - @Test fun single_extracting_function_passes() { + @Test + fun single_extracting_function_passes() { assertThat(arrayOf("one", "two")).extracting { it.length }.containsExactly(3, 3) } - @Test fun single_extracting_function_fails() { + @Test + fun single_extracting_function_fails() { val error = assertFailsWith { assertThat(arrayOf("one", "two")).extracting { it.length }.containsExactly(2, 2) } @@ -351,13 +394,15 @@ class ArrayTest { ) } - @Test fun pair_extracting_function_passes() { + @Test + fun pair_extracting_function_passes() { assertThat(listOf(Thing("one", 1, '1'), Thing("two", 2, '2'))) .extracting(Thing::one, Thing::two) .containsExactly("one" to 1, "two" to 2) } - @Test fun pair_extracting_function_fails() { + @Test + fun pair_extracting_function_fails() { val error = assertFailsWith { assertThat(arrayOf(Thing("one", 1, '1'), Thing("two", 2, '2'))) .extracting(Thing::one, Thing::two) @@ -374,13 +419,15 @@ class ArrayTest { ) } - @Test fun triple_extracting_function_passes() { + @Test + fun triple_extracting_function_passes() { assertThat(arrayOf(Thing("one", 1, '1'), Thing("two", 2, '2'))) .extracting(Thing::one, Thing::two, Thing::three) .containsExactly(Triple("one", 1, '1'), Triple("two", 2, '2')) } - @Test fun triple_extracting_function_fails() { + @Test + fun triple_extracting_function_fails() { val error = assertFailsWith { assertThat(arrayOf(Thing("one", 1, '1'), Thing("two", 2, '2'))) .extracting(Thing::one, Thing::two, Thing::three) diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/BooleanTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/BooleanTest.kt index 22d658b4..e811d1e5 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/BooleanTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/BooleanTest.kt @@ -9,11 +9,13 @@ import kotlin.test.assertFailsWith class BooleanTest { //region isTrue - @Test fun isTrue_true_value_passes() { + @Test + fun isTrue_true_value_passes() { assertThat(true).isTrue() } - @Test fun isTrue_false_value_fails() { + @Test + fun isTrue_false_value_fails() { val error = assertFailsWith { assertThat(false).isTrue() } @@ -22,11 +24,13 @@ class BooleanTest { //endregion //region isFalse - @Test fun isFalse_false_value_passes() { + @Test + fun isFalse_false_value_passes() { assertThat(false).isFalse() } - @Test fun isFalse_true_value_fails() { + @Test + fun isFalse_true_value_fails() { val error = assertFailsWith { assertThat(true).isFalse() } diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/CharSequenceTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/CharSequenceTest.kt index cddd8754..8eb64c0b 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/CharSequenceTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/CharSequenceTest.kt @@ -9,17 +9,20 @@ import kotlin.test.assertFailsWith class CharSequenceTest { //region props - @Test fun extracts_length() { + @Test + fun extracts_length() { assertEquals(4, assertThat("test").length().valueOrFail) } //endregion //region isEmpty - @Test fun isEmpty_empty_passes() { + @Test + fun isEmpty_empty_passes() { assertThat("").isEmpty() } - @Test fun isEmpty_non_empty_fails() { + @Test + fun isEmpty_non_empty_fails() { val error = assertFailsWith { assertThat("test").isEmpty() } @@ -28,11 +31,13 @@ class CharSequenceTest { //endregion //region isNotEmpty - @Test fun isNotEmpty_non_empty_passes() { + @Test + fun isNotEmpty_non_empty_passes() { assertThat("test").isNotEmpty() } - @Test fun isNotEmpty_empty_fails() { + @Test + fun isNotEmpty_empty_fails() { val error = assertFailsWith { assertThat("").isNotEmpty() } @@ -41,15 +46,18 @@ class CharSequenceTest { //endregion //region isNullOrEmpty - @Test fun isNullOrEmpty_null_passes() { + @Test + fun isNullOrEmpty_null_passes() { assertThat(null as CharSequence?).isNullOrEmpty() } - @Test fun isNullOrEmpty_empty_passes() { + @Test + fun isNullOrEmpty_empty_passes() { assertThat("").isNullOrEmpty() } - @Test fun isNullOrEmpty_non_empty_fails() { + @Test + fun isNullOrEmpty_non_empty_fails() { val error = assertFailsWith { assertThat("test").isNullOrEmpty() } @@ -58,11 +66,13 @@ class CharSequenceTest { //endregion //region hasLength - @Test fun hasLength_correct_length_passes() { + @Test + fun hasLength_correct_length_passes() { assertThat("test").hasLength(4) } - @Test fun hasLength_wrong_length_fails() { + @Test + fun hasLength_wrong_length_fails() { val error = assertFailsWith { assertThat("test").hasLength(0) } @@ -71,11 +81,13 @@ class CharSequenceTest { //endregion //region hasSameLengthAs - @Test fun hasSameLengthAs_same_length_passes() { + @Test + fun hasSameLengthAs_same_length_passes() { assertThat("test").hasSameLengthAs("four") } - @Test fun hasSameLengthAs_different_length_fails() { + @Test + fun hasSameLengthAs_different_length_fails() { val error = assertFailsWith { assertThat("test").hasSameLengthAs("") } @@ -84,22 +96,26 @@ class CharSequenceTest { //endregion //region contains single - @Test fun contains_value_substring_passes() { + @Test + fun contains_value_substring_passes() { assertThat("test").contains("est") } - @Test fun contains_value_not_substring_fails() { + @Test + fun contains_value_not_substring_fails() { val error = assertFailsWith { assertThat("test").contains("not") } assertEquals("expected to contain:<\"not\"> but was:<\"test\">", error.message) } - @Test fun contains_value_substring_ignore_case_passes() { + @Test + fun contains_value_substring_ignore_case_passes() { assertThat("Test").contains("EST", true) } - @Test fun contains_value_not_substring_ignore_case_fails() { + @Test + fun contains_value_not_substring_ignore_case_fails() { val error = assertFailsWith { assertThat("Test").contains("EST", false) } @@ -108,34 +124,41 @@ class CharSequenceTest { //endregion //region contains multi - @Test fun contains_empty_arg_passes() { + @Test + fun contains_empty_arg_passes() { assertThat("test").contains() } - @Test fun contains_value_contains_passes() { + @Test + fun contains_value_contains_passes() { assertThat("test").contains("te", "st") } - @Test fun contains_list_contains_passes() { + @Test + fun contains_list_contains_passes() { assertThat("test").contains(listOf("te", "st")) } - @Test fun contains_contains_unordered_passes() { + @Test + fun contains_contains_unordered_passes() { assertThat("test").contains("st", "te") } - @Test fun contains_value_not_contains_fails() { + @Test + fun contains_value_not_contains_fails() { val error = assertFailsWith { assertThat("test").contains("foo", "bar") } assertEquals("expected to contain:<[\"foo\", \"bar\"]> but was:<\"test\">", error.message) } - @Test fun contains_value_contains_ignore_case_passes() { + @Test + fun contains_value_contains_ignore_case_passes() { assertThat("Test").contains("te", "ST", ignoreCase = true) } - @Test fun contains_value_not_contains_ignore_case_fails() { + @Test + fun contains_value_not_contains_ignore_case_fails() { val error = assertFailsWith { assertThat("Test").contains("te", "ST", ignoreCase = false) } @@ -145,70 +168,82 @@ class CharSequenceTest { //region doesNotContain single - @Test fun doesNotContain_value_not_substring_passes() { + @Test + fun doesNotContain_value_not_substring_passes() { assertThat("test").doesNotContain("not") } - @Test fun doesNotContain_value_substring_fails() { + @Test + fun doesNotContain_value_substring_fails() { val error = assertFailsWith { assertThat("test").doesNotContain("est") } assertEquals("expected to not contain:<\"est\"> but was:<\"test\">", error.message) } - @Test fun doesNotContain_value_substring_ignore_case_fails() { + @Test + fun doesNotContain_value_substring_ignore_case_fails() { val error = assertFailsWith { assertThat("Test").doesNotContain("EST", true) } assertEquals("expected to not contain:<\"EST\"> but was:<\"Test\">", error.message) } - @Test fun doesNotContain_value_not_substring_ignore_case_passes() { + @Test + fun doesNotContain_value_not_substring_ignore_case_passes() { assertThat("Test").doesNotContain("EST", false) } //endregion //region doesNotContain multi - @Test fun doesNotContain_multivalue_not_substring_passes() { + @Test + fun doesNotContain_multivalue_not_substring_passes() { assertThat("test").doesNotContain("foo", "bar") } - @Test fun doesNotContain_multivalue_substring_fails() { + @Test + fun doesNotContain_multivalue_substring_fails() { val error = assertFailsWith { assertThat("test").doesNotContain("te", "st") } assertEquals("expected to not contain:<[\"te\", \"st\"]> but was:<\"test\">", error.message) } - @Test fun doesNotContain_multivalue_substring_ignore_case_fails() { + @Test + fun doesNotContain_multivalue_substring_ignore_case_fails() { val error = assertFailsWith { assertThat("Test").doesNotContain("TE", "ST", ignoreCase = true) } assertEquals("expected to not contain:<[\"TE\", \"ST\"]> but was:<\"Test\">", error.message) } - @Test fun doesNotContain_multivalue_not_substring_ignore_case_passes() { + @Test + fun doesNotContain_multivalue_not_substring_ignore_case_passes() { assertThat("Test").doesNotContain("TE", "ST", ignoreCase = false) } //endregion //region startsWith - @Test fun startsWith_value_prefix_passes() { + @Test + fun startsWith_value_prefix_passes() { assertThat("test").startsWith("te") } - @Test fun startsWith_value_not_prefix_fails() { + @Test + fun startsWith_value_not_prefix_fails() { val error = assertFailsWith { assertThat("test").startsWith("st") } assertEquals("expected to start with:<\"st\"> but was:<\"test\">", error.message) } - @Test fun startsWith_value_prefix_ignore_case_passes() { + @Test + fun startsWith_value_prefix_ignore_case_passes() { assertThat("test").startsWith("TE", true) } - @Test fun startsWith_value_not_prefix_ignore_case_fails() { + @Test + fun startsWith_value_not_prefix_ignore_case_fails() { val error = assertFailsWith { assertThat("test").startsWith("TE", false) } @@ -217,22 +252,26 @@ class CharSequenceTest { //endregion //region endsWith - @Test fun endsWith_value_suffix_passes() { + @Test + fun endsWith_value_suffix_passes() { assertThat("test").endsWith("st") } - @Test fun endsWith_value_not_suffix_fails() { + @Test + fun endsWith_value_not_suffix_fails() { val error = assertFailsWith { assertThat("test").endsWith("te") } assertEquals("expected to end with:<\"te\"> but was:<\"test\">", error.message) } - @Test fun endsWith_value_suffix_ignore_case_passes() { + @Test + fun endsWith_value_suffix_ignore_case_passes() { assertThat("test").endsWith("ST", true) } - @Test fun endsWith_value_not_suffix_ignore_case_passes() { + @Test + fun endsWith_value_not_suffix_ignore_case_passes() { val error = assertFailsWith { assertThat("test").endsWith("ST", false) } @@ -241,7 +280,8 @@ class CharSequenceTest { //endregion //region hasLineCount - @Test fun hasLineCount_correct_value_passes() { + @Test + fun hasLineCount_correct_value_passes() { assertThat("").hasLineCount(1) assertThat("test test").hasLineCount(1) assertThat("test test\ntest test").hasLineCount(2) @@ -249,7 +289,8 @@ class CharSequenceTest { assertThat("test test\rtest test").hasLineCount(2) } - @Test fun hasLineCount_wrong_value_fails() { + @Test + fun hasLineCount_wrong_value_fails() { val error = assertFailsWith { assertThat("test test").hasLineCount(2) } @@ -258,11 +299,13 @@ class CharSequenceTest { //endregion //region matches - @Test fun matches_matching_value_passes() { + @Test + fun matches_matching_value_passes() { assertThat("1234").matches(Regex("\\d\\d\\d\\d")) } - @Test fun matches_not_matching_value_fails() { + @Test + fun matches_not_matching_value_fails() { val regex = Regex("\\d\\d\\d\\d") val error = assertFailsWith { assertThat("12345").matches(regex) @@ -272,11 +315,13 @@ class CharSequenceTest { //endregion //region contains match - @Test fun contains_match_matching_value_passes() { + @Test + fun contains_match_matching_value_passes() { assertThat("abc1234xyz").containsMatch(Regex("\\d\\d\\d\\d")) } - @Test fun contains_match_not_matching_value_fails() { + @Test + fun contains_match_not_matching_value_fails() { val regex = Regex("\\d\\d\\d\\d") val error = assertFailsWith { assertThat("abc123xyz").containsMatch(regex) diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/CollectionTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/CollectionTest.kt index c4dc42b6..03eb67a3 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/CollectionTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/CollectionTest.kt @@ -8,11 +8,13 @@ import kotlin.test.assertFailsWith class CollectionTest { //region isEmpty - @Test fun isEmpty_empty_passes() { + @Test + fun isEmpty_empty_passes() { assertThat(emptyList()).isEmpty() } - @Test fun isEmpty_non_empty_fails() { + @Test + fun isEmpty_non_empty_fails() { val error = assertFailsWith { assertThat(listOf(null)).isEmpty() } @@ -21,11 +23,13 @@ class CollectionTest { //endregion //region isNotEmpty - @Test fun isNotEmpty_non_empty_passes() { + @Test + fun isNotEmpty_non_empty_passes() { assertThat(listOf(null)).isNotEmpty() } - @Test fun isNotEmpty_empty_fails() { + @Test + fun isNotEmpty_empty_fails() { val error = assertFailsWith { assertThat(emptyList()).isNotEmpty() } @@ -34,15 +38,18 @@ class CollectionTest { //endregion //region isNullOrEmpty - @Test fun isNullOrEmpty_null_passes() { + @Test + fun isNullOrEmpty_null_passes() { assertThat(null as List?).isNullOrEmpty() } - @Test fun isNullOrEmpty_empty_passes() { + @Test + fun isNullOrEmpty_empty_passes() { assertThat(emptyList()).isNullOrEmpty() } - @Test fun isNullOrEmpty_non_empty_fails() { + @Test + fun isNullOrEmpty_non_empty_fails() { val error = assertFailsWith { assertThat(listOf(null)).isNullOrEmpty() } @@ -51,11 +58,13 @@ class CollectionTest { //endregion //region hasSize - @Test fun hasSize_correct_size_passes() { + @Test + fun hasSize_correct_size_passes() { assertThat(emptyList()).hasSize(0) } - @Test fun hasSize_wrong_size_fails() { + @Test + fun hasSize_wrong_size_fails() { val error = assertFailsWith { assertThat(emptyList()).hasSize(1) } @@ -64,11 +73,13 @@ class CollectionTest { //endregion //region hasSameSizeAs - @Test fun hasSameSizeAs_equal_sizes_passes() { + @Test + fun hasSameSizeAs_equal_sizes_passes() { assertThat(emptyList()).hasSameSizeAs(emptyList()) } - @Test fun hasSameSizeAs_non_equal_sizes_fails() { + @Test + fun hasSameSizeAs_non_equal_sizes_fails() { val error = assertFailsWith { assertThat(emptyList()).hasSameSizeAs(listOf(null)) } diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/ComparableTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/ComparableTest.kt index 79513787..bacb4192 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/ComparableTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/ComparableTest.kt @@ -16,11 +16,13 @@ import kotlin.test.assertFailsWith class ComparableTest { //region isGreaterThan - @Test fun isGreaterThan_greater_value_passes() { + @Test + fun isGreaterThan_greater_value_passes() { assertThat(2).isGreaterThan(1) } - @Test fun isGreaterThan_non_greater_value_fails() { + @Test + fun isGreaterThan_non_greater_value_fails() { val error = assertFailsWith { assertThat(0).isGreaterThan(0) } @@ -29,11 +31,13 @@ class ComparableTest { //endregion //region isLessThan - @Test fun isLessThan_lesser_value_passes() { + @Test + fun isLessThan_lesser_value_passes() { assertThat(1).isLessThan(2) } - @Test fun isLessThan_non_lesser_value_fails() { + @Test + fun isLessThan_non_lesser_value_fails() { val error = assertFailsWith { assertThat(0).isLessThan(0) } @@ -42,15 +46,18 @@ class ComparableTest { //endregion //region isGreaterThanOrEqualTo - @Test fun isGreaterThanOrEqualTo_greater_value_passes() { + @Test + fun isGreaterThanOrEqualTo_greater_value_passes() { assertThat(2).isGreaterThanOrEqualTo(1) } - @Test fun isGreaterThanOrEqualTo_equal_value_passes() { + @Test + fun isGreaterThanOrEqualTo_equal_value_passes() { assertThat(2).isGreaterThanOrEqualTo(2) } - @Test fun isGreaterThanOrEqualTo_lesser_value_fails() { + @Test + fun isGreaterThanOrEqualTo_lesser_value_fails() { val error = assertFailsWith { assertThat(0).isGreaterThanOrEqualTo(2) } @@ -59,15 +66,18 @@ class ComparableTest { //endregion //region isLessThanOrEqualTo - @Test fun isLessThanOrEqualTo_lesser_value_passes() { + @Test + fun isLessThanOrEqualTo_lesser_value_passes() { assertThat(1).isLessThanOrEqualTo(2) } - @Test fun isLessThanOrEqualTo_equal_value_passes() { + @Test + fun isLessThanOrEqualTo_equal_value_passes() { assertThat(2).isLessThanOrEqualTo(2) } - @Test fun isLessThanOrEqualTo_greater_value_fails() { + @Test + fun isLessThanOrEqualTo_greater_value_fails() { val error = assertFailsWith { assertThat(2).isLessThanOrEqualTo(0) } @@ -76,26 +86,31 @@ class ComparableTest { //endregion //region isBetween - @Test fun isBetween_inside_range_passes() { + @Test + fun isBetween_inside_range_passes() { assertThat(1).isBetween(0, 2) } - @Test fun isBetween_lower_bound_passes() { + @Test + fun isBetween_lower_bound_passes() { assertThat(0).isBetween(0, 2) } - @Test fun isBetween_upper_bound_passes() { + @Test + fun isBetween_upper_bound_passes() { assertThat(2).isBetween(0, 2) } - @Test fun isBetween_below_lower_bound_fails() { + @Test + fun isBetween_below_lower_bound_fails() { val error = assertFailsWith { assertThat(-1).isBetween(0, 2) } assertEquals("expected to be between:<0> and <2> but was:<-1>", error.message) } - @Test fun isBetween_above_upper_bound_fails() { + @Test + fun isBetween_above_upper_bound_fails() { val error = assertFailsWith { assertThat(3).isBetween(0, 2) } @@ -104,32 +119,37 @@ class ComparableTest { //endregion //region isStrictlyBetween - @Test fun isStrictlyBetween_inside_range_passes() { + @Test + fun isStrictlyBetween_inside_range_passes() { assertThat(0 + 1).isStrictlyBetween(0, 2) } - @Test fun isStrictlyBetween_lower_bound_fails() { + @Test + fun isStrictlyBetween_lower_bound_fails() { val error = assertFailsWith { assertThat(0).isStrictlyBetween(0, 2) } assertEquals("expected to be strictly between:<0> and <2> but was:<0>", error.message) } - @Test fun isStrictlyBetween_upper_bound_fails() { + @Test + fun isStrictlyBetween_upper_bound_fails() { val error = assertFailsWith { assertThat(2).isStrictlyBetween(0, 2) } assertEquals("expected to be strictly between:<0> and <2> but was:<2>", error.message) } - @Test fun isStrictlyBetween_below_lower_bound_fails() { + @Test + fun isStrictlyBetween_below_lower_bound_fails() { val error = assertFailsWith { assertThat(0 - 1).isStrictlyBetween(0, 2) } assertEquals("expected to be strictly between:<0> and <2> but was:<-1>", error.message) } - @Test fun isStrictlyBetween_above_upper_bound_fails() { + @Test + fun isStrictlyBetween_above_upper_bound_fails() { val error = assertFailsWith { assertThat(2 + 1).isStrictlyBetween(0, 2) } @@ -163,7 +183,10 @@ class ComparableTest { val error = assertFailsWith { assertThat(10.1f).isCloseTo(15.0f, 3f) } - assertEquals("expected ${show(10.1f)} to be close to ${show(15.0f)} with delta of ${show(3f)}, but was not", error.message) + assertEquals( + "expected ${show(10.1f)} to be close to ${show(15.0f)} with delta of ${show(3f)}, but was not", + error.message + ) } @Test @@ -171,7 +194,10 @@ class ComparableTest { val error = assertFailsWith { assertThat(10.1).isCloseTo(15.0, 3.0) } - assertEquals("expected ${show(10.1)} to be close to ${show(15.0)} with delta of ${show(3.0)}, but was not", error.message) + assertEquals( + "expected ${show(10.1)} to be close to ${show(15.0)} with delta of ${show(3.0)}, but was not", + error.message + ) } @Test @@ -187,10 +213,11 @@ class ComparableTest { assertThat(Info("aaa")).isEqualByComparingTo(Info("bbb")) } - private class Info(private val data: String): Comparable { + private class Info(private val data: String) : Comparable { override fun compareTo(other: Info): Int { return data.length - other.data.length } + override fun toString(): String { return data } diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/IterableTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/IterableTest.kt index fb57146b..32361f81 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/IterableTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/IterableTest.kt @@ -31,11 +31,13 @@ import kotlin.test.assertFailsWith class IterableTest { //region contains - @Test fun contains_element_present_passes() { + @Test + fun contains_element_present_passes() { assertThat(iterableOf(1, 2)).contains(2) } - @Test fun contains_element_missing_fails() { + @Test + fun contains_element_missing_fails() { val error = assertFailsWith { assertThat(emptyIterable()).contains(1) } @@ -44,11 +46,13 @@ class IterableTest { //endregion //region doesNotContain - @Test fun doesNotContain_element_missing_passes() { + @Test + fun doesNotContain_element_missing_passes() { assertThat(emptyIterable()).doesNotContain(1) } - @Test fun doesNotContain_element_present_fails() { + @Test + fun doesNotContain_element_present_fails() { val error = assertFailsWith { assertThat(iterableOf(1, 2)).doesNotContain(2) } @@ -57,11 +61,13 @@ class IterableTest { //endregion //region containsNone - @Test fun containsNone_missing_elements_passes() { + @Test + fun containsNone_missing_elements_passes() { assertThat(emptyIterable()).containsNone(1) } - @Test fun containsNone_present_element_fails() { + @Test + fun containsNone_present_element_fails() { val error = assertFailsWith { assertThat(iterableOf(1, 2)).containsNone(2, 3) } @@ -74,11 +80,13 @@ class IterableTest { //region //region containsAtLeast - @Test fun containsAtLeast_all_elements_passes() { + @Test + fun containsAtLeast_all_elements_passes() { assertThat(iterableOf(1, 2)).containsAtLeast(2, 1) } - @Test fun containsAtLeast_some_elements_fails() { + @Test + fun containsAtLeast_some_elements_fails() { val error = assertFailsWith { assertThat(iterableOf(1)).containsAtLeast(1, 2) } @@ -91,19 +99,23 @@ class IterableTest { //endregion //region containsOnly - @Test fun containsOnly_only_elements_passes() { + @Test + fun containsOnly_only_elements_passes() { assertThat(iterableOf(1, 2)).containsOnly(2, 1) } - @Test fun containsOnly_duplicate_elements_passes() { + @Test + fun containsOnly_duplicate_elements_passes() { assertThat(iterableOf(1, 2, 2)).containsOnly(2, 1) } - @Test fun containsOnly_duplicate_elements_passes2() { + @Test + fun containsOnly_duplicate_elements_passes2() { assertThat(iterableOf(1, 2)).containsOnly(2, 2, 1) } - @Test fun containsOnly_more_elements_fails() { + @Test + fun containsOnly_more_elements_fails() { val error = assertFailsWith { assertThat(iterableOf(1, 2, 3)).containsOnly(2, 1) } @@ -114,7 +126,8 @@ class IterableTest { ) } - @Test fun containsOnly_less_elements_fails() { + @Test + fun containsOnly_less_elements_fails() { val error = assertFailsWith { assertThat(iterableOf(1, 2, 3)).containsOnly(2, 1, 3, 4) } @@ -126,7 +139,8 @@ class IterableTest { ) } - @Test fun containsOnly_different_elements_fails() { + @Test + fun containsOnly_different_elements_fails() { val error = assertFailsWith { assertThat(iterableOf(1)).containsOnly(2) } @@ -141,15 +155,18 @@ class IterableTest { //endregion //region containsExactlyInAnyOrder - @Test fun containsExactlyInAnyOrder_only_elements_passes() { + @Test + fun containsExactlyInAnyOrder_only_elements_passes() { assertThat(iterableOf(1, 2)).containsExactlyInAnyOrder(2, 1) } - @Test fun containsExactlyInAnyOrder_only_elements_passes2() { + @Test + fun containsExactlyInAnyOrder_only_elements_passes2() { assertThat(iterableOf(1, 2, 1)).containsExactlyInAnyOrder(2, 1, 1) } - @Test fun containsExactlyInAnyOrder_duplicate_elements_fails() { + @Test + fun containsExactlyInAnyOrder_duplicate_elements_fails() { val error = assertFailsWith { assertThat(iterableOf(1, 2, 2)).containsExactlyInAnyOrder(2, 1) } @@ -160,7 +177,8 @@ class IterableTest { ) } - @Test fun containsExactlyInAnyOrder_duplicate_elements_fails2() { + @Test + fun containsExactlyInAnyOrder_duplicate_elements_fails2() { val error = assertFailsWith { assertThat(iterableOf(1, 2)).containsExactlyInAnyOrder(2, 2, 1) } @@ -171,7 +189,8 @@ class IterableTest { ) } - @Test fun containsExactlyInAnyOrder_more_elements_fails() { + @Test + fun containsExactlyInAnyOrder_more_elements_fails() { val error = assertFailsWith { assertThat(iterableOf(1, 2, 3)).containsExactlyInAnyOrder(2, 1) } @@ -182,7 +201,8 @@ class IterableTest { ) } - @Test fun containsExactlyInAnyOrder_less_elements_fails() { + @Test + fun containsExactlyInAnyOrder_less_elements_fails() { val error = assertFailsWith { assertThat(iterableOf(1, 2, 3)).containsExactlyInAnyOrder(2, 1, 3, 4) } @@ -194,7 +214,8 @@ class IterableTest { ) } - @Test fun containsExactlyInAnyOrder_different_elements_fails() { + @Test + fun containsExactlyInAnyOrder_different_elements_fails() { val error = assertFailsWith { assertThat(iterableOf(1)).containsExactlyInAnyOrder(2) } @@ -209,15 +230,18 @@ class IterableTest { //endregion //region each - @Test fun each_empty_list_passes() { + @Test + fun each_empty_list_passes() { assertThat(emptyIterable()).each { it.isEqualTo(1) } } - @Test fun each_content_passes() { + @Test + fun each_content_passes() { assertThat(iterableOf(1, 2)).each { it.isGreaterThan(0) } } - @Test fun each_non_matching_content_fails() { + @Test + fun each_non_matching_content_fails() { val error = assertFailsWith { assertThat(iterableOf(1, 2, 3)).each { it.isLessThan(2) } } @@ -231,11 +255,13 @@ class IterableTest { //endregion //region none - @Test fun none_empty_list_passes() { + @Test + fun none_empty_list_passes() { assertThat(emptyIterable()).none { it.isEqualTo(1) } } - @Test fun none_matching_content_fails() { + @Test + fun none_matching_content_fails() { val error = assertFailsWith { assertThat(iterableOf(1, 2)).none { it.isGreaterThan(0) } } @@ -247,7 +273,8 @@ class IterableTest { ) } - @Test fun none_matching_some_content_fails() { + @Test + fun none_matching_some_content_fails() { val error = assertFailsWith { assertThat(listOf(1, 2, 3) as Iterable).none { it.isGreaterThanOrEqualTo(3) } } @@ -258,11 +285,13 @@ class IterableTest { ) } - @Test fun none_all_non_matching_content_passes() { + @Test + fun none_all_non_matching_content_passes() { assertThat(listOf(1, 2, 3) as Iterable).none { it.isLessThan(0) } } - @Test fun none_multiple_failures_passes() { + @Test + fun none_multiple_failures_passes() { assertThat(iterableOf(1, 2, 3)).none { it.isLessThan(2) it.isGreaterThan(2) @@ -271,7 +300,8 @@ class IterableTest { //endregion //region atLeast - @Test fun atLeast_too_many_failures_fails() { + @Test + fun atLeast_too_many_failures_fails() { val error = assertFailsWith { assertThat(iterableOf(1, 2, 3)).atLeast(2) { it.isGreaterThan(2) } } @@ -283,19 +313,23 @@ class IterableTest { ) } - @Test fun atLeast_no_failures_passes() { + @Test + fun atLeast_no_failures_passes() { assertThat(iterableOf(1, 2, 3)).atLeast(2) { it.isGreaterThan(0) } } - @Test fun atLeast_less_than_times_failures_passes() { + @Test + fun atLeast_less_than_times_failures_passes() { assertThat(iterableOf(1, 2, 3)).atLeast(2) { it.isGreaterThan(1) } } - @Test fun atLeast_works_in_a_soft_assert_context() { + @Test + fun atLeast_works_in_a_soft_assert_context() { assertThat(iterableOf(1, 2, 3)).all { atLeast(2) { it.isGreaterThan(1) } } } - @Test fun atLeast_multiple_failures_passes() { + @Test + fun atLeast_multiple_failures_passes() { assertThat(listOf(1, 2, 3) as Iterable).atLeast(2) { it.isGreaterThan(1) it.isGreaterThan(1) @@ -304,7 +338,8 @@ class IterableTest { //endregion //region atMost - @Test fun atMost_more_than_times_passed_fails() { + @Test + fun atMost_more_than_times_passed_fails() { val error = assertFailsWith { assertThat(iterableOf(1, 2, 3)).atMost(2) { it.isGreaterThan(0) } } @@ -313,19 +348,22 @@ class IterableTest { ) } - @Test fun atMost_exactly_times_passed_passes() { + @Test + fun atMost_exactly_times_passed_passes() { assertThat(iterableOf(1, 2, 3)).atMost(2) { it.isGreaterThan(1) } } - @Test fun atMost_less_than_times_passed_passes() { + @Test + fun atMost_less_than_times_passed_passes() { assertThat(iterableOf(1, 2)).atMost(2) { it.isGreaterThan(1) } } //endregion //region exactly - @Test fun exactly_too_few_passes_fails() { + @Test + fun exactly_too_few_passes_fails() { val error = assertFailsWith { assertThat(iterableOf(1, 2, 3)).exactly(2) { it.isGreaterThan(2) } } @@ -337,7 +375,8 @@ class IterableTest { ) } - @Test fun exactly_too_many_passes_fails() { + @Test + fun exactly_too_many_passes_fails() { val error = assertFailsWith { assertThat(iterableOf(5, 4, 3)).exactly(2) { it.isGreaterThan(2) } } @@ -346,7 +385,8 @@ class IterableTest { ) } - @Test fun exactly_too_few_inside_all_fails() { + @Test + fun exactly_too_few_inside_all_fails() { val error = assertFailsWith { assertThat(iterableOf(5, 4, 3)).all { exactly(2) { it.isGreaterThan(2) } @@ -357,11 +397,13 @@ class IterableTest { ) } - @Test fun exactly_times_passed_passes() { + @Test + fun exactly_times_passed_passes() { assertThat(iterableOf(0, 1, 2)).exactly(2) { it.isGreaterThan(0) } } - @Test fun exactly_times_passed_passes_multiple_assertions() { + @Test + fun exactly_times_passed_passes_multiple_assertions() { assertThat(listOf(0, 1, 2) as Iterable).exactly(2) { it.isGreaterThan(0) it.isGreaterThan(0) @@ -370,11 +412,13 @@ class IterableTest { //endregion //region any - @Test fun any_passes_if_one_item_passes() { + @Test + fun any_passes_if_one_item_passes() { assertThat(iterableOf(1, 2)).any { it.isGreaterThan(1) } } - @Test fun any_fails_if_all_fail() { + @Test + fun any_fails_if_all_fail() { val error = assertFailsWith { assertThat(iterableOf(1, 2)).any { it.isGreaterThan(3) } } @@ -386,7 +430,8 @@ class IterableTest { ) } - @Test fun any_multiple_assertions_fail() { + @Test + fun any_multiple_assertions_fail() { assertFailsWith { assertThat(iterableOf("one")).any { it.isEqualTo("two") @@ -395,7 +440,8 @@ class IterableTest { } } - @Test fun any_multiple_items_fail() { + @Test + fun any_multiple_items_fail() { val error = assertFailsWith { assertThat(iterableOf(1, 2, 3)).any { it.isEqualTo(4) @@ -411,7 +457,8 @@ class IterableTest { ) } - @Test fun any_with_exception_still_passes() { + @Test + fun any_with_exception_still_passes() { var count = 0 assertThat(iterableOf("one", "two")).any { if (count == 1) { @@ -423,12 +470,14 @@ class IterableTest { //endregion //region isEmpty - @Test fun empty_iterable_passes_is_empty() { + @Test + fun empty_iterable_passes_is_empty() { val empty = emptyIterable() assertThat(empty).isEmpty() } - @Test fun non_empty_iterable_fails_is_empty() { + @Test + fun non_empty_iterable_fails_is_empty() { val nonEmpty = iterableOf(1) val error = assertFailsWith { assertThat(nonEmpty).isEmpty() @@ -438,12 +487,14 @@ class IterableTest { //endregion //region isNotEmpty - @Test fun non_empty_iterable_passes_is_not_empty() { + @Test + fun non_empty_iterable_passes_is_not_empty() { val nonEmpty = iterableOf(1) assertThat(nonEmpty).isNotEmpty() } - @Test fun empty_iterable_fails_is_not_empty() { + @Test + fun empty_iterable_fails_is_not_empty() { val empty = emptyIterable() val error = assertFailsWith { assertThat(empty).isNotEmpty() @@ -453,11 +504,13 @@ class IterableTest { //endregion //region extracting - @Test fun single_extracting_function_passes() { + @Test + fun single_extracting_function_passes() { assertThat(iterableOf("one", "two")).extracting { it.length }.containsExactly(3, 3) } - @Test fun single_extracting_function_fails() { + @Test + fun single_extracting_function_fails() { val error = assertFailsWith { assertThat(iterableOf("one", "two")).extracting { it.length }.containsExactly(2, 2) } @@ -470,13 +523,15 @@ class IterableTest { ) } - @Test fun pair_extracting_function_passes() { + @Test + fun pair_extracting_function_passes() { assertThat(iterableOf(Thing("one", 1, '1'), Thing("two", 2, '2'))) .extracting(Thing::one, Thing::two) .containsExactly("one" to 1, "two" to 2) } - @Test fun pair_extracting_function_fails() { + @Test + fun pair_extracting_function_fails() { val error = assertFailsWith { assertThat(iterableOf(Thing("one", 1, '1'), Thing("two", 2, '2'))) .extracting(Thing::one, Thing::two) @@ -492,13 +547,15 @@ class IterableTest { ) } - @Test fun triple_extracting_function_passes() { + @Test + fun triple_extracting_function_passes() { assertThat(iterableOf(Thing("one", 1, '1'), Thing("two", 2, '2'))) .extracting(Thing::one, Thing::two, Thing::three) .containsExactly(Triple("one", 1, '1'), Triple("two", 2, '2')) } - @Test fun triple_extracting_function_fails() { + @Test + fun triple_extracting_function_fails() { val error = assertFailsWith { assertThat(iterableOf(Thing("one", 1, '1'), Thing("two", 2, '2'))) .extracting(Thing::one, Thing::two, Thing::three) @@ -516,18 +573,21 @@ class IterableTest { //region extracting //region first - @Test fun first_element_present_match_passes() { + @Test + fun first_element_present_match_passes() { assertThat(listOf(1, 2)).first().isEqualTo(1) } - @Test fun first_element_present_mismatch_fails() { + @Test + fun first_element_present_mismatch_fails() { val error = assertFailsWith { assertThat(listOf(1, 2)).first().isEqualTo(2) } assertEquals("expected [first]:<[2]> but was:<[1]> ([1, 2])", error.message) } - @Test fun first_element_missing_fails() { + @Test + fun first_element_missing_fails() { val error = assertFailsWith { assertThat(emptyList()).first().isEqualTo(1) } @@ -536,25 +596,29 @@ class IterableTest { //endregion //region first - @Test fun single_single_element_match_passes() { + @Test + fun single_single_element_match_passes() { assertThat(listOf(1)).single().isEqualTo(1) } - @Test fun single_single_element_mismatch_fails() { + @Test + fun single_single_element_mismatch_fails() { val error = assertFailsWith { assertThat(listOf(1)).single().isEqualTo(2) } assertEquals("expected [single]:<[2]> but was:<[1]> ([1])", error.message) } - @Test fun single_no_element_fails() { + @Test + fun single_no_element_fails() { val error = assertFailsWith { assertThat(emptyList()).single().isEqualTo(1) } assertEquals("expected to have single element but was empty", error.message) } - @Test fun single_multiple_fails() { + @Test + fun single_multiple_fails() { val error = assertFailsWith { assertThat(listOf(1, 2)).single().isEqualTo(1) } diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/ListTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/ListTest.kt index 803a5db7..b8cafb96 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/ListTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/ListTest.kt @@ -9,11 +9,13 @@ import kotlin.test.assertFailsWith class ListTest { //region containsExactly - @Test fun containsExactly_all_elements_in_same_order_passes() { + @Test + fun containsExactly_all_elements_in_same_order_passes() { assertThat(listOf(1, 2)).containsExactly(1, 2) } - @Test fun containsExactly_all_elements_in_different_order_fails() { + @Test + fun containsExactly_all_elements_in_different_order_fails() { val error = assertFailsWith { assertThat(listOf(1, 2)).containsExactly(2, 1) } @@ -26,7 +28,8 @@ class ListTest { } // https://github.com/willowtreeapps/assertk/issues/185 - @Test fun containsExactly_elements_in_different_order_fails2() { + @Test + fun containsExactly_elements_in_different_order_fails2() { val error = assertFailsWith { assertThat(listOf("1", "2", "3")).containsExactly("2", "3", "1") } @@ -38,7 +41,8 @@ class ListTest { ) } - @Test fun containsExactly_same_indexes_are_together() { + @Test + fun containsExactly_same_indexes_are_together() { val error = assertFailsWith { assertThat(listOf(1, 1)).containsExactly(2, 2) } @@ -52,7 +56,8 @@ class ListTest { ) } - @Test fun containsExactly_missing_element_fails() { + @Test + fun containsExactly_missing_element_fails() { val error = assertFailsWith { assertThat(listOf(1, 2)).containsExactly(3) } @@ -65,7 +70,8 @@ class ListTest { ) } - @Test fun containsExactly_extra_element_fails() { + @Test + fun containsExactly_extra_element_fails() { val error = assertFailsWith { assertThat(listOf(1, 2)).containsExactly(1, 2, 3) } @@ -76,7 +82,8 @@ class ListTest { ) } - @Test fun containsExactly_missing_element_in_middle_fails() { + @Test + fun containsExactly_missing_element_in_middle_fails() { val error = assertFailsWith { assertThat(listOf(1, 3)).containsExactly(1, 2, 3) } @@ -87,7 +94,8 @@ class ListTest { ) } - @Test fun containsExactly_extra_element_in_middle_fails() { + @Test + fun containsExactly_extra_element_in_middle_fails() { val error = assertFailsWith { assertThat(listOf(1, 2, 3)).containsExactly(1, 3) } @@ -98,17 +106,20 @@ class ListTest { ) } - @Test fun containsExactly_custom_list_impl_passes() { + @Test + fun containsExactly_custom_list_impl_passes() { assertThat(MyList("one", "two")).containsExactly("one", "two") } //endregion //region index - @Test fun index_successful_assertion_passes() { + @Test + fun index_successful_assertion_passes() { assertThat(listOf("one", "two"), name = "subject").index(0).isEqualTo("one") } - @Test fun index_unsuccessful_assertion_fails() { + @Test + fun index_unsuccessful_assertion_fails() { val error = assertFailsWith { assertThat(listOf("one", "two"), name = "subject").index(0).isEqualTo("wrong") } @@ -118,7 +129,8 @@ class ListTest { ) } - @Test fun index_out_of_range_fails() { + @Test + fun index_out_of_range_fails() { val error = assertFailsWith { assertThat(listOf("one", "two"), name = "subject").index(-1).isEqualTo(listOf("one")) } @@ -127,62 +139,73 @@ class ListTest { //endregion //region containsSubList - @Test fun containsSubList_passes_if_sublist_is_empty_and_actual_is_not_empty() { + @Test + fun containsSubList_passes_if_sublist_is_empty_and_actual_is_not_empty() { val emptySubList: List = emptyList() val actualList: List = listOf("Jason", "Jane", "Anne", "Darius", "Lee") assertThat(actualList).containsSubList(emptySubList) } - @Test fun containsSubList_passes_when_sublist_and_actual_list_is_empty() { + @Test + fun containsSubList_passes_when_sublist_and_actual_list_is_empty() { val sublist: List = emptyList() val actualList: List = emptyList() assertThat(actualList).containsSubList(sublist) } - @Test fun containsSubList_fails_if_sublist_is_contained_in_actual_but_not_in_exact_order() { + @Test + fun containsSubList_fails_if_sublist_is_contained_in_actual_but_not_in_exact_order() { val actualList: List = listOf("John", "Victoria", "Lee-Anne") val sublist: List = listOf("John", "Lee-Anne", "Victoria") val error = assertFailsWith { assertThat(actualList).containsSubList(sublist) } assertEquals( - """expected to contain the exact sublist (in the same order) as:<["John", "Lee-Anne", "Victoria"]>, but found none matching in:<["John", "Victoria", "Lee-Anne"]>""", error.message + """expected to contain the exact sublist (in the same order) as:<["John", "Lee-Anne", "Victoria"]>, but found none matching in:<["John", "Victoria", "Lee-Anne"]>""", + error.message ) } - @Test fun containsSubList_fails_if_sublist_is_contained_in_actual_but_in_reverse_order() { + @Test + fun containsSubList_fails_if_sublist_is_contained_in_actual_but_in_reverse_order() { val actualList: List = listOf("John", "Victoria", "Lee-Anne") val sublist: List = listOf("Lee-Anne", "Victoria", "John") val error = assertFailsWith { assertThat(actualList).containsSubList(sublist) } assertEquals( - """expected to contain the exact sublist (in the same order) as:<["Lee-Anne", "Victoria", "John"]>, but found none matching in:<["John", "Victoria", "Lee-Anne"]>""", error.message + """expected to contain the exact sublist (in the same order) as:<["Lee-Anne", "Victoria", "John"]>, but found none matching in:<["John", "Victoria", "Lee-Anne"]>""", + error.message ) } - @Test fun containsSubList_passes_if_actual_contains_sublist_in_exact_order() { + @Test + fun containsSubList_passes_if_actual_contains_sublist_in_exact_order() { val actualList: List = listOf("John", "Victoria", "Lee-Anne", "Darius", "Victor") val sublist: List = listOf("Victoria", "Lee-Anne", "Darius") assertThat(actualList).containsSubList(sublist) } - @Test fun containsSubList_passes_if_sublist_is_the_head_of_the_list() { + @Test + fun containsSubList_passes_if_sublist_is_the_head_of_the_list() { val actualList: List = listOf("1", "2", null, "4") val sublist: List = listOf("1", "2", null, "4") assertThat(actualList).containsSubList(sublist) } - @Test fun containsSubList_passes_if_sublist_is_the_tail_of_the_list() { + @Test + fun containsSubList_passes_if_sublist_is_the_tail_of_the_list() { val actualList: List = listOf("1", "2", null, "4") val sublist: List = listOf(null, "4") assertThat(actualList).containsSubList(sublist) } - @Test fun containsSubList_passes_if_sublist_is_exactly_the_same_size_and_order() { + @Test + fun containsSubList_passes_if_sublist_is_exactly_the_same_size_and_order() { val actualList: List = listOf(1, 2, 3) - val sublist:List = listOf(1, 2, 3) + val sublist: List = listOf(1, 2, 3) assertThat(actualList).containsSubList(sublist) } - @Test fun containsSubList_passes_if_actual_list_contain_fully_matched_sublist_after_partial_match() { - val sublist: List = listOf("Gordan","Jayce","Ann-Lee") + @Test + fun containsSubList_passes_if_actual_list_contain_fully_matched_sublist_after_partial_match() { + val sublist: List = listOf("Gordan", "Jayce", "Ann-Lee") val partialList: List = listOf("Gordan", "Jayce") val actualList: List = listOf("Andy", "John") + partialList + listOf("Elly") + sublist assertThat(actualList).containsSubList(sublist) @@ -190,12 +213,14 @@ class ListTest { //endregion //region startsWith - @Test fun startsWith_passes_if_values_are_at_the_head_of_the_list() { + @Test + fun startsWith_passes_if_values_are_at_the_head_of_the_list() { val given: List = listOf("Jason", "Jane", "Anne", "Darius", "Lee") assertThat(given).startsWith("Jason", "Jane") } - @Test fun startsWith_fails_if_values_are_not_at_the_head_of_the_list() { + @Test + fun startsWith_fails_if_values_are_not_at_the_head_of_the_list() { val given: List = listOf(1, 2, 3, 4, 5) val error = assertFailsWith { assertThat(given).startsWith(2, 4) @@ -207,7 +232,8 @@ class ListTest { ) } - @Test fun startsWith_fails_if_there_is_not_enough_elements_in_the_list() { + @Test + fun startsWith_fails_if_there_is_not_enough_elements_in_the_list() { val given: List = listOf(1, 2) val error = assertFailsWith { assertThat(given).startsWith(1, 2, 3) @@ -219,24 +245,28 @@ class ListTest { ) } - @Test fun startsWith_fails_if_elements_order_do_not_match() { + @Test + fun startsWith_fails_if_elements_order_do_not_match() { val given: List = listOf("Jason", "Jane", "Anne") assertFailsWith { assertThat(given).startsWith("Jane", "Jason") } } - @Test fun startsWith_pass_if_values_are_equal_to_the_list() { + @Test + fun startsWith_pass_if_values_are_equal_to_the_list() { val given: List = listOf("Jason", "Jane", "Anne") assertThat(given).startsWith("Jason", "Jane", "Anne") } //endregion //region endsWith - @Test fun endsWith_passes_if_values_are_at_the_tail_of_the_list() { + @Test + fun endsWith_passes_if_values_are_at_the_tail_of_the_list() { val given: List = listOf("Jason", "Jane", "Anne", "Darius", "Lee") assertThat(given).endsWith("Darius", "Lee") } - @Test fun endsWith_fails_if_values_are_not_at_the_tail_of_the_list() { + @Test + fun endsWith_fails_if_values_are_not_at_the_tail_of_the_list() { val given: List = listOf(1, 2, 3, 4, 5) val error = assertFailsWith { assertThat(given).endsWith(4, 2) @@ -248,7 +278,8 @@ class ListTest { ) } - @Test fun endsWith_fails_if_there_is_not_enough_elements_in_the_list() { + @Test + fun endsWith_fails_if_there_is_not_enough_elements_in_the_list() { val given: List = listOf(2, 3) val error = assertFailsWith { assertThat(given).endsWith(1, 2, 3) @@ -260,12 +291,14 @@ class ListTest { ) } - @Test fun endsWith_fails_if_elements_order_do_not_match() { + @Test + fun endsWith_fails_if_elements_order_do_not_match() { val given: List = listOf("Jason", "Jane", "Anne") assertFailsWith { assertThat(given).endsWith("Anne", "Jane") } } - @Test fun endsWith_pass_if_values_are_equal_to_the_list() { + @Test + fun endsWith_pass_if_values_are_equal_to_the_list() { val given: List = listOf("Jason", "Jane", "Anne") assertThat(given).endsWith("Jason", "Jane", "Anne") } diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/MapTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/MapTest.kt index 601c0139..39184ca4 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/MapTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/MapTest.kt @@ -8,18 +8,21 @@ import kotlin.test.assertFailsWith class MapTest { //region contains - @Test fun contains_element_present_passes() { + @Test + fun contains_element_present_passes() { assertThat(mapOf("one" to 1, "two" to 2)).contains("two" to 2) } - @Test fun contains_element_missing_fails() { + @Test + fun contains_element_missing_fails() { val error = assertFailsWith { assertThat(emptyMap()).contains("one" to 1) } assertEquals("expected to contain:<{\"one\"=1}> but was:<{}>", error.message) } - @Test fun contains_element_with_nullable_value_missing_fails() { + @Test + fun contains_element_with_nullable_value_missing_fails() { val error = assertFailsWith { assertThat(emptyMap()).contains("one" to null) } @@ -28,26 +31,31 @@ class MapTest { //endregion //region doesNotContain - @Test fun doesNotContain_element_missing_passes() { + @Test + fun doesNotContain_element_missing_passes() { assertThat(emptyMap()).doesNotContain("one" to 1) } - @Test fun doesNotContain_element_with_missing_nullable_value_passes() { + @Test + fun doesNotContain_element_with_missing_nullable_value_passes() { assertThat(emptyMap()).doesNotContain("one" to null) } - @Test fun doesNotContain_element_present_fails() { + @Test + fun doesNotContain_element_present_fails() { val error = assertFailsWith { assertThat(mapOf("one" to 1, "two" to 2)).doesNotContain("two" to 2) } assertEquals("expected to not contain:<{\"two\"=2}> but was:<{\"one\"=1, \"two\"=2}>", error.message) } - @Test fun doesNotContainKey_key_missing_passes() { + @Test + fun doesNotContainKey_key_missing_passes() { assertThat(emptyMap()).doesNotContainKey("one") } - @Test fun doesNotContainKey_key_present_fails() { + @Test + fun doesNotContainKey_key_present_fails() { val error = assertFailsWith { assertThat(mapOf("one" to 1)).doesNotContainKey("one") } @@ -57,15 +65,18 @@ class MapTest { //endregion //region containsNone - @Test fun containsNone_missing_elements_passes() { + @Test + fun containsNone_missing_elements_passes() { assertThat(emptyMap()).containsNone("one" to 1) } - @Test fun containsNone_missing_elements_with_nullable_value_passes() { + @Test + fun containsNone_missing_elements_with_nullable_value_passes() { assertThat(emptyMap()).containsNone("one" to null) } - @Test fun containsNone_present_element_fails() { + @Test + fun containsNone_present_element_fails() { val error = assertFailsWith { assertThat(mapOf("one" to 1, "two" to 2)).containsNone("two" to 2, "three" to 3) } @@ -79,38 +90,43 @@ class MapTest { //region //region containsAtLeast - @Test fun containsAtLeast_all_elements_passes() { + @Test + fun containsAtLeast_all_elements_passes() { assertThat(mapOf("one" to 1, "two" to 2)).containsAtLeast("two" to 2, "one" to 1) } - @Test fun containsAtLeast_extra_elements_passes() { + @Test + fun containsAtLeast_extra_elements_passes() { assertThat(mapOf("one" to 1, "two" to 2, "three" to 3)).containsAtLeast("one" to 1, "two" to 2) } - @Test fun containsAtLeast_swapped_keys_and_values_fails() { + @Test + fun containsAtLeast_swapped_keys_and_values_fails() { val error = assertFailsWith { assertThat(mapOf("one" to 2, "two" to 1)).containsAtLeast("two" to 2, "one" to 1) } assertEquals( - """expected to contain all:<{"two"=2, "one"=1}> but was:<{"one"=2, "two"=1}> + """expected to contain all:<{"two"=2, "one"=1}> but was:<{"one"=2, "two"=1}> | elements not found:<{"two"=2, "one"=1}> """.trimMargin(), error.message ) } - @Test fun containsAtLeast_nullable_values_fails() { + @Test + fun containsAtLeast_nullable_values_fails() { val error = assertFailsWith { assertThat(mapOf()).containsAtLeast("key" to null) } assertEquals( - """expected to contain all:<{"key"=null}> but was:<{}> + """expected to contain all:<{"key"=null}> but was:<{}> | elements not found:<{"key"=null}> """.trimMargin(), error.message ) } - @Test fun containsAtLeast_some_elements_fails() { + @Test + fun containsAtLeast_some_elements_fails() { val error = assertFailsWith { assertThat(mapOf("one" to 1)).containsAtLeast("one" to 1, "two" to 2) } @@ -124,24 +140,27 @@ class MapTest { //endregion //region containsOnly - @Test fun containsOnly_all_elements_passes() { + @Test + fun containsOnly_all_elements_passes() { assertThat(mapOf("one" to 1, "two" to 2)).containsOnly("two" to 2, "one" to 1) } - @Test fun containsOnly_swapped_keys_and_values_fails() { + @Test + fun containsOnly_swapped_keys_and_values_fails() { val error = assertFailsWith { assertThat(mapOf("one" to 2, "two" to 1)).containsOnly("two" to 2, "one" to 1) } assertEquals( - """expected to contain only:<{"two"=2, "one"=1}> but was:<{"one"=2, "two"=1}> + """expected to contain only:<{"two"=2, "one"=1}> but was:<{"one"=2, "two"=1}> | elements not found:<{"two"=2, "one"=1}> | extra elements found:<{"one"=2, "two"=1}> """.trimMargin(), error.message ) } - @Test fun containsOnly_missing_element_fails() { + @Test + fun containsOnly_missing_element_fails() { val error = assertFailsWith { assertThat(mapOf("one" to 1, "two" to 2)).containsOnly("three" to 3) } @@ -153,7 +172,8 @@ class MapTest { ) } - @Test fun containsOnly_extra_element_fails() { + @Test + fun containsOnly_extra_element_fails() { val error = assertFailsWith { assertThat(mapOf("one" to 1, "two" to 2)).containsOnly("one" to 1) } @@ -166,11 +186,13 @@ class MapTest { //endregion //region isEmpty - @Test fun isEmpty_empty_passes() { + @Test + fun isEmpty_empty_passes() { assertThat(emptyMap()).isEmpty() } - @Test fun isEmpty_non_empty_fails() { + @Test + fun isEmpty_non_empty_fails() { val error = assertFailsWith { assertThat(mapOf(null to null)).isEmpty() } @@ -179,11 +201,13 @@ class MapTest { //endregion //region isNotEmpty - @Test fun isNotEmpty_non_empty_passes() { + @Test + fun isNotEmpty_non_empty_passes() { assertThat(mapOf(null to null)).isNotEmpty() } - @Test fun isNotEmpty_empty_fails() { + @Test + fun isNotEmpty_empty_fails() { val error = assertFailsWith { assertThat(mapOf()).isNotEmpty() } @@ -192,15 +216,18 @@ class MapTest { //endregion //region isNullOrEmpty - @Test fun isNullOrEmpty_null_passes() { + @Test + fun isNullOrEmpty_null_passes() { assertThat(null as Map?).isNullOrEmpty() } - @Test fun isNullOrEmpty_empty_passes() { + @Test + fun isNullOrEmpty_empty_passes() { assertThat(emptyMap()).isNullOrEmpty() } - @Test fun isNullOrEmpty_non_empty_fails() { + @Test + fun isNullOrEmpty_non_empty_fails() { val error = assertFailsWith { assertThat(mapOf(null to null)).isNullOrEmpty() } @@ -209,11 +236,13 @@ class MapTest { //endregion //region hasSize - @Test fun hasSize_correct_size_passes() { + @Test + fun hasSize_correct_size_passes() { assertThat(emptyMap()).hasSize(0) } - @Test fun hasSize_wrong_size_fails() { + @Test + fun hasSize_wrong_size_fails() { val error = assertFailsWith { assertThat(emptyMap()).hasSize(1) } @@ -222,11 +251,13 @@ class MapTest { //endregion //region hasSameSizeAs - @Test fun hasSameSizeAs_equal_sizes_passes() { + @Test + fun hasSameSizeAs_equal_sizes_passes() { assertThat(emptyMap()).hasSameSizeAs(emptyMap()) } - @Test fun hasSameSizeAs_non_equal_sizes_fails() { + @Test + fun hasSameSizeAs_non_equal_sizes_fails() { val error = assertFailsWith { assertThat(emptyMap()).hasSameSizeAs(mapOf("one" to 1)) } @@ -235,18 +266,21 @@ class MapTest { //endregion //region key - @Test fun index_successful_assertion_passes() { + @Test + fun index_successful_assertion_passes() { assertThat(mapOf("one" to 1, "two" to 2), name = "subject").key("one").isEqualTo(1) } - @Test fun index_unsuccessful_assertion_fails() { + @Test + fun index_unsuccessful_assertion_fails() { val error = assertFailsWith { assertThat(mapOf("one" to 1, "two" to 2), name = "subject").key("one").isEqualTo(2) } assertEquals("expected [subject[\"one\"]]:<[2]> but was:<[1]> ({\"one\"=1, \"two\"=2})", error.message) } - @Test fun index_missing_key_fails() { + @Test + fun index_missing_key_fails() { val error = assertFailsWith { assertThat(mapOf("one" to 1, "two" to 2), name = "subject").key("wrong").isEqualTo(1) } diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/NumberTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/NumberTest.kt index b96da52f..188a8f34 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/NumberTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/NumberTest.kt @@ -9,11 +9,13 @@ import kotlin.test.assertFailsWith class NumberTest { //region isZero - @Test fun isZero_value_zero_passes() { + @Test + fun isZero_value_zero_passes() { assertThat(0).isZero() } - @Test fun isZero_value_non_zero_fails() { + @Test + fun isZero_value_non_zero_fails() { val error = assertFailsWith { assertThat(1).isZero() } @@ -22,11 +24,13 @@ class NumberTest { //endregion //region isNonZero - @Test fun isNonZero_value_non_zero_passes() { + @Test + fun isNonZero_value_non_zero_passes() { assertThat(1).isNotZero() } - @Test fun isNonZero_value_zero_fails() { + @Test + fun isNonZero_value_zero_fails() { val error = assertFailsWith { assertThat(0).isNotZero() } @@ -35,18 +39,21 @@ class NumberTest { //endregion //region isPositive - @Test fun isPositive_value_positive_passes() { + @Test + fun isPositive_value_positive_passes() { assertThat(1).isPositive() } - @Test fun isPositive_value_zero_fails() { + @Test + fun isPositive_value_zero_fails() { val error = assertFailsWith { assertThat(0).isPositive() } assertEquals("expected to be positive but was:<0>", error.message) } - @Test fun isPositive_value_negative_fails() { + @Test + fun isPositive_value_negative_fails() { val error = assertFailsWith { assertThat(-1).isPositive() } @@ -55,18 +62,21 @@ class NumberTest { //endregion //region isNegative - @Test fun isNegative_value_negative_passes() { + @Test + fun isNegative_value_negative_passes() { assertThat(-1).isNegative() } - @Test fun isNegative_value_zero_fails() { + @Test + fun isNegative_value_zero_fails() { val error = assertFailsWith { assertThat(0).isNegative() } assertEquals("expected to be negative but was:<0>", error.message) } - @Test fun isNegative_value_positive_fails() { + @Test + fun isNegative_value_positive_fails() { val error = assertFailsWith { assertThat(1).isNegative() } @@ -75,7 +85,8 @@ class NumberTest { //endregion //region isEqualTo - @Test fun isEqualTo_number_literal_is_inferred_based_on_type() { + @Test + fun isEqualTo_number_literal_is_inferred_based_on_type() { assertThat(1.toByte()).isEqualTo(1) assertThat(1.toShort()).isEqualTo(1) assertThat(1).isEqualTo(1) diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/PredicateTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/PredicateTest.kt index 3f7de6b8..2de3078d 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/PredicateTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/PredicateTest.kt @@ -8,13 +8,15 @@ import kotlin.test.assertFailsWith class PredicateTest { - @Test fun matchesPredicate_true_predicate_passes() { + @Test + fun matchesPredicate_true_predicate_passes() { val divisibleBy5: (Int) -> Boolean = { it % 5 == 0 } assertThat(10).matchesPredicate(divisibleBy5) } - @Test fun matchesPredicate_false_predicate_fails() { + @Test + fun matchesPredicate_false_predicate_fails() { val divisibleBy5: (Int) -> Boolean = { it % 5 == 0 } val error = assertFailsWith { assertThat(6).matchesPredicate(divisibleBy5) } diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/ResultTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/ResultTest.kt index 7606c4e9..bdbd3561 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/ResultTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/ResultTest.kt @@ -12,15 +12,18 @@ import kotlin.test.assertFailsWith class ResultTest { // region success - @Test fun success_passes() { + @Test + fun success_passes() { assertThat(Result.success(1)).isSuccess() } - @Test fun success_on_null_passed() { + @Test + fun success_on_null_passed() { assertThat(Result.success(null)).isSuccess() } - @Test fun success_fails() { + @Test + fun success_fails() { val error = assertFailsWith { assertThat(Result.failure(Exception("error"))).isSuccess() } @@ -30,11 +33,13 @@ class ResultTest { ) } - @Test fun chained_success_passes() { + @Test + fun chained_success_passes() { assertThat(Result.success(1)).isSuccess().isEqualTo(1) } - @Test fun chained_success_fails() { + @Test + fun chained_success_fails() { val error = assertFailsWith { assertThat(Result.success(1)).isSuccess().isEqualTo(2) } @@ -43,22 +48,26 @@ class ResultTest { //endregion //region failure - @Test fun failure_passes() { + @Test + fun failure_passes() { assertThat(Result.failure(Exception("error"))).isFailure() } - @Test fun failure_fails() { + @Test + fun failure_fails() { val error = assertFailsWith { assertThat(Result.success(1)).isFailure() } assertEquals("expected failure but was success:<1>", error.message) } - @Test fun chained_failure_passes() { + @Test + fun chained_failure_passes() { assertThat(Result.failure(Exception("error"))).isFailure().hasMessage("error") } - @Test fun chained_failure_fails() { + @Test + fun chained_failure_fails() { val error = assertFailsWith { assertThat(Result.failure(Exception("error"))).isFailure().hasMessage("wrong") } diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/SequenceTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/SequenceTest.kt index b12e03c2..6c1bd108 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/SequenceTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/SequenceTest.kt @@ -29,15 +29,18 @@ import kotlin.test.assertFailsWith class SequenceTest { //region contains - @Test fun contains_element_present_passes() { + @Test + fun contains_element_present_passes() { assertThat(sequenceOf(1, 2, 3)).contains(2) } - @Test fun contains_oneshot_passes() { + @Test + fun contains_oneshot_passes() { assertThat(oneshotSequenceOf(1, 2, 3)).contains(2) } - @Test fun contains_element_missing_fails() { + @Test + fun contains_element_missing_fails() { val error = assertFailsWith { assertThat(emptySequence()).contains(1) } @@ -46,18 +49,21 @@ class SequenceTest { //endregion //region doesNotContain - @Test fun doesNotContain_element_missing_passes() { + @Test + fun doesNotContain_element_missing_passes() { assertThat(emptySequence()).doesNotContain(1) } - @Test fun doesNotContain_element_present_fails() { + @Test + fun doesNotContain_element_present_fails() { val error = assertFailsWith { assertThat(sequenceOf(1, 2, 3)).doesNotContain(2) } assertEquals("expected to not contain:<2> but was:<[1, 2, 3]>", error.message) } - @Test fun doesNotContain_oneshot_fails() { + @Test + fun doesNotContain_oneshot_fails() { val error = assertFailsWith { assertThat(oneshotSequenceOf(1, 2, 3)).doesNotContain(2) } @@ -66,11 +72,13 @@ class SequenceTest { //endregion //region containsNone - @Test fun containsNone_missing_elements_passes() { + @Test + fun containsNone_missing_elements_passes() { assertThat(emptySequence()).containsNone(1) } - @Test fun containsNone_present_element_fails() { + @Test + fun containsNone_present_element_fails() { val error = assertFailsWith { assertThat(sequenceOf(1, 2)).containsNone(2, 3) } @@ -81,7 +89,8 @@ class SequenceTest { ) } - @Test fun containsNone_oneshot_fails() { + @Test + fun containsNone_oneshot_fails() { val error = assertFailsWith { assertThat(oneshotSequenceOf(1, 2)).containsNone(2, 3) } @@ -95,15 +104,18 @@ class SequenceTest { //region //region containsAtLeast - @Test fun containsAtLeast_all_elements_passes() { + @Test + fun containsAtLeast_all_elements_passes() { assertThat(sequenceOf(1, 2)).containsAtLeast(2, 1) } - @Test fun containsAtLeast_oneshot_passes() { + @Test + fun containsAtLeast_oneshot_passes() { assertThat(oneshotSequenceOf(1, 2)).containsAtLeast(2, 1) } - @Test fun containsAtLeast_some_elements_fails() { + @Test + fun containsAtLeast_some_elements_fails() { val error = assertFailsWith { assertThat(sequenceOf(1)).containsAtLeast(1, 2) } @@ -116,23 +128,28 @@ class SequenceTest { //endregion //region containsOnly - @Test fun containsOnly_only_elements_passes() { + @Test + fun containsOnly_only_elements_passes() { assertThat(sequenceOf(1, 2)).containsOnly(2, 1) } - @Test fun containsOnly_duplicate_elements_passes() { + @Test + fun containsOnly_duplicate_elements_passes() { assertThat(sequenceOf(1, 2, 2)).containsOnly(2, 1) } - @Test fun containsOnly_duplicate_elements_passes2() { + @Test + fun containsOnly_duplicate_elements_passes2() { assertThat(sequenceOf(1, 2)).containsOnly(2, 2, 1) } - @Test fun containsOnly_oneshot_passes() { + @Test + fun containsOnly_oneshot_passes() { assertThat(oneshotSequenceOf(1, 2)).containsOnly(2, 1) } - @Test fun containsOnly_more_elements_fails() { + @Test + fun containsOnly_more_elements_fails() { val error = assertFailsWith { assertThat(sequenceOf(1, 2, 3)).containsOnly(2, 1) } @@ -143,7 +160,8 @@ class SequenceTest { ) } - @Test fun containsOnly_less_elements_fails() { + @Test + fun containsOnly_less_elements_fails() { val error = assertFailsWith { assertThat(sequenceOf(1, 2, 3)).containsOnly(2, 1, 3, 4) } @@ -155,7 +173,8 @@ class SequenceTest { ) } - @Test fun containsOnly_different_elements_fails() { + @Test + fun containsOnly_different_elements_fails() { val error = assertFailsWith { assertThat(sequenceOf(1)).containsOnly(2) } @@ -168,7 +187,8 @@ class SequenceTest { ) } - @Test fun containsOnly_oneshot_fails() { + @Test + fun containsOnly_oneshot_fails() { val error = assertFailsWith { assertThat(oneshotSequenceOf(1, 2, 3)).containsOnly(2, 1) } @@ -181,19 +201,23 @@ class SequenceTest { //endregion //region containsExactlyInAnyOrder - @Test fun containsExactlyInAnyOrder_only_elements_passes() { + @Test + fun containsExactlyInAnyOrder_only_elements_passes() { assertThat(sequenceOf(1, 2)).containsExactlyInAnyOrder(2, 1) } - @Test fun containsExactlyInAnyOrder_only_elements_passes2() { + @Test + fun containsExactlyInAnyOrder_only_elements_passes2() { assertThat(sequenceOf(1, 2, 1)).containsExactlyInAnyOrder(2, 1, 1) } - @Test fun containsExactlyInAnyOrder_oneshot_passes() { + @Test + fun containsExactlyInAnyOrder_oneshot_passes() { assertThat(oneshotSequenceOf(1, 2)).containsExactlyInAnyOrder(2, 1) } - @Test fun containsExactlyInAnyOrder_duplicate_elements_fails() { + @Test + fun containsExactlyInAnyOrder_duplicate_elements_fails() { val error = assertFailsWith { assertThat(sequenceOf(1, 2, 2)).containsExactlyInAnyOrder(2, 1) } @@ -204,7 +228,8 @@ class SequenceTest { ) } - @Test fun containsExactlyInAnyOrder_duplicate_elements_fails2() { + @Test + fun containsExactlyInAnyOrder_duplicate_elements_fails2() { val error = assertFailsWith { assertThat(sequenceOf(1, 2)).containsExactlyInAnyOrder(2, 2, 1) } @@ -215,7 +240,8 @@ class SequenceTest { ) } - @Test fun containsExactlyInAnyOrder_more_elements_fails() { + @Test + fun containsExactlyInAnyOrder_more_elements_fails() { val error = assertFailsWith { assertThat(sequenceOf(1, 2, 3)).containsExactlyInAnyOrder(2, 1) } @@ -226,7 +252,8 @@ class SequenceTest { ) } - @Test fun containsExactlyInAnyOrder_less_elements_fails() { + @Test + fun containsExactlyInAnyOrder_less_elements_fails() { val error = assertFailsWith { assertThat(sequenceOf(1, 2, 3)).containsExactlyInAnyOrder(2, 1, 3, 4) } @@ -238,7 +265,8 @@ class SequenceTest { ) } - @Test fun containsExactlyInAnyOrder_different_elements_fails() { + @Test + fun containsExactlyInAnyOrder_different_elements_fails() { val error = assertFailsWith { assertThat(sequenceOf(1)).containsExactlyInAnyOrder(2) } @@ -251,7 +279,8 @@ class SequenceTest { ) } - @Test fun containsExactlyInAnyOrder_oneshot_fails() { + @Test + fun containsExactlyInAnyOrder_oneshot_fails() { val error = assertFailsWith { assertThat(oneshotSequenceOf(1, 2, 2)).containsExactlyInAnyOrder(2, 1) } @@ -264,19 +293,23 @@ class SequenceTest { //endregion //region each - @Test fun each_empty_list_passes() { + @Test + fun each_empty_list_passes() { assertThat(emptySequence()).each { it.isEqualTo(1) } } - @Test fun each_content_passes() { + @Test + fun each_content_passes() { assertThat(sequenceOf(1, 2)).each { it.isGreaterThan(0) } } - @Test fun each_oneshot_passes() { + @Test + fun each_oneshot_passes() { assertThat(oneshotSequenceOf(1, 2)).each { it.isGreaterThan(0) } } - @Test fun each_non_matching_content_fails() { + @Test + fun each_non_matching_content_fails() { val error = assertFailsWith { assertThat(sequenceOf(1, 2, 3)).each { it.isLessThan(2) } } @@ -290,11 +323,13 @@ class SequenceTest { //endregion //region none - @Test fun none_empty_list_passes() { + @Test + fun none_empty_list_passes() { assertThat(emptySequence()).none { it.isEqualTo(1) } } - @Test fun none_matching_content_fails() { + @Test + fun none_matching_content_fails() { val error = assertFailsWith { assertThat(sequenceOf(1, 2)).none { it.isGreaterThan(0) } } @@ -306,7 +341,8 @@ class SequenceTest { ) } - @Test fun none_matching_some_content_fails() { + @Test + fun none_matching_some_content_fails() { val error = assertFailsWith { assertThat(sequenceOf(1, 2, 3)).none { it.isGreaterThanOrEqualTo(3) } } @@ -317,11 +353,13 @@ class SequenceTest { ) } - @Test fun none_all_non_matching_content_passes() { + @Test + fun none_all_non_matching_content_passes() { assertThat(sequenceOf(1, 2, 3)).none { it.isLessThan(0) } } - @Test fun none_multiple_failures_passes() { + @Test + fun none_multiple_failures_passes() { assertThat(sequenceOf(1, 2, 3)).none { it.isLessThan(2) it.isGreaterThan(2) @@ -330,7 +368,8 @@ class SequenceTest { //endregion //region atLeast - @Test fun atLeast_too_many_failures_fails() { + @Test + fun atLeast_too_many_failures_fails() { val error = assertFailsWith { assertThat(sequenceOf(1, 2, 3)).atLeast(2) { it.isGreaterThan(2) } } @@ -342,21 +381,25 @@ class SequenceTest { ) } - @Test fun atLeast_no_failures_passes() { + @Test + fun atLeast_no_failures_passes() { assertThat(sequenceOf(1, 2, 3)).atLeast(2) { it.isGreaterThan(0) } } - @Test fun atLeast_less_than_times_failures_passes() { + @Test + fun atLeast_less_than_times_failures_passes() { assertThat(sequenceOf(1, 2, 3)).atLeast(2) { it.isGreaterThan(1) } } - @Test fun atLeast_works_in_a_soft_assert_context() { + @Test + fun atLeast_works_in_a_soft_assert_context() { assertThat(sequenceOf(1, 2, 3)).all { atLeast(2) { it.isGreaterThan(1) } } } //endregion //region atMost - @Test fun atMost_more_than_times_passed_fails() { + @Test + fun atMost_more_than_times_passed_fails() { val error = assertFailsWith { assertThat(sequenceOf(1, 2, 3)).atMost(2) { it.isGreaterThan(0) } } @@ -365,19 +408,22 @@ class SequenceTest { ) } - @Test fun atMost_exactly_times_passed_passes() { + @Test + fun atMost_exactly_times_passed_passes() { assertThat(sequenceOf(1, 2, 3)).atMost(2) { it.isGreaterThan(1) } } - @Test fun atMost_less_than_times_passed_passes() { + @Test + fun atMost_less_than_times_passed_passes() { assertThat(sequenceOf(1, 2)).atMost(2) { it.isGreaterThan(1) } } //endregion //region exactly - @Test fun exactly_too_few_passes_fails() { + @Test + fun exactly_too_few_passes_fails() { val error = assertFailsWith { assertThat(sequenceOf(1, 2, 3)).exactly(2) { it.isGreaterThan(2) } } @@ -389,7 +435,8 @@ class SequenceTest { ) } - @Test fun exactly_too_many_passes_fails() { + @Test + fun exactly_too_many_passes_fails() { val error = assertFailsWith { assertThat(sequenceOf(5, 4, 3)).exactly(2) { it.isGreaterThan(2) } } @@ -398,7 +445,8 @@ class SequenceTest { ) } - @Test fun exactly_too_few_inside_all_fails() { + @Test + fun exactly_too_few_inside_all_fails() { val error = assertFailsWith { assertThat(sequenceOf(5, 4, 3)).all { exactly(2) { it.isGreaterThan(2) } @@ -409,17 +457,20 @@ class SequenceTest { ) } - @Test fun exactly_times_passed_passes() { + @Test + fun exactly_times_passed_passes() { assertThat(sequenceOf(0, 1, 2)).exactly(2) { it.isGreaterThan(0) } } //endregion //region any - @Test fun any_passes_if_one_item_passes() { + @Test + fun any_passes_if_one_item_passes() { assertThat(sequenceOf(1, 2)).any { it.isGreaterThan(1) } } - @Test fun any_fails_if_all_fail() { + @Test + fun any_fails_if_all_fail() { val error = assertFailsWith { assertThat(sequenceOf(1, 2)).any { it.isGreaterThan(3) } } @@ -431,7 +482,8 @@ class SequenceTest { ) } - @Test fun any_multiple_assertions_fail() { + @Test + fun any_multiple_assertions_fail() { assertFailsWith { assertThat(sequenceOf("one")).any { it.isEqualTo("two") @@ -440,7 +492,8 @@ class SequenceTest { } } - @Test fun any_multiple_items_fail() { + @Test + fun any_multiple_items_fail() { val error = assertFailsWith { assertThat(sequenceOf(1, 2, 3)).any { it.isEqualTo(4) @@ -456,7 +509,8 @@ class SequenceTest { ) } - @Test fun any_with_exception_still_passes() { + @Test + fun any_with_exception_still_passes() { var count = 0 assertThat(sequenceOf("one", "two")).any { if (count == 1) { @@ -468,17 +522,20 @@ class SequenceTest { //endregion //region isEmpty - @Test fun isEmpty_empty_passes() { + @Test + fun isEmpty_empty_passes() { val empty = emptySequence() assertThat(empty).isEmpty() } - @Test fun isEmpty_oneshot_passes() { + @Test + fun isEmpty_oneshot_passes() { val empty = oneshotSequenceOf() assertThat(empty).isEmpty() } - @Test fun isEmpty_non_empty_fails() { + @Test + fun isEmpty_non_empty_fails() { val nonEmpty = sequenceOf(1) val error = assertFailsWith { assertThat(nonEmpty).isEmpty() @@ -486,7 +543,8 @@ class SequenceTest { assertEquals("expected to be empty but was:<[1]>", error.message) } - @Test fun isEmpty_oneshot_fails() { + @Test + fun isEmpty_oneshot_fails() { val nonEmpty = oneshotSequenceOf(1) val error = assertFailsWith { assertThat(nonEmpty).isEmpty() @@ -496,17 +554,20 @@ class SequenceTest { //endregion //region isNotEmpty - @Test fun isNotEmpty_non_empty_passes() { + @Test + fun isNotEmpty_non_empty_passes() { val nonEmpty = sequenceOf(1) assertThat(nonEmpty).isNotEmpty() } - @Test fun isNotEmpty_oneshot_passes() { + @Test + fun isNotEmpty_oneshot_passes() { val nonEmpty = oneshotSequenceOf(1) assertThat(nonEmpty).isNotEmpty() } - @Test fun isNotEmpty_empty_fails() { + @Test + fun isNotEmpty_empty_fails() { val empty = emptySequence() val error = assertFailsWith { assertThat(empty).isNotEmpty() @@ -514,7 +575,8 @@ class SequenceTest { assertEquals("expected to not be empty", error.message) } - @Test fun isNotEmpty_oneshot_fails() { + @Test + fun isNotEmpty_oneshot_fails() { val empty = oneshotSequenceOf() val error = assertFailsWith { assertThat(empty).isNotEmpty() @@ -524,12 +586,14 @@ class SequenceTest { //endregion //region extracting - @Test fun single_extracting_function_passes() { + @Test + fun single_extracting_function_passes() { assertThat(sequenceOf("one", "two")).extracting { it.length } .containsOnly(3, 3) } - @Test fun single_extracting_function_fails() { + @Test + fun single_extracting_function_fails() { val error = assertFailsWith { assertThat(sequenceOf("one", "two")).extracting { it.length }.containsExactly(2, 2) } @@ -542,13 +606,15 @@ class SequenceTest { ) } - @Test fun pair_extracting_function_passes() { + @Test + fun pair_extracting_function_passes() { assertThat(sequenceOf(Thing("one", 1, '1'), Thing("two", 2, '2'))) .extracting(Thing::one, Thing::two) .containsExactly("one" to 1, "two" to 2) } - @Test fun pair_extracting_function_fails() { + @Test + fun pair_extracting_function_fails() { val error = assertFailsWith { assertThat(sequenceOf(Thing("one", 1, '1'), Thing("two", 2, '2'))) .extracting(Thing::one, Thing::two) @@ -564,13 +630,15 @@ class SequenceTest { ) } - @Test fun triple_extracting_function_passes() { + @Test + fun triple_extracting_function_passes() { assertThat(sequenceOf(Thing("one", 1, '1'), Thing("two", 2, '2'))) .extracting(Thing::one, Thing::two, Thing::three) .containsExactly(Triple("one", 1, '1'), Triple("two", 2, '2')) } - @Test fun triple_extracting_function_fails() { + @Test + fun triple_extracting_function_fails() { val error = assertFailsWith { assertThat(sequenceOf(Thing("one", 1, '1'), Thing("two", 2, '2'))) .extracting(Thing::one, Thing::two, Thing::three) diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/ThrowableTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/ThrowableTest.kt index 58a96e37..008cc9bd 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/ThrowableTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/ThrowableTest.kt @@ -12,24 +12,29 @@ class ThrowableTest { val cause = Exception("cause", rootCause) val subject = Exception("test", cause) - @Test fun extracts_message() { + @Test + fun extracts_message() { assertEquals(subject.message, assertThat(subject).message().valueOrFail) } - @Test fun extracts_cause() { + @Test + fun extracts_cause() { assertEquals(cause, assertThat(subject).cause().valueOrFail) } - @Test fun extracts_root_cause() { + @Test + fun extracts_root_cause() { assertEquals(rootCause, assertThat(subject).rootCause().valueOrFail) } //region hasMessage - @Test fun hasMessage_same_message_passes() { + @Test + fun hasMessage_same_message_passes() { assertThat(subject).hasMessage("test") } - @Test fun hasMessage_different_message_fails() { + @Test + fun hasMessage_different_message_fails() { val error = assertFailsWith { assertThat(subject).hasMessage("not test") } @@ -38,11 +43,13 @@ class ThrowableTest { //endregion //region messageContains - @Test fun messageContains_similar_message_passes() { + @Test + fun messageContains_similar_message_passes() { assertThat(subject).messageContains("es") } - @Test fun messageContains_different_message_fails() { + @Test + fun messageContains_different_message_fails() { val error = assertFailsWith { assertThat(subject).messageContains("not") } @@ -52,11 +59,13 @@ class ThrowableTest { //endregion //region hasCause - @Test fun hasCause_same_type_and_message_passes() { + @Test + fun hasCause_same_type_and_message_passes() { assertThat(subject).hasCause(Exception("cause")) } - @Test fun hasCause_no_cause_fails() { + @Test + fun hasCause_no_cause_fails() { val causeless = Exception("test") val error = assertFailsWith { assertThat(causeless).hasCause(cause) @@ -67,7 +76,8 @@ class ThrowableTest { ) } - @Test fun hasCause_different_message_fails() { + @Test + fun hasCause_different_message_fails() { val wrongCause = Exception("wrong") val error = assertFailsWith { assertThat(subject).hasCause(wrongCause) @@ -78,7 +88,8 @@ class ThrowableTest { ) } - @Test fun hasCause_different_type_fails() { + @Test + fun hasCause_different_type_fails() { val wrongCause = IllegalArgumentException("cause") val error = assertFailsWith { assertThat(subject).hasCause(wrongCause) @@ -91,12 +102,14 @@ class ThrowableTest { //endregion //region hasNoCause - @Test fun hasNoCause_no_cause_passes() { + @Test + fun hasNoCause_no_cause_passes() { val causeless = Exception("test") assertThat(causeless).hasNoCause() } - @Test fun hasNoCause_cause_fails() { + @Test + fun hasNoCause_cause_fails() { val error = assertFailsWith { assertThat(subject).hasNoCause() } @@ -105,11 +118,13 @@ class ThrowableTest { //endregion //region hasRootCause - @Test fun hasRootCause_same_root_cause_type_and_message_passes() { + @Test + fun hasRootCause_same_root_cause_type_and_message_passes() { assertThat(subject).hasRootCause(Exception("rootCause")) } - @Test fun hasRootCause_wrong_cause_type_fails() { + @Test + fun hasRootCause_wrong_cause_type_fails() { val wrongCause = IllegalArgumentException("rootCause") val error = assertFailsWith { assertThat(subject).hasRootCause(wrongCause) @@ -120,7 +135,8 @@ class ThrowableTest { ) } - @Test fun hasRootCause_wrong_cause_message_fails() { + @Test + fun hasRootCause_wrong_cause_message_fails() { val wrongCause = Exception("wrong") val error = assertFailsWith { assertThat(subject).hasRootCause(wrongCause) diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/support/ListDifferTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/support/ListDifferTest.kt index 6c43c68d..b1a2162a 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/support/ListDifferTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/support/ListDifferTest.kt @@ -5,31 +5,36 @@ import kotlin.test.Test import kotlin.test.assertEquals class ListDifferTest { - @Test fun empty_diff() { + @Test + fun empty_diff() { val diff = ListDiffer.diff(emptyList(), emptyList()) assertEquals(emptyList(), diff) } - @Test fun single_item_no_change() { + @Test + fun single_item_no_change() { val diff = ListDiffer.diff(listOf(1), listOf(1)) assertEquals(listOf(ListDiffer.Edit.Eq(oldIndex = 0, oldValue = 1, newIndex = 0, newValue = 1)), diff) } - @Test fun singe_insert() { + @Test + fun singe_insert() { val diff = ListDiffer.diff(emptyList(), listOf(1)) assertEquals(listOf(ListDiffer.Edit.Ins(newIndex = 0, newValue = 1)), diff) } - @Test fun singe_delete() { + @Test + fun singe_delete() { val diff = ListDiffer.diff(listOf(1), emptyList()) assertEquals(listOf(ListDiffer.Edit.Del(oldIndex = 0, oldValue = 1)), diff) } - @Test fun single_insert_middle() { + @Test + fun single_insert_middle() { val diff = ListDiffer.diff(listOf(1, 3), listOf(1, 2, 3)) assertEquals( @@ -41,7 +46,8 @@ class ListDifferTest { ) } - @Test fun singe_delete_middle() { + @Test + fun singe_delete_middle() { val diff = ListDiffer.diff(listOf(1, 2, 3), listOf(1, 3)) assertEquals( @@ -53,7 +59,8 @@ class ListDifferTest { ) } - @Test fun single_delete_multiple_inserts() { + @Test + fun single_delete_multiple_inserts() { val diff = ListDiffer.diff(listOf(3), listOf(1, 2)) assertEquals( diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/support/SupportTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/support/SupportTest.kt index 5cc33d13..4dff6db2 100644 --- a/assertk/src/commonTest/kotlin/test/assertk/assertions/support/SupportTest.kt +++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/support/SupportTest.kt @@ -14,96 +14,118 @@ import kotlin.test.* class SupportTest { //region show - @Test fun show_null() { + @Test + fun show_null() { assertEquals("", show(null)) } - @Test fun show_boolean() { + @Test + fun show_boolean() { assertEquals("", show(true)) } - @Test fun show_char() { + @Test + fun show_char() { assertEquals("<'c'>", show('c')) } - @Test fun show_double() { + @Test + fun show_double() { assertEquals("<1.234567890123>", show(1.234567890123)) } - @Test fun show_int() { + @Test + fun show_int() { assertEquals("<42>", show(42)) } - @Test fun show_long() { + @Test + fun show_long() { assertEquals("<42L>", show(42L)) } - @Test fun show_short() { + @Test + fun show_short() { assertEquals("<42>", show(42.toShort())) } - @Test fun show_string() { + @Test + fun show_string() { assertEquals("<\"value\">", show("value")) } - @Test fun show_generic_array() { + @Test + fun show_generic_array() { assertEquals("<[\"one\", \"two\"]>", show(arrayOf("one", "two"))) } - @Test fun show_boolean_array() { + @Test + fun show_boolean_array() { assertEquals("<[true, false]>", show(booleanArrayOf(true, false))) } - @Test fun show_char_array() { + @Test + fun show_char_array() { assertEquals("<['a', 'b']>", show(charArrayOf('a', 'b'))) } - @Test fun show_double_array() { + @Test + fun show_double_array() { assertEquals("<[1.2345, 6.789]>", show(doubleArrayOf(1.2345, 6.789))) } - @Test fun show_int_array() { + @Test + fun show_int_array() { assertEquals("<[42, 8]>", show(intArrayOf(42, 8))) } - @Test fun show_long_array() { + @Test + fun show_long_array() { assertEquals("<[42L, 8L]>", show(longArrayOf(42L, 8L))) } - @Test fun show_short_array() { + @Test + fun show_short_array() { assertEquals("<[42, -1]>", show(shortArrayOf(42, -1))) } - @Test fun show_list() { + @Test + fun show_list() { assertEquals("<[1, 2, 3]>", show(listOf(1, 2, 3))) } - @Test fun show_map() { + @Test + fun show_map() { assertEquals("<{1=5, 2=6}>", show(mapOf(1 to 5, 2 to 6))) } - @Test fun show_pair() { + @Test + fun show_pair() { assertEquals("<(\"one\", '2')>", show("one" to '2')) } - @Test fun show_triple() { + @Test + fun show_triple() { assertEquals("<(\"one\", '2', 3)>", show(Triple("one", '2', 3))) } - @Test fun show_custom_type() { + @Test + fun show_custom_type() { val other = object : Any() { override fun toString(): String = "different" } assertEquals("", show(other)) } - @Test fun show_different_wrapper() { + @Test + fun show_different_wrapper() { assertEquals("{42}", show(42, "{}")) } //endregion //region fail - @Test fun fail_expected_and_actual_the_same_shows_simple_message_without_diff() { + @Test + fun fail_expected_and_actual_the_same_shows_simple_message_without_diff() { val error = assertFailsWith { assertThat(0).fail(1, 1) } @@ -111,7 +133,8 @@ class SupportTest { assertEquals("expected:<1> but was:<1>", error.message) } - @Test fun fail_expected_null_shows_simple_message_without_diff() { + @Test + fun fail_expected_null_shows_simple_message_without_diff() { val error = assertFailsWith { assertThat(0).fail(null, 1) } @@ -119,7 +142,8 @@ class SupportTest { assertEquals("expected: but was:<1>", error.message) } - @Test fun fail_actual_null_shows_simple_message_without_diff() { + @Test + fun fail_actual_null_shows_simple_message_without_diff() { val error = assertFailsWith { assertThat(0).fail(1, null) } @@ -127,7 +151,8 @@ class SupportTest { assertEquals("expected:<1> but was:", error.message) } - @Test fun fail_short_expected_and_actual_different_shows_simple_diff() { + @Test + fun fail_short_expected_and_actual_different_shows_simple_diff() { val error = assertFailsWith { assertThat(0).fail("test1", "test2") } @@ -135,7 +160,8 @@ class SupportTest { assertEquals("expected:<\"test[1]\"> but was:<\"test[2]\">", error.message) } - @Test fun fail_long_expected_and_actual_different_shows_compact_diff() { + @Test + fun fail_long_expected_and_actual_different_shows_compact_diff() { val error = assertFailsWith { assertThat(0).fail( "this is a long prefix 1 this is a long suffix", @@ -151,7 +177,8 @@ class SupportTest { //endregion //region expected - @Test fun expected_throws_assertion_failed_error_with_actual_and_expected_present_and_defined() { + @Test + fun expected_throws_assertion_failed_error_with_actual_and_expected_present_and_defined() { val error = assertFailsWith { assertThat(0).expected("message", "expected", "actual") } @@ -165,7 +192,8 @@ class SupportTest { assertNull(error.cause) } - @Test fun expected_throws_assertion_failed_error_with_actual_and_expected_not_defined() { + @Test + fun expected_throws_assertion_failed_error_with_actual_and_expected_not_defined() { val error = assertFailsWith { assertThat(0).expected("message") } @@ -179,7 +207,8 @@ class SupportTest { assertNull(error.cause) } - @Test fun expected_throwable_included_as_cause() { + @Test + fun expected_throwable_included_as_cause() { val subject = RuntimeException() val error = assertFailsWith { assertThat(subject).expected("message") @@ -187,7 +216,8 @@ class SupportTest { assertSame(subject, error.cause) } - @Test fun expected_failure_result_included_as_cause() { + @Test + fun expected_failure_result_included_as_cause() { val subject = RuntimeException() val error = assertFailsWith { assertThat(Result.failure(subject)).expected("message") @@ -195,14 +225,16 @@ class SupportTest { assertSame(subject, error.cause) } - @Test fun expected_success_result_not_included_as_cause() { + @Test + fun expected_success_result_not_included_as_cause() { val error = assertFailsWith { assertThat(Result.success("hey")).expected("message") } assertNull(error.cause) } - @Test fun expected_originating_throwable_included_as_cause() { + @Test + fun expected_originating_throwable_included_as_cause() { val subject = RuntimeException() val assert = assertThat(subject).message() val error = assertFailsWith { @@ -211,7 +243,8 @@ class SupportTest { assertSame(subject, error.cause) } - @Test fun expected_originating_failure_result_included_as_cause() { + @Test + fun expected_originating_failure_result_included_as_cause() { val subject = RuntimeException() val assert = assertThat(Result.failure(subject)).isFailure().message() val error = assertFailsWith { @@ -220,7 +253,8 @@ class SupportTest { assertSame(subject, error.cause) } - @Test fun expected_originating_success_result_not_included_as_cause() { + @Test + fun expected_originating_success_result_not_included_as_cause() { val assert = assertThat(Result.success("hey")).isSuccess() val error = assertFailsWith { assert.expected("message") diff --git a/assertk/src/jsTest/kotlin/test/assertk/assertions/support/JsSupportTest.kt b/assertk/src/jsTest/kotlin/test/assertk/assertions/support/JsSupportTest.kt index f5bd2535..e1715696 100644 --- a/assertk/src/jsTest/kotlin/test/assertk/assertions/support/JsSupportTest.kt +++ b/assertk/src/jsTest/kotlin/test/assertk/assertions/support/JsSupportTest.kt @@ -6,7 +6,8 @@ import kotlin.test.assertEquals class JsSupportTest { - @Test fun show_regex() { + @Test + fun show_regex() { assertEquals("", show(Regex("^abcd$"))) } } \ No newline at end of file diff --git a/assertk/src/jvmTest/kotlin/test/assertk/JVMAssertAllTest.kt b/assertk/src/jvmTest/kotlin/test/assertk/JVMAssertAllTest.kt index 2689a9d7..fabfb159 100644 --- a/assertk/src/jvmTest/kotlin/test/assertk/JVMAssertAllTest.kt +++ b/assertk/src/jvmTest/kotlin/test/assertk/JVMAssertAllTest.kt @@ -12,7 +12,8 @@ import kotlin.test.assertFailsWith import kotlin.test.assertFalse class JVMAssertAllTest { - @Test fun assertAll_is_thread_safe() { + @Test + fun assertAll_is_thread_safe() { runOnMultipleThreads { assertAll { assertThat("one").isEqualTo("one") @@ -21,7 +22,8 @@ class JVMAssertAllTest { } } - @Test fun all_is_thread_safe() { + @Test + fun all_is_thread_safe() { runOnMultipleThreads { assertThat("one").all { contains("o") @@ -30,7 +32,8 @@ class JVMAssertAllTest { } } - @Test fun assertAll_includes_exceptions_as_suppressed() { + @Test + fun assertAll_includes_exceptions_as_suppressed() { val error = assertFailsWith { assertAll { assertThat(1).isEqualTo(2) @@ -42,7 +45,8 @@ class JVMAssertAllTest { assertEquals("expected:<[1]> but was:<[2]>", error.suppressed[1].message) } - @Test fun assertAll_does_not_catch_out_of_memory_errors() { + @Test + fun assertAll_does_not_catch_out_of_memory_errors() { assertFailsWith { assertAll { throw OutOfMemoryError() @@ -50,7 +54,8 @@ class JVMAssertAllTest { } } - @Test fun assertAll_does_not_catch_out_of_memory_errors_in_nested_assert() { + @Test + fun assertAll_does_not_catch_out_of_memory_errors_in_nested_assert() { var runs = false assertFailsWith { assertAll { diff --git a/assertk/src/jvmTest/kotlin/test/assertk/assertions/FileTest.kt b/assertk/src/jvmTest/kotlin/test/assertk/assertions/FileTest.kt index 62c95689..3518c891 100644 --- a/assertk/src/jvmTest/kotlin/test/assertk/assertions/FileTest.kt +++ b/assertk/src/jvmTest/kotlin/test/assertk/assertions/FileTest.kt @@ -12,11 +12,13 @@ class FileTest { val directory = Files.createTempDirectory("isDirectory").toFile() //region exists - @Test fun exists_with_existing_file_passes() { + @Test + fun exists_with_existing_file_passes() { assertThat(file).exists() } - @Test fun exists_with_nonexistent_file_fails() { + @Test + fun exists_with_nonexistent_file_fails() { val tempFile = File.createTempFile("exists", "txt") tempFile.delete() val error = assertFailsWith { @@ -27,11 +29,13 @@ class FileTest { //endregion //region isDirectory - @Test fun isDirectory_value_directory_passes() { + @Test + fun isDirectory_value_directory_passes() { assertThat(directory).isDirectory() } - @Test fun isDirectory_value_file_fails() { + @Test + fun isDirectory_value_file_fails() { val error = assertFailsWith { assertThat(file).isDirectory() } @@ -40,11 +44,13 @@ class FileTest { //endregion //region isFile - @Test fun isFile_value_file_passes() { + @Test + fun isFile_value_file_passes() { assertThat(file).isFile() } - @Test fun isFile_value_directory_fails() { + @Test + fun isFile_value_directory_fails() { val error = assertFailsWith { assertThat(directory).isFile() } @@ -53,13 +59,15 @@ class FileTest { //endregion //region isNotHidden - @Test fun isNotHidden_value_regular_file_passes() { + @Test + fun isNotHidden_value_regular_file_passes() { assertThat(file).isNotHidden() } //endregion //region isHidden - @Test fun isHidden_value_regular_file_fails() { + @Test + fun isHidden_value_regular_file_fails() { val error = assertFailsWith { assertThat(file).isHidden() } @@ -71,22 +79,29 @@ class FileTest { val namedFile = File("assertKt/file.txt") val namedDirectory = File("assertKt/directory") - @Test fun hasName_correct_value_file_passes() { + @Test + fun hasName_correct_value_file_passes() { assertThat(namedFile).hasName("file.txt") } - @Test fun hasName_correct_value_directory_pases() { + @Test + fun hasName_correct_value_directory_pases() { assertThat(namedDirectory).hasName("directory") } - @Test fun hasName_wrong_value_file_fails() { + @Test + fun hasName_wrong_value_file_fails() { val error = assertFailsWith { assertThat(namedFile).hasName("file") } - assertEquals("expected [name]:<\"file[]\"> but was:<\"file[.txt]\"> (assertKt${File.separator}file.txt)", error.message) + assertEquals( + "expected [name]:<\"file[]\"> but was:<\"file[.txt]\"> (assertKt${File.separator}file.txt)", + error.message + ) } - @Test fun hasName_wront_value_directory_fails() { + @Test + fun hasName_wront_value_directory_fails() { val error = assertFailsWith { assertThat(namedDirectory).hasName("assertKt") } @@ -100,11 +115,13 @@ class FileTest { //region hasPath val fileWithPath = File("assertKt/file.txt") - @Test fun hasPath_correct_path_passes() { + @Test + fun hasPath_correct_path_passes() { assertThat(fileWithPath).hasPath("assertKt/file.txt") } - @Test fun hasPath_wrong_path_fails() { + @Test + fun hasPath_wrong_path_fails() { val error = assertFailsWith { assertThat(fileWithPath).hasPath("/directory") } @@ -118,15 +135,18 @@ class FileTest { //region hasParent val fileWithParent = File("assertKt/directory/file.txt") - @Test fun hasParent_correct_parent_passes() { + @Test + fun hasParent_correct_parent_passes() { assertThat(fileWithParent).hasParent("assertKt/directory") } - @Test fun hasParent_wrong_parent_passes() { + @Test + fun hasParent_wrong_parent_passes() { val error = assertFailsWith { assertThat(fileWithParent).hasParent("directory") } - val expected = "expected [parent]:<\"[]directory\"> but was:<\"[assertKt${File.separator}]directory\"> (assertKt${File.separator}directory${File.separator}file.txt)" + val expected = + "expected [parent]:<\"[]directory\"> but was:<\"[assertKt${File.separator}]directory\"> (assertKt${File.separator}directory${File.separator}file.txt)" println(expected) println(error.message) assertEquals( @@ -139,15 +159,20 @@ class FileTest { //region hasExtension val fileWithExtension = File("file.txt") - @Test fun hasExtension_correct_extension_passes() { + @Test + fun hasExtension_correct_extension_passes() { assertThat(fileWithExtension).hasExtension("txt") } - @Test fun hasExtension_wrong_extension_fails() { + @Test + fun hasExtension_wrong_extension_fails() { val error = assertFailsWith { assertThat(fileWithExtension).hasExtension("png") } - assertEquals("expected [extension]:<\"[png]\"> but was:<\"[${fileWithExtension.extension}]\"> (file.txt)", error.message) + assertEquals( + "expected [extension]:<\"[png]\"> but was:<\"[${fileWithExtension.extension}]\"> (file.txt)", + error.message + ) } //endregion @@ -161,11 +186,13 @@ class FileTest { fileWithText.writeText(text) } - @Test fun hasText_correct_value_passes() { + @Test + fun hasText_correct_value_passes() { assertThat(fileWithText).hasText(text) } - @Test fun hasText_wrong_value_fails() { + @Test + fun hasText_wrong_value_fails() { val error = assertFailsWith { assertThat(fileWithText).hasText("Forty-two!") } @@ -175,11 +202,13 @@ class FileTest { //endregion //region contains - @Test fun contains_correct_substring_passes() { + @Test + fun contains_correct_substring_passes() { assertThat(fileWithText).text().contains("Forty-two") } - @Test fun contains_wrong_substring_fails() { + @Test + fun contains_wrong_substring_fails() { val error = assertFailsWith { assertThat(fileWithText).text().contains("Forty-two!") } @@ -197,11 +226,13 @@ class FileTest { matchingFile.writeText(matchingText) } - @Test fun matches_correct_regex_passes() { + @Test + fun matches_correct_regex_passes() { assertThat(matchingFile).text().matches(".a...e.".toRegex()) } - @Test fun matches_wrong_regex_fails() { + @Test + fun matches_wrong_regex_fails() { val incorrectRegexp = ".*d".toRegex() val error = assertFailsWith { assertThat(matchingFile).text().matches(incorrectRegexp) @@ -215,11 +246,13 @@ class FileTest { val directoryWithChild = Files.createTempDirectory("isDirectory").toFile() val childFile = File.createTempFile("file", ".txt", directoryWithChild) - @Test fun hasDirectChild_value_is_child_passes() { + @Test + fun hasDirectChild_value_is_child_passes() { assertThat(directoryWithChild).hasDirectChild(childFile) } - @Test fun hasDirectChild_value_not_child_fails() { + @Test + fun hasDirectChild_value_not_child_fails() { val newFile = File.createTempFile("file", ".txt") val error = assertFailsWith { assertThat(directoryWithChild).hasDirectChild(newFile) @@ -227,7 +260,8 @@ class FileTest { assertEquals("expected to have direct child <$newFile>", error.message) } - @Test fun hasDirectChild_empty_directory_fails() { + @Test + fun hasDirectChild_empty_directory_fails() { directoryWithChild.listFiles().forEach { it.delete() } val error = assertFailsWith { assertThat(directory).hasDirectChild(file) diff --git a/assertk/src/jvmTest/kotlin/test/assertk/assertions/InputStreamTest.kt b/assertk/src/jvmTest/kotlin/test/assertk/assertions/InputStreamTest.kt index 7d455b12..d39e4f9c 100644 --- a/assertk/src/jvmTest/kotlin/test/assertk/assertions/InputStreamTest.kt +++ b/assertk/src/jvmTest/kotlin/test/assertk/assertions/InputStreamTest.kt @@ -12,11 +12,13 @@ import kotlin.test.assertFailsWith class InputStreamTest { //region hasSameContentAs - @Test fun hasSameContentAs_on_empty_streams_passes() { + @Test + fun hasSameContentAs_on_empty_streams_passes() { assertThat(emptyStream()).hasSameContentAs(emptyStream()) } - @Test fun hasSameContentAs_on_different_streams_fails() { + @Test + fun hasSameContentAs_on_different_streams_fails() { val error = assertFailsWith { assertThat(emptyStream()).hasSameContentAs(streamA()) } @@ -26,7 +28,8 @@ class InputStreamTest { ) } - @Test fun hasSameContentAs_on_different_non_empty_streams_fails() { + @Test + fun hasSameContentAs_on_different_non_empty_streams_fails() { val error = assertFailsWith { assertThat(streamA()).hasSameContentAs(streamB()) } @@ -36,11 +39,13 @@ class InputStreamTest { ) } - @Test fun hasSameContentAs_with_same_streams_passes() { + @Test + fun hasSameContentAs_with_same_streams_passes() { assertThat(streamA()).hasSameContentAs(streamA()) } - @Test fun hasSameContent_on_different_sized_streams_fails() { + @Test + fun hasSameContent_on_different_sized_streams_fails() { val error = assertFailsWith { assertThat(prefixOfStreamA()).hasSameContentAs(streamA()) } @@ -52,7 +57,8 @@ class InputStreamTest { assertEquals("expected to have the same size, but actual size (10) differs from other size (5)", error2.message) } - @Test fun hasSameContentAs_streams_different_in_single_value_fails() { + @Test + fun hasSameContentAs_streams_different_in_single_value_fails() { val error = assertFailsWith { assertThat(streamB()).hasSameContentAs(streamC()) } @@ -65,29 +71,34 @@ class InputStreamTest { //endregion //region hasNotSameContentAs - @Test fun hasNotSameContentAs_on_empty_streams_fails() { + @Test + fun hasNotSameContentAs_on_empty_streams_fails() { val error = assertFailsWith { assertThat(emptyStream()).hasNotSameContentAs(emptyStream()) } assertEquals("expected streams not to be equal, but they were equal", error.message) } - @Test fun hasNotSameContentAs_on_different_streams_passes() { + @Test + fun hasNotSameContentAs_on_different_streams_passes() { assertThat(emptyStream()).hasNotSameContentAs(streamA()) } - @Test fun hasNotSameContentAs_on_same_streams_fails() { + @Test + fun hasNotSameContentAs_on_same_streams_fails() { val error = assertFailsWith { assertThat(streamA()).hasNotSameContentAs(streamA()) } assertEquals("expected streams not to be equal, but they were equal", error.message) } - @Test fun hasNotSameContentAs_on_different_non_empty_streams_passes() { + @Test + fun hasNotSameContentAs_on_different_non_empty_streams_passes() { assertThat(streamA()).hasNotSameContentAs(streamB()) } - @Test fun hasNotSameContentAs_on_different_sized_streams_passes() { + @Test + fun hasNotSameContentAs_on_different_sized_streams_passes() { assertThat(prefixOfStreamA()).hasNotSameContentAs(streamA()) assertThat(streamA()).hasNotSameContentAs(prefixOfStreamA()) assertThat(streamB()).hasNotSameContentAs(streamC()) diff --git a/assertk/src/jvmTest/kotlin/test/assertk/assertions/JVMResultTest.kt b/assertk/src/jvmTest/kotlin/test/assertk/assertions/JVMResultTest.kt index 7b5c6cf0..06ccbb1d 100644 --- a/assertk/src/jvmTest/kotlin/test/assertk/assertions/JVMResultTest.kt +++ b/assertk/src/jvmTest/kotlin/test/assertk/assertions/JVMResultTest.kt @@ -11,7 +11,8 @@ import kotlin.test.assertTrue class JVMResultTest { - @Test fun failure_result_fails_with_stacktrace() { + @Test + fun failure_result_fails_with_stacktrace() { val error = assertFailsWith { assertThat(Result.failure(Exception("test"))).isSuccess() } diff --git a/assertk/src/jvmTest/kotlin/test/assertk/assertions/JavaAnyTest.kt b/assertk/src/jvmTest/kotlin/test/assertk/assertions/JavaAnyTest.kt index 44a3cc1b..c162b2df 100644 --- a/assertk/src/jvmTest/kotlin/test/assertk/assertions/JavaAnyTest.kt +++ b/assertk/src/jvmTest/kotlin/test/assertk/assertions/JavaAnyTest.kt @@ -15,21 +15,25 @@ class JavaAnyTest { val subject = BasicObject("test") //region jClass - @Test fun extracts_jClass() { + @Test + fun extracts_jClass() { assertEquals(BasicObject::class.java, assertThat(subject as TestObject).jClass().valueOrFail) } //endregion //region isInstanceOf - @Test fun isInstanceOf_jclass_same_class_passes() { + @Test + fun isInstanceOf_jclass_same_class_passes() { assertThat(subject).isInstanceOf(BasicObject::class.java) } - @Test fun isInstanceOf_jclass_parent_class_passes() { + @Test + fun isInstanceOf_jclass_parent_class_passes() { assertThat(subject).isInstanceOf(TestObject::class.java) } - @Test fun isInstanceOf_jclass_different_class_fails() { + @Test + fun isInstanceOf_jclass_different_class_fails() { val error = assertFailsWith { assertThat(subject).isInstanceOf(DifferentObject::class.java) } @@ -39,7 +43,8 @@ class JavaAnyTest { ) } - @Test fun isInstanceOf_jclass_run_block_when_passes() { + @Test + fun isInstanceOf_jclass_run_block_when_passes() { val error = assertFailsWith { assertThat(subject as TestObject) .isInstanceOf(BasicObject::class.java) @@ -49,7 +54,8 @@ class JavaAnyTest { assertEquals("expected [str]:<\"[wrong]\"> but was:<\"[test]\"> (test)", error.message) } - @Test fun isInstanceOf_jclass_doesnt_run_block_when_fails() { + @Test + fun isInstanceOf_jclass_doesnt_run_block_when_fails() { val error = assertFailsWith { assertThat(subject as TestObject) .isInstanceOf(DifferentObject::class.java) @@ -63,18 +69,21 @@ class JavaAnyTest { //endregion //region isNotInstanceOf - @Test fun isNotInstanceOf_jclass_different_class_passess() { + @Test + fun isNotInstanceOf_jclass_different_class_passess() { assertThat(subject).isNotInstanceOf(DifferentObject::class.java) } - @Test fun isNotInstanceOf_jclass_same_class_fails() { + @Test + fun isNotInstanceOf_jclass_same_class_fails() { val error = assertFailsWith { assertThat(subject).isNotInstanceOf(BasicObject::class.java) } assertEquals("expected to not be instance of:<$p\$BasicObject>", error.message) } - @Test fun isNotInstanceOf_jclass_parent_class_fails() { + @Test + fun isNotInstanceOf_jclass_parent_class_fails() { val error = assertFailsWith { assertThat(subject).isNotInstanceOf(TestObject::class.java) } @@ -83,12 +92,14 @@ class JavaAnyTest { //endregion //region isDataClassEqualTo - @Test fun isDataClassEqualTo_equal_data_classes_passes() { + @Test + fun isDataClassEqualTo_equal_data_classes_passes() { assertThat(DataClass(InnerDataClass("test"), 1, 'a')) .isDataClassEqualTo(DataClass(InnerDataClass("test"), 1, 'a')) } - @Test fun isDataClassEqualTo_reports_all_properties_that_differ_on_failure() { + @Test + fun isDataClassEqualTo_reports_all_properties_that_differ_on_failure() { val error = assertFailsWith { assertThat(DataClass(InnerDataClass("test"), 1, 'a')) .isDataClassEqualTo(DataClass(InnerDataClass("wrong"), 1, 'b')) @@ -101,7 +112,8 @@ class JavaAnyTest { ) } - @Test fun isDataClassEqualTo_fails_on_null_property_in_actual() { + @Test + fun isDataClassEqualTo_fails_on_null_property_in_actual() { val error = assertFailsWith { assertThat(DataClass(null, 1, 'a')) .isDataClassEqualTo(DataClass(InnerDataClass("wrong"), 1, 'b')) @@ -114,7 +126,8 @@ class JavaAnyTest { ) } - @Test fun isDataClassEqualTo_fails_on_null_property_in_expected() { + @Test + fun isDataClassEqualTo_fails_on_null_property_in_expected() { val error = assertFailsWith { assertThat(DataClass(InnerDataClass("test"), 1, 'a')) .isDataClassEqualTo(DataClass(null, 1, 'b')) @@ -129,18 +142,41 @@ class JavaAnyTest { //endregion //region isEqualToIgnoringGivenProperties - @Test fun isEqualToIgnoringGivenProperties_passes() { - assertThat(BasicObject("Rarity")).isEqualToIgnoringGivenProperties(BasicObject("notRarity"), BasicObject::str, BasicObject::other, BasicObject::failing) + @Test + fun isEqualToIgnoringGivenProperties_passes() { + assertThat(BasicObject("Rarity")).isEqualToIgnoringGivenProperties( + BasicObject("notRarity"), + BasicObject::str, + BasicObject::other, + BasicObject::failing + ) } - @Test fun isEqualToIgnoringGivenProperties_fails() { + @Test + fun isEqualToIgnoringGivenProperties_fails() { assertFailsWith { - assertThat(BasicObject("Rarity", int = 42)).isEqualToIgnoringGivenProperties(BasicObject("notRarity", int = 1337), BasicObject::str, BasicObject::failing) + assertThat(BasicObject("Rarity", int = 42)).isEqualToIgnoringGivenProperties( + BasicObject( + "notRarity", + int = 1337 + ), BasicObject::str, BasicObject::failing + ) } } - @Test fun isEqualToIgnoringGivenProperties_passes_even_when_private_property_differs() { - assertThat(BasicObject(str = "Rarity", private = 1)).isEqualToIgnoringGivenProperties(BasicObject(str = "notRarity", private = 2), BasicObject::str, BasicObject::other, BasicObject::failing) + @Test + fun isEqualToIgnoringGivenProperties_passes_even_when_private_property_differs() { + assertThat( + BasicObject( + str = "Rarity", + private = 1 + ) + ).isEqualToIgnoringGivenProperties( + BasicObject(str = "notRarity", private = 2), + BasicObject::str, + BasicObject::other, + BasicObject::failing + ) } //endregion diff --git a/assertk/src/jvmTest/kotlin/test/assertk/assertions/JavaNullableStringTest.kt b/assertk/src/jvmTest/kotlin/test/assertk/assertions/JavaNullableStringTest.kt index 6c70c6f9..94516e38 100644 --- a/assertk/src/jvmTest/kotlin/test/assertk/assertions/JavaNullableStringTest.kt +++ b/assertk/src/jvmTest/kotlin/test/assertk/assertions/JavaNullableStringTest.kt @@ -10,11 +10,13 @@ import kotlin.test.assertFailsWith class JavaNullableStringTest { //region isEqualTo - @Test fun isEqualTo_same_nullable_string_passes() { + @Test + fun isEqualTo_same_nullable_string_passes() { assertThat(JavaNullableString.string()).isEqualTo(JavaNullableString.string()) } - @Test fun isEqualTo_different_string_fails() { + @Test + fun isEqualTo_different_string_fails() { val error = assertFailsWith { assertThat(JavaNullableString.string()).isEqualTo("wrong") } @@ -23,11 +25,13 @@ class JavaNullableStringTest { //endregion //region isNotEqualTo - @Test fun isNotEqualTo_different_string_passes() { + @Test + fun isNotEqualTo_different_string_passes() { assertThat(JavaNullableString.string()).isNotEqualTo("wrong") } - @Test fun isNotEqualTo_same_nullable_string_fails() { + @Test + fun isNotEqualTo_same_nullable_string_fails() { val error = assertFailsWith { assertThat(JavaNullableString.string()).isNotEqualTo(JavaNullableString.string()) } diff --git a/assertk/src/jvmTest/kotlin/test/assertk/assertions/OptionalTest.kt b/assertk/src/jvmTest/kotlin/test/assertk/assertions/OptionalTest.kt index 0961ba76..0596a1a3 100644 --- a/assertk/src/jvmTest/kotlin/test/assertk/assertions/OptionalTest.kt +++ b/assertk/src/jvmTest/kotlin/test/assertk/assertions/OptionalTest.kt @@ -13,7 +13,8 @@ import kotlin.test.assertFailsWith internal class OptionalTest { - @Test fun isPresent_passes() { + @Test + fun isPresent_passes() { assertThat(Optional.of("test")).isPresent() } @@ -28,11 +29,13 @@ internal class OptionalTest { ) } - @Test fun isEmpty_passes() { + @Test + fun isEmpty_passes() { assertThat(Optional.empty()).isEmpty() } - @Test fun isEmpty_fails() { + @Test + fun isEmpty_fails() { val error = assertFailsWith { assertThat(Optional.of("test")).isEmpty() } @@ -42,11 +45,13 @@ internal class OptionalTest { ) } - @Test fun hasValue_passes() { + @Test + fun hasValue_passes() { assertThat(Optional.of("test")).hasValue("test") } - @Test fun hasValue_empty_fails() { + @Test + fun hasValue_empty_fails() { val error = assertFailsWith { assertThat(Optional.empty()).hasValue("test") } @@ -56,7 +61,8 @@ internal class OptionalTest { ) } - @Test fun hasValue_wrong_value_fails() { + @Test + fun hasValue_wrong_value_fails() { val error = assertFailsWith { assertThat(Optional.of("test")).hasValue("wrong") } diff --git a/assertk/src/jvmTest/kotlin/test/assertk/assertions/PathTest.kt b/assertk/src/jvmTest/kotlin/test/assertk/assertions/PathTest.kt index 48e0a758..86a92368 100644 --- a/assertk/src/jvmTest/kotlin/test/assertk/assertions/PathTest.kt +++ b/assertk/src/jvmTest/kotlin/test/assertk/assertions/PathTest.kt @@ -30,11 +30,13 @@ class PathTest { } //region isRegularFile - @Test fun isRegularFile_value_regularFile_passes() { + @Test + fun isRegularFile_value_regularFile_passes() { assertThat(regularFile!!).isRegularFile() } - @Test fun isRegularFile_value_directory_fails() { + @Test + fun isRegularFile_value_directory_fails() { val error = assertFailsWith { assertThat(directory!!).isRegularFile() } @@ -43,27 +45,31 @@ class PathTest { //endregion //region isDirectory - @Test fun isDirectory_value_not_directory_fails() { + @Test + fun isDirectory_value_not_directory_fails() { val error = assertFailsWith { assertThat(regularFile!!).isDirectory() } assertEquals("expected <$regularFile> to be a directory, but it is not", error.message) } - @Test fun isDirectory_value_directory_passes() { + @Test + fun isDirectory_value_directory_passes() { assertThat(directory!!).isDirectory() } //endregion //region isHidden - @Test fun isHidden_value_regular_file_not_hidden_fails() { + @Test + fun isHidden_value_regular_file_not_hidden_fails() { val error = assertFailsWith { assertThat(regularFile!!).isHidden() } assertEquals("expected <$regularFile> to be hidden, but it is not", error.message) } - @Test fun isHidden_value_directory_not_hidden_fails() { + @Test + fun isHidden_value_directory_not_hidden_fails() { val error = assertFailsWith { assertThat(directory!!).isHidden() } @@ -72,24 +78,28 @@ class PathTest { //endregion //region isReadable - @Test fun isReadable_value_readable_file_passes() { + @Test + fun isReadable_value_readable_file_passes() { assertThat(regularFile!!).isReadable() } - @Test fun isReadable_value_readable_directory_passes() { + @Test + fun isReadable_value_readable_directory_passes() { assertThat(directory!!).isReadable() } //endregion //region isSymbolicLink - @Test fun isSymbolicLink_value_regular_file_fails() { + @Test + fun isSymbolicLink_value_regular_file_fails() { val error = assertFailsWith { assertThat(regularFile!!).isSymbolicLink() } assertEquals("expected <$regularFile> to be a symbolic link, but it is not", error.message) } - @Test fun isSymbolicLink_value_directory_fails() { + @Test + fun isSymbolicLink_value_directory_fails() { val error = assertFailsWith { assertThat(directory!!).isSymbolicLink() } @@ -98,43 +108,52 @@ class PathTest { //endregion //region isWritable - @Test fun isWritable_value_writable_file_passes() { + @Test + fun isWritable_value_writable_file_passes() { assertThat(regularFile!!).isWritable() } - @Test fun isWritable_value_writable_directory_passes() { + @Test + fun isWritable_value_writable_directory_passes() { assertThat(directory!!).isWritable() } //endregion //region isSameFileAs - @Test fun isSameFileAs_value_same_file_passes() { + @Test + fun isSameFileAs_value_same_file_passes() { assertThat(regularFile!!).isSameFileAs(regularFile!!) } - @Test fun isSameFileAs_value_same_directory_passes() { + @Test + fun isSameFileAs_value_same_directory_passes() { assertThat(directory!!).isSameFileAs(directory!!) } - @Test fun isSameFileAs_value_same_file_different_path_passes() { + @Test + fun isSameFileAs_value_same_file_different_path_passes() { assertThat(regularFile!!).isSameFileAs(regularFile!!.toAbsolutePath()) } - @Test fun isSameFileAs_value_same_directory_different_path_passes() { + @Test + fun isSameFileAs_value_same_directory_different_path_passes() { assertThat(directory!!).isSameFileAs(directory!!.toAbsolutePath()) } //endregion //region exists - @Test fun exists_value_regularFile_passes() { + @Test + fun exists_value_regularFile_passes() { assertThat(regularFile!!).exists() } - @Test fun exists_value_directory_passes() { + @Test + fun exists_value_directory_passes() { assertThat(directory!!).exists() } - @Test fun exists_value_not_exists_fails() { + @Test + fun exists_value_not_exists_fails() { val error = assertFailsWith { assertThat(doesNotExist!!).exists() } @@ -143,13 +162,15 @@ class PathTest { //endregion //region lines - @Test fun lines_correct_string_passes() { + @Test + fun lines_correct_string_passes() { assertThat(regularFileWithText!!).lines().containsExactly("a", "b") } //endregion //region bytes - @Test fun bytes_value_correct_byte_array_passes() { + @Test + fun bytes_value_correct_byte_array_passes() { assertThat(regularFile!!).bytes().containsExactly(*ByteArray(10)) } //endregion @@ -157,4 +178,5 @@ class PathTest { private fun createTempDir() = Files.createTempDirectory("tempDir") private fun createTempFile() = Files.createTempFile("tempFile", "").apply { toFile().writeBytes(ByteArray(10)) } -private fun createTempFileWithText() = Files.createTempFile("tempFileWithText", "").apply { toFile().writeText("a\nb", Charsets.UTF_8) } +private fun createTempFileWithText() = + Files.createTempFile("tempFileWithText", "").apply { toFile().writeText("a\nb", Charsets.UTF_8) } diff --git a/assertk/src/jvmTest/kotlin/test/assertk/assertions/support/JavaSupportTest.kt b/assertk/src/jvmTest/kotlin/test/assertk/assertions/support/JavaSupportTest.kt index 0e10563d..c6bcc99f 100644 --- a/assertk/src/jvmTest/kotlin/test/assertk/assertions/support/JavaSupportTest.kt +++ b/assertk/src/jvmTest/kotlin/test/assertk/assertions/support/JavaSupportTest.kt @@ -6,23 +6,28 @@ import kotlin.test.assertEquals class JavaSupportTest { - @Test fun show_float() { + @Test + fun show_float() { assertEquals("<1.2345f>", show(1.2345f)) } - @Test fun show_float_array() { + @Test + fun show_float_array() { assertEquals("<[1.2345f, 6.789f]>", show(floatArrayOf(1.2345f, 6.789f))) } - @Test fun show_byte() { + @Test + fun show_byte() { assertEquals("<0x0F>", show(15.toByte())) } - @Test fun show_byte_array() { + @Test + fun show_byte_array() { assertEquals("<[0x0A, 0x0F]>", show(byteArrayOf(10, 15))) } - @Test fun show_regex() { + @Test + fun show_regex() { assertEquals("", show(Regex("^abcd$"))) } } \ No newline at end of file diff --git a/assertk/src/nativeTest/kotlin/test/assertk/NativeAssertAllTest.kt b/assertk/src/nativeTest/kotlin/test/assertk/NativeAssertAllTest.kt index 86a47ff6..aa438f6a 100644 --- a/assertk/src/nativeTest/kotlin/test/assertk/NativeAssertAllTest.kt +++ b/assertk/src/nativeTest/kotlin/test/assertk/NativeAssertAllTest.kt @@ -15,7 +15,8 @@ import kotlin.test.* @ObsoleteWorkersApi class NativeAssertAllTest { - @Test fun assert_all_is_thread_safe() { + @Test + fun assert_all_is_thread_safe() { aBunchOfWokers { w -> w.execute(TransferMode.SAFE, { }, { assertAll { @@ -26,7 +27,8 @@ class NativeAssertAllTest { } } - @Test fun all_is_thread_safe() { + @Test + fun all_is_thread_safe() { aBunchOfWokers { w -> w.execute(TransferMode.SAFE, { }, { assertThat("one").all { @@ -37,7 +39,8 @@ class NativeAssertAllTest { } } - @Test fun assertAll_does_not_catch_out_of_memory_errors() { + @Test + fun assertAll_does_not_catch_out_of_memory_errors() { assertFailsWith { assertAll { throw OutOfMemoryError() @@ -45,7 +48,8 @@ class NativeAssertAllTest { } } - @Test fun assertAll_does_not_catch_out_of_memory_errors_in_nested_assert() { + @Test + fun assertAll_does_not_catch_out_of_memory_errors_in_nested_assert() { var runs = false assertFailsWith { assertAll { @@ -64,7 +68,9 @@ class NativeAssertAllTest { futures.add(f(w)) } } - for (future in futures) { future.result } + for (future in futures) { + future.result + } for (w in workers) { w.requestTermination().result diff --git a/assertk/src/nativeTest/kotlin/test/assertk/assertions/support/NativeSupportTest.kt b/assertk/src/nativeTest/kotlin/test/assertk/assertions/support/NativeSupportTest.kt index 76c93a1d..6912e97b 100644 --- a/assertk/src/nativeTest/kotlin/test/assertk/assertions/support/NativeSupportTest.kt +++ b/assertk/src/nativeTest/kotlin/test/assertk/assertions/support/NativeSupportTest.kt @@ -6,7 +6,8 @@ import kotlin.test.assertEquals class NativeSupportTest { - @Test fun show_byte_array() { + @Test + fun show_byte_array() { assertEquals("<[0x0A, 0x0F]>", show(byteArrayOf(10, 15))) } diff --git a/assertk/src/testTemplate/test/assertk/assertions/FloatArrayContainsTest.kt b/assertk/src/testTemplate/test/assertk/assertions/FloatArrayContainsTest.kt index db489300..21666993 100644 --- a/assertk/src/testTemplate/test/assertk/assertions/FloatArrayContainsTest.kt +++ b/assertk/src/testTemplate/test/assertk/assertions/FloatArrayContainsTest.kt @@ -12,15 +12,18 @@ $T:$N:$E = FloatArray:floatArray:Float, DoubleArray:doubleArray:Double class $TContainsTest { //region contains - @Test fun contains_element_present_passes() { + @Test + fun contains_element_present_passes() { assertThat($NOf(1.to$E(), 2.to$E())).contains(2.to$E()) } - @Test fun contains_nan_present_passes() { + @Test + fun contains_nan_present_passes() { assertThat($NOf($E.NaN)).contains($E.NaN) } - @Test fun contains_element_missing_fails() { + @Test + fun contains_element_missing_fails() { val error = assertFailsWith { assertThat($NOf()).contains(1.to$E()) } @@ -29,18 +32,21 @@ class $TContainsTest { //endregion //region doesNotContain - @Test fun doesNotContain_element_missing_passes() { + @Test + fun doesNotContain_element_missing_passes() { assertThat($NOf()).doesNotContain(1.to$E()) } - @Test fun doesNotContain_element_present_fails() { + @Test + fun doesNotContain_element_present_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E())).doesNotContain(2.to$E()) } assertEquals("expected to not contain:<${show(2.to$E(), "")}> but was:<[${show(1.to$E(), "")}, ${show(2.to$E(), "")}]>", error.message) } - @Test fun doesNotContain_nan_present_fails() { + @Test + fun doesNotContain_nan_present_fails() { val error = assertFailsWith { assertThat($NOf($E.NaN)).doesNotContain($E.NaN) } @@ -49,11 +55,13 @@ class $TContainsTest { //endregion //region containsNone - @Test fun containsNone_missing_elements_passes() { + @Test + fun containsNone_missing_elements_passes() { assertThat($NOf()).containsNone(1.to$E()) } - @Test fun containsNone_present_element_fails() { + @Test + fun containsNone_present_element_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E())).containsNone(2.to$E(), 3.to$E()) } @@ -66,11 +74,13 @@ class $TContainsTest { //region //region containsAtLeast - @Test fun containsAtLeast_all_elements_passes() { + @Test + fun containsAtLeast_all_elements_passes() { assertThat($NOf(1.to$E(), 2.to$E())).containsAtLeast(2.to$E(), 1.to$E()) } - @Test fun containsAtLeast_some_elements_fails() { + @Test + fun containsAtLeast_some_elements_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E())).containsAtLeast(1.to$E(), 2.to$E()) } @@ -83,19 +93,23 @@ class $TContainsTest { //endregion //region containsOnly - @Test fun containsOnly_only_elements_passes() { + @Test + fun containsOnly_only_elements_passes() { assertThat($NOf(1.to$E(), 2.to$E())).containsOnly(2.to$E(), 1.to$E()) } - @Test fun containsOnly_duplicate_elements_passes() { + @Test + fun containsOnly_duplicate_elements_passes() { assertThat($NOf(1.to$E(), 2.to$E(), 2.to$E())).containsOnly(2.to$E(), 1.to$E()) } - @Test fun containsOnly_duplicate_elements_passes2() { + @Test + fun containsOnly_duplicate_elements_passes2() { assertThat($NOf(1.to$E(), 2.to$E())).containsOnly(2.to$E(), 2.to$E(), 1.to$E()) } - @Test fun containsOnly_more_elements_fails() { + @Test + fun containsOnly_more_elements_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E(), 3.to$E())).containsOnly(2.to$E(), 1.to$E()) } @@ -106,7 +120,8 @@ class $TContainsTest { ) } - @Test fun containsOnly_less_elements_fails() { + @Test + fun containsOnly_less_elements_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E(), 3.to$E())).containsOnly(2.to$E(), 1.to$E(), 3.to$E(), 4.to$E()) } @@ -118,7 +133,8 @@ class $TContainsTest { ) } - @Test fun containsOnly_different_elements_fails() { + @Test + fun containsOnly_different_elements_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E())).containsOnly(2.to$E()) } @@ -133,11 +149,13 @@ class $TContainsTest { //endregion //region containsExactly - @Test fun containsExactly_all_elements_in_same_order_passes() { + @Test + fun containsExactly_all_elements_in_same_order_passes() { assertThat($NOf(1.to$E(), 2.to$E())).containsExactly(1.to$E(), 2.to$E()) } - @Test fun containsExactly_all_elements_in_different_order_fails() { + @Test + fun containsExactly_all_elements_in_different_order_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E())).containsExactly(2.to$E(), 1.to$E()) } @@ -149,7 +167,8 @@ class $TContainsTest { ) } - @Test fun containsExactly_missing_element_fails() { + @Test + fun containsExactly_missing_element_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E())).containsExactly(3.to$E()) } @@ -162,7 +181,8 @@ class $TContainsTest { ) } - @Test fun containsExactly_same_indexes_are_together() { + @Test + fun containsExactly_same_indexes_are_together() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 1.to$E())).containsExactly(2.to$E(), 2.to$E()) } @@ -176,7 +196,8 @@ class $TContainsTest { ) } - @Test fun containsExactly_extra_element_fails() { + @Test + fun containsExactly_extra_element_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E())).containsExactly(1.to$E(), 2.to$E(), 3.to$E()) } @@ -187,7 +208,8 @@ class $TContainsTest { ) } - @Test fun containsExactly_missing_element_in_middle_fails() { + @Test + fun containsExactly_missing_element_in_middle_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 3.to$E())).containsExactly(1.to$E(), 2.to$E(), 3.to$E()) } @@ -198,7 +220,8 @@ class $TContainsTest { ) } - @Test fun containsExactly_extra_element_in_middle_fails() { + @Test + fun containsExactly_extra_element_in_middle_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E(), 3.to$E())).containsExactly(1.to$E(), 3.to$E()) } @@ -211,15 +234,18 @@ class $TContainsTest { //endregion //region containsExactlyInAnyOrder - @Test fun containsExactlyInAnyOrder_only_elements_passes() { + @Test + fun containsExactlyInAnyOrder_only_elements_passes() { assertThat($NOf(1.to$E(), 2.to$E())).containsExactlyInAnyOrder(2.to$E(), 1.to$E()) } - @Test fun containsExactlyInAnyOrder_only_elements_passes2() { + @Test + fun containsExactlyInAnyOrder_only_elements_passes2() { assertThat($NOf(1.to$E(), 2.to$E(), 1.to$E())).containsExactlyInAnyOrder(2.to$E(), 1.to$E(), 1.to$E()) } - @Test fun containsExactlyInAnyOrder_duplicate_elements_fails() { + @Test + fun containsExactlyInAnyOrder_duplicate_elements_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E(), 2.to$E())).containsExactlyInAnyOrder(2.to$E(), 1.to$E()) } @@ -230,7 +256,8 @@ class $TContainsTest { ) } - @Test fun containsExactlyInAnyOrder_duplicate_elements_fails2() { + @Test + fun containsExactlyInAnyOrder_duplicate_elements_fails2() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E())).containsExactlyInAnyOrder(2.to$E(), 2.to$E(), 1.to$E()) } @@ -241,7 +268,8 @@ class $TContainsTest { ) } - @Test fun containsExactlyInAnyOrder_more_elements_fails() { + @Test + fun containsExactlyInAnyOrder_more_elements_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E(), 3.to$E())).containsExactlyInAnyOrder(2.to$E(), 1.to$E()) } @@ -252,7 +280,8 @@ class $TContainsTest { ) } - @Test fun containsExactlyInAnyOrder_less_elements_fails() { + @Test + fun containsExactlyInAnyOrder_less_elements_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E(), 3.to$E())).containsExactlyInAnyOrder(2.to$E(), 1.to$E(), 3.to$E(), 4.to$E()) } @@ -264,7 +293,8 @@ class $TContainsTest { ) } - @Test fun containsExactlyInAnyOrder_different_elements_fails() { + @Test + fun containsExactlyInAnyOrder_different_elements_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E())).containsExactlyInAnyOrder(2.to$E()) } @@ -279,15 +309,18 @@ class $TContainsTest { //endregion //region each - @Test fun each_empty_list_passes() { + @Test + fun each_empty_list_passes() { assertThat($NOf()).each { it.isEqualTo(1) } } - @Test fun each_content_passes() { + @Test + fun each_content_passes() { assertThat($NOf(1.to$E(), 2.to$E())).each { it.isGreaterThan(0.to$E()) } } - @Test fun each_non_matching_content_fails() { + @Test + fun each_non_matching_content_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E(), 3.to$E())).each { it.isLessThan(2.to$E()) } } @@ -301,11 +334,13 @@ class $TContainsTest { //endregion //region index - @Test fun index_successful_assertion_passes() { + @Test + fun index_successful_assertion_passes() { assertThat($NOf(1.to$E(), 2.to$E()), name = "subject").index(0).isEqualTo(1.to$E()) } - @Test fun index_unsuccessful_assertion_fails() { + @Test + fun index_unsuccessful_assertion_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E()), name = "subject").index(0).isGreaterThan(2.to$E()) } @@ -315,7 +350,8 @@ class $TContainsTest { ) } - @Test fun index_out_of_range_fails() { + @Test + fun index_out_of_range_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E()), name = "subject").index(-1).isEqualTo(listOf(1.to$E())) } diff --git a/assertk/src/testTemplate/test/assertk/assertions/PrimativeArrayContainsTest.kt b/assertk/src/testTemplate/test/assertk/assertions/PrimativeArrayContainsTest.kt index 6abf4025..93fff2d2 100644 --- a/assertk/src/testTemplate/test/assertk/assertions/PrimativeArrayContainsTest.kt +++ b/assertk/src/testTemplate/test/assertk/assertions/PrimativeArrayContainsTest.kt @@ -23,11 +23,13 @@ $T:$N:$E = @OptIn(ExperimentalUnsignedTypes::class) class $TContainsTest { //region contains - @Test fun contains_element_present_passes() { + @Test + fun contains_element_present_passes() { assertThat($NOf(1.to$E(), 2.to$E())).contains(2.to$E()) } - @Test fun contains_element_missing_fails() { + @Test + fun contains_element_missing_fails() { val error = assertFailsWith { assertThat($NOf()).contains(1.to$E()) } @@ -36,11 +38,13 @@ class $TContainsTest { //endregion //region doesNotContain - @Test fun doesNotContain_element_missing_passes() { + @Test + fun doesNotContain_element_missing_passes() { assertThat($NOf()).doesNotContain(1.to$E()) } - @Test fun doesNotContain_element_present_fails() { + @Test + fun doesNotContain_element_present_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E())).doesNotContain(2.to$E()) } @@ -49,11 +53,13 @@ class $TContainsTest { //endregion //region containsNone - @Test fun containsNone_missing_elements_passes() { + @Test + fun containsNone_missing_elements_passes() { assertThat($NOf()).containsNone(1.to$E()) } - @Test fun containsNone_present_element_fails() { + @Test + fun containsNone_present_element_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E())).containsNone(2.to$E(), 3.to$E()) } @@ -66,11 +72,13 @@ class $TContainsTest { //region //region containsAtLeast - @Test fun containsAtLeast_all_elements_passes() { + @Test + fun containsAtLeast_all_elements_passes() { assertThat($NOf(1.to$E(), 2.to$E())).containsAtLeast(2.to$E(), 1.to$E()) } - @Test fun containsAtLeast_some_elements_fails() { + @Test + fun containsAtLeast_some_elements_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E())).containsAtLeast(1.to$E(), 2.to$E()) } @@ -83,19 +91,23 @@ class $TContainsTest { //endregion //region containsOnly - @Test fun containsOnly_only_elements_passes() { + @Test + fun containsOnly_only_elements_passes() { assertThat($NOf(1.to$E(), 2.to$E())).containsOnly(2.to$E(), 1.to$E()) } - @Test fun containsOnly_duplicate_elements_passes() { + @Test + fun containsOnly_duplicate_elements_passes() { assertThat($NOf(1.to$E(), 2.to$E(), 2.to$E())).containsOnly(2.to$E(), 1.to$E()) } - @Test fun containsOnly_duplicate_elements_passes2() { + @Test + fun containsOnly_duplicate_elements_passes2() { assertThat($NOf(1.to$E(), 2.to$E())).containsOnly(2.to$E(), 2.to$E(), 1.to$E()) } - @Test fun containsOnly_more_elements_fails() { + @Test + fun containsOnly_more_elements_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E(), 3.to$E())).containsOnly(2.to$E(), 1.to$E()) } @@ -106,7 +118,8 @@ class $TContainsTest { ) } - @Test fun containsOnly_less_elements_fails() { + @Test + fun containsOnly_less_elements_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E(), 3.to$E())).containsOnly(2.to$E(), 1.to$E(), 3.to$E(), 4.to$E()) } @@ -118,7 +131,8 @@ class $TContainsTest { ) } - @Test fun containsOnly_different_elements_fails() { + @Test + fun containsOnly_different_elements_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E())).containsOnly(2.to$E()) } @@ -133,11 +147,13 @@ class $TContainsTest { //endregion //region containsExactly - @Test fun containsExactly_all_elements_in_same_order_passes() { + @Test + fun containsExactly_all_elements_in_same_order_passes() { assertThat($NOf(1.to$E(), 2.to$E())).containsExactly(1.to$E(), 2.to$E()) } - @Test fun containsExactly_all_elements_in_different_order_fails() { + @Test + fun containsExactly_all_elements_in_different_order_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E())).containsExactly(2.to$E(), 1.to$E()) } @@ -149,7 +165,8 @@ class $TContainsTest { ) } - @Test fun containsExactly_missing_element_fails() { + @Test + fun containsExactly_missing_element_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E())).containsExactly(3.to$E()) } @@ -162,7 +179,8 @@ class $TContainsTest { ) } - @Test fun containsExactly_same_indexes_are_together() { + @Test + fun containsExactly_same_indexes_are_together() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 1.to$E())).containsExactly(2.to$E(), 2.to$E()) } @@ -176,7 +194,8 @@ class $TContainsTest { ) } - @Test fun containsExactly_extra_element_fails() { + @Test + fun containsExactly_extra_element_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E())).containsExactly(1.to$E(), 2.to$E(), 3.to$E()) } @@ -187,7 +206,8 @@ class $TContainsTest { ) } - @Test fun containsExactly_missing_element_in_middle_fails() { + @Test + fun containsExactly_missing_element_in_middle_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 3.to$E())).containsExactly(1.to$E(), 2.to$E(), 3.to$E()) } @@ -198,7 +218,8 @@ class $TContainsTest { ) } - @Test fun containsExactly_extra_element_in_middle_fails() { + @Test + fun containsExactly_extra_element_in_middle_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E(), 3.to$E())).containsExactly(1.to$E(), 3.to$E()) } @@ -211,15 +232,18 @@ class $TContainsTest { //endregion //region containsExactlyInAnyOrder - @Test fun containsExactlyInAnyOrder_only_elements_passes() { + @Test + fun containsExactlyInAnyOrder_only_elements_passes() { assertThat($NOf(1.to$E(), 2.to$E())).containsExactlyInAnyOrder(2.to$E(), 1.to$E()) } - @Test fun containsExactlyInAnyOrder_only_elements_passes2() { + @Test + fun containsExactlyInAnyOrder_only_elements_passes2() { assertThat($NOf(1.to$E(), 2.to$E(), 1.to$E())).containsExactlyInAnyOrder(2.to$E(), 1.to$E(), 1.to$E()) } - @Test fun containsExactlyInAnyOrder_duplicate_elements_fails() { + @Test + fun containsExactlyInAnyOrder_duplicate_elements_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E(), 2.to$E())).containsExactlyInAnyOrder(2.to$E(), 1.to$E()) } @@ -230,7 +254,8 @@ class $TContainsTest { ) } - @Test fun containsExactlyInAnyOrder_duplicate_elements_fails2() { + @Test + fun containsExactlyInAnyOrder_duplicate_elements_fails2() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E())).containsExactlyInAnyOrder(2.to$E(), 2.to$E(), 1.to$E()) } @@ -241,7 +266,8 @@ class $TContainsTest { ) } - @Test fun containsExactlyInAnyOrder_more_elements_fails() { + @Test + fun containsExactlyInAnyOrder_more_elements_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E(), 3.to$E())).containsExactlyInAnyOrder(2.to$E(), 1.to$E()) } @@ -252,7 +278,8 @@ class $TContainsTest { ) } - @Test fun containsExactlyInAnyOrder_less_elements_fails() { + @Test + fun containsExactlyInAnyOrder_less_elements_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E(), 3.to$E())).containsExactlyInAnyOrder(2.to$E(), 1.to$E(), 3.to$E(), 4.to$E()) } @@ -264,7 +291,8 @@ class $TContainsTest { ) } - @Test fun containsExactlyInAnyOrder_different_elements_fails() { + @Test + fun containsExactlyInAnyOrder_different_elements_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E())).containsExactlyInAnyOrder(2.to$E()) } @@ -279,15 +307,18 @@ class $TContainsTest { //endregion //region each - @Test fun each_empty_list_passes() { + @Test + fun each_empty_list_passes() { assertThat($NOf()).each { it.isEqualTo(1) } } - @Test fun each_content_passes() { + @Test + fun each_content_passes() { assertThat($NOf(1.to$E(), 2.to$E())).each { it.isGreaterThan(0.to$E()) } } - @Test fun each_non_matching_content_fails() { + @Test + fun each_non_matching_content_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E(), 3.to$E())).each { it.isLessThan(2.to$E()) } } @@ -301,11 +332,13 @@ class $TContainsTest { //endregion //region index - @Test fun index_successful_assertion_passes() { + @Test + fun index_successful_assertion_passes() { assertThat($NOf(1.to$E(), 2.to$E()), name = "subject").index(0).isEqualTo(1.to$E()) } - @Test fun index_unsuccessful_assertion_fails() { + @Test + fun index_unsuccessful_assertion_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E()), name = "subject").index(0).isGreaterThan(2.to$E()) } @@ -315,7 +348,8 @@ class $TContainsTest { ) } - @Test fun index_out_of_range_fails() { + @Test + fun index_out_of_range_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E()), name = "subject").index(-1).isEqualTo(listOf(1.to$E())) } diff --git a/assertk/src/testTemplate/test/assertk/assertions/PrimativeArrayTest.kt b/assertk/src/testTemplate/test/assertk/assertions/PrimativeArrayTest.kt index ce087490..25374119 100644 --- a/assertk/src/testTemplate/test/assertk/assertions/PrimativeArrayTest.kt +++ b/assertk/src/testTemplate/test/assertk/assertions/PrimativeArrayTest.kt @@ -38,11 +38,13 @@ class $TTest { //endregion //region isNotEqualTo - @Test fun isNotEqualTo_different_contents_passes() { + @Test + fun isNotEqualTo_different_contents_passes() { assertThat($NOf(0.to$E())).isNotEqualTo($NOf(1.to$E())) } - @Test fun isNotEqualTo_same_contents_fails() { + @Test + fun isNotEqualTo_same_contents_fails() { val error = assertFailsWith { assertThat($NOf(0.to$E())).isNotEqualTo($NOf(0.to$E())) } @@ -51,11 +53,13 @@ class $TTest { //endregion //region isEmpty - @Test fun isEmpty_empty_passes() { + @Test + fun isEmpty_empty_passes() { assertThat($NOf()).isEmpty() } - @Test fun isEmpty_non_empty_fails() { + @Test + fun isEmpty_non_empty_fails() { val error = assertFailsWith { assertThat($NOf(0.to$E())).isEmpty() } @@ -64,11 +68,13 @@ class $TTest { //endregion //region isNotEmpty - @Test fun isNotEmpty_non_empty_passes() { + @Test + fun isNotEmpty_non_empty_passes() { assertThat($NOf(0.to$E())).isNotEmpty() } - @Test fun isNotEmpty_empty_fails() { + @Test + fun isNotEmpty_empty_fails() { val error = assertFailsWith { assertThat($NOf()).isNotEmpty() } @@ -77,15 +83,18 @@ class $TTest { //endregion //region isNullOrEmpty - @Test fun isNullOrEmpty_null_passes() { + @Test + fun isNullOrEmpty_null_passes() { assertThat(null as $T?).isNullOrEmpty() } - @Test fun isNullOrEmpty_empty_passes() { + @Test + fun isNullOrEmpty_empty_passes() { assertThat($NOf()).isNullOrEmpty() } - @Test fun isNullOrEmpty_non_empty_fails() { + @Test + fun isNullOrEmpty_non_empty_fails() { val error = assertFailsWith { assertThat($NOf(0.to$E())).isNullOrEmpty() } @@ -94,11 +103,13 @@ class $TTest { //endregion //region hasSize - @Test fun hasSize_correct_size_passes() { + @Test + fun hasSize_correct_size_passes() { assertThat($NOf()).hasSize(0) } - @Test fun hasSize_wrong_size_fails() { + @Test + fun hasSize_wrong_size_fails() { val error = assertFailsWith { assertThat($NOf()).hasSize(1) } @@ -107,11 +118,13 @@ class $TTest { //endregion //region hasSameSizeAs - @Test fun hasSameSizeAs_equal_sizes_passes() { + @Test + fun hasSameSizeAs_equal_sizes_passes() { assertThat($NOf()).hasSameSizeAs($NOf()) } - @Test fun hasSameSizeAs_non_equal_sizes_fails() { + @Test + fun hasSameSizeAs_non_equal_sizes_fails() { val error = assertFailsWith { assertThat($NOf()).hasSameSizeAs($NOf(0.to$E())) } @@ -120,15 +133,18 @@ class $TTest { //endregion //region each - @Test fun each_empty_list_passes() { + @Test + fun each_empty_list_passes() { assertThat($NOf()).each { it.isEqualTo(1) } } - @Test fun each_content_passes() { + @Test + fun each_content_passes() { assertThat($NOf(1.to$E(), 2.to$E())).each { it.isGreaterThan(0.to$E()) } } - @Test fun each_non_matching_content_fails() { + @Test + fun each_non_matching_content_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E(), 3.to$E())).each { it.isLessThan(2.to$E()) } } @@ -142,11 +158,13 @@ class $TTest { //endregion //region index - @Test fun index_successful_assertion_passes() { + @Test + fun index_successful_assertion_passes() { assertThat($NOf(1.to$E(), 2.to$E()), name = "subject").index(0).isEqualTo(1.to$E()) } - @Test fun index_unsuccessful_assertion_fails() { + @Test + fun index_unsuccessful_assertion_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E()), name = "subject").index(0).isGreaterThan(2.to$E()) } @@ -156,7 +174,8 @@ class $TTest { ) } - @Test fun index_out_of_range_fails() { + @Test + fun index_out_of_range_fails() { val error = assertFailsWith { assertThat($NOf(1.to$E(), 2.to$E()), name = "subject").index(-1).isEqualTo(listOf(1.to$E())) } diff --git a/assertk/src/wasmJsTest/kotlin/test/assertk/assertions/support/WasmJsSupportTest.kt b/assertk/src/wasmJsTest/kotlin/test/assertk/assertions/support/WasmJsSupportTest.kt index 3111c7ab..0da9c527 100644 --- a/assertk/src/wasmJsTest/kotlin/test/assertk/assertions/support/WasmJsSupportTest.kt +++ b/assertk/src/wasmJsTest/kotlin/test/assertk/assertions/support/WasmJsSupportTest.kt @@ -6,7 +6,8 @@ import kotlin.test.assertEquals class WasmJsSupportTest { - @Test fun show_byte_array() { + @Test + fun show_byte_array() { assertEquals("<[0x0A, 0x0F]>", show(byteArrayOf(10, 15))) } } \ No newline at end of file