Platform (jvm, js, android): jvm
Extension (none, kotlin 1.3, jdk8): kotlin 1.3
expect(Result.success(1)).isFailure<IllegalArgumentException>()
expect(Result.success(1)).isFailure<IllegalArgumentException> {
messageContains("hello world")
}
//instead of
expect(Result.success(1)).feature { f(it::exceptionOrNull) }.isA<IllegalArgumentException>()
expect(Result.success(1)).feature({ f(it::exceptionOrNull) }.isA<IllegalArgumentException> {
isGreaterThan(1)
isLessThan(5)
}
However in reporting we want to see for
expect(Result.success(1)).isFailure<IllegalArgumentException>()
the following
expect: Success(1)
◆ ▶ exception: ❗❗ is not a Failure
>> is instance of type: IllegalArgumentException
And for
expect(Result.success(1)).isFailure<IllegalArgumentException> {
messageContains("hello world")
}
the following
expect: Success(1)
◆ ▶ exception: ❗❗ is not a Failure
>> is instance of type: IllegalArgumentException
>> message:
>> contains: "hello world"
And for
expect(Result.failiure<Int>(UnsupportedOpertionException("NOP")))
.isFailure<IllegalArgumentException> { messageContains("hello world") }
the following
expect: Failure(java.lang.UnsupportedOpertionException: NOP)
◆ ▶ exception: UnsupportedOpertionException: NOP
>> is instance of type: IllegalArgumentException
>> message:
>> contains: "hello world"
And for
expect(Result.failiure<Int>(UnsupportedOpertionException("NOP")))
.isFailure<IllegalArgumentException> { messageContains("hello world") }
the following
expect: Failure(java.lang.IllegalArgumentException: NOP)
◆ ▶ exception: IllegalArgumentException: NOP
>> message:
>> contains: \"hello world\"
Following the things you need to do:
lib
ChangedSubjectPostStep<Throwable?, TExpected> where TExpected: Throwable by two steps (see fun0Assertions.kt -> isThrowing):exceptionOrNull manually (use exception as representation) with a custom representation in case it is null (via withOptions)IS_NOT_FAILURE("❗❗ is not a failure") to DescriptionResultAssertions for en_GBIS_NOT_FAILURE("❗❗ ist kein Fehler") to DescriptionResultAssertions for de_CHexpectedType: KClass<TExpected> as second argument) - use also the ThrowableThrownFailureHandler as for fun0Assertions.kt -> isThrowingdomain
isFailure which returns ChangedSubjectPostStep<Throwable?, TExpected> where TExpected: Throwable (see isSuccess as a guideline)api
assertionCreator-lambda and returns Expect@since 0.9.0 (adopt to next release version) to KDOC of val and fundescribe and context, see TODOs -- no need to cover the nullable case within the specs) and extend it in atrium-api-fluent-en_GB-common/src/testisFailure also compiles for a nullable Result type (e.g. Result<Int?>)I'll work on this if you would like to take this issue over.I will work on this
Please only one at a time so that other people taking part in hacktoberfest have a chance to deliver as well. Be fast with #203 and you can pick up this one as well :wink:
i will work on it.
@Anubhav007 do you need help? Un-assigning you so that others can take over
I could work on this
@robstoll, in the instructions, you mention that isFailure() should return ChangedSubjectPostStep but then you also say that its implementation should use ExpectImpl.feature.extractor... which returns an ExtractedFeaturePostStep.
Does this mean that the method's implementation should, first, use ExpectImpl.feature.extractor... to extract the exception from the Result, and then, use ExpectImpl.changeSubject... to assert the specified exception is indeed the one that was thrown?
@johnGachihi I probably have updated the description to use feature.extractor without changing the return type. Updated it now. I'll merge part of https://github.com/robstoll/atrium/pull/270 later this evening in order that you don't have to repeat this work. Have a look at it in case you want extra hints, it's very similar to your issue.
@johnGachihi please rebase on master, I have merged Result.isSuccess (see 6ef99c01 for details) and made some cleanup and added some TODOs for you.
I was actually wrong in my last comment, the domain will return ChangedSubjectPostStep as we need to narrow the subject down to the specific exception type (kind of what you expected).
I have updated the description again and I have also changed the steps in the description. It makes probably more sense to first implement the lib and then build on the upper layers based on it.
Thanks. The description makes better sense now.
implemented with 163071b