Atrium: Result.isSuccess

Created on 10 Oct 2019  Â·  13Comments  Â·  Source: robstoll/atrium

Platform (jvm, js, android): jvm
Extension (none, kotlin 1.3, jdk8): kotlin 1.3

Code related feature

Similar as #113

expect(Result.success(1)).isSuccess()
expect(Result.success(1)).isSuccess {
  isGreaterThan(1)  
  isLessThan(5)
}

//instead of

expect(Result.success(1)).feature { f(it::getOrNull) }.notToBeNull()
expect(Result.success(1)).feature({ f(it::getOrNull) }.notToBeNull {
    isGreaterThan(1)  
    isLessThan(5)
}

However in reporting we want to see for

expect(Result.failure<Int>(IllegalArgumentException())).isSuccess()

the following

expect: Failure(java.lang.IllegalArgumentException)        (kotlin.Result <1651855867>)
◆ unboxed: !! not a Success

And for

expect(Result.failure<Int>(IllegalArgumentException())).isSuccess {
    isGreaterThan(1)
    isLessThan(5)
}

the following

expect: Failure(java.lang.IllegalArgumentException)        (kotlin.Result <459857341>)
◆ ▶ unboxed: !! not a Success
      » is greater than: 1        (kotlin.Int <1392425346>)
      » is less than: 5        (kotlin.Int <2054574951>)

And for

expect(Result.success(0)).isSuccess {
    isGreaterThan(1)
    isLessThan(5)
}

the following:

expect: Success(0)        (kotlin.Result <1518864111>)
◆ ▶ unboxed: 0        (kotlin.Int <1685232414>)
    ◾ is greater than: 1        (kotlin.Int <1754638213>)

Following the things you need to do:

domain

  • extend ResultAssertions with a function isSuccess which returns ExtractedFeaturePostStep<T, E> whereT: Result` (see ListAssertions.get as a guideline)
  • modify ResultAssertionsBuilder, delegate to resultAssertions (see ListAssertionsBuilder.get as a guideline)
  • delegate implementation to robstoll-lib in ResultAssertionsImpl (see ListAssertionsImpl.get as a guideline)
  • register ResultAssertionsImpl as ServiceLoader Service (meaning, add the file under src/main/resources/META-INF/services -> see atrium-domain-robstoll-jvm)

lib

  • implement _isSuccess in resultAssertions by using the ExpectImpl.feature.extractor...

api

  • provide a val which returns Expect (see listAssertions.kt -> get as a guideline)
  • provide a fun which expects an assertionCreator-lambda and returns Expect (see listAssertions.kt -> get as a guideline)
  • add @since 0.9.0 (adopt to next release version) to KDOC of val and fun
  • extend or write a separate Spec named ResultFeatureAssertionsSpec in specs-common (see for instance ListFeatureAssertionsSpec) and extend it in atrium-api-fluent-en_GB-common/src/test

Your first contribution?

  • Write a comment I'll work on this if you would like to take this issue over.
    This way we get the chance to revise the description in case things have changed in the meantime,
    we might give you additional hints and we can assign the task to you, so that others do not start as well.
  • See Your first code contribution for guidelines.
  • Do not hesitate to ask questions here or to contact us via Atrium's slack channel if you need help
    (Invite yourself in case you do not have an account yet).
good first issue help wanted

All 13 comments

I will work on this

A couple of things here
1) There is no class : ExtractedFeatureOption so using ExtractedFeaturePostStep.
2) After referring to the implementation of get in listAssertions,
For the method _isSuccess() in file resultsAssertions.kt, after line 15, i have to write .withRepresentationForFailure(). And can you suggest me a parameter in that option, as there is no DescriptionListAssertion equivalent for result assertions

  1. :heavy_check_mark: sorry, copied from another task where it was probably named this way (at that time)
  2. Introduce DescriptionResultAssertion (for en_GB and de_CH) and make a suggestion.

ps: I have updated the description for domain, note that you have to register ResultAssertionsImpl as service

@robstoll :

  1. I have added the DescriptionResultAssertion.kt in en_GB for now. Please let me know if it is ok.
  2. I have added the implementation for _isSuccess(), but I am getting an error as
    Required : ExtractedFeaturePostStep<T, E>
    Found : ExtractedFeaturePostStep<T, E?>
    Attached an image for the same.

I have a small idea about the null saftey in kotlin, but I couldn't think of a way to fix this one.

image

See review in the PR and please open up a new one where your PR is based on the latest version of the master branch (also see link in the PR for help)

I have created a new PR with the mentioned changes.

expect: Failure(java.lang.IllegalArgumentException)        (kotlin.Result <1651855867>)
◆ unboxed: !! not a Success

However I think that even Using unboxed here is not 100% clear for some one who is using this feature for the 1st time.
I am not sure what could be the correct word there, I think it could be.

expect: Failure(java.lang.IllegalArgumentException)        (kotlin.Result <1651855867>)
◆ The result is : not a Success

Also when I run a build I get an error :

Task :atrium-domain-robstoll-js:compileKotlin2Js FAILED
e: D:\SRH\shardulsonar-atrium\domain\robstoll\atrium-domain-robstoll-js\src\main\kotlin\ch\tutteli\atrium\domain\robstoll\registerServices.kt: (40, 46): Unresolved reference: kotlin_1_3
e: D:\SRH\shardulsonar-atrium\domain\robstoll\atrium-domain-robstoll-js\src\main\kotlin\ch\tutteli\atrium\domain\robstoll\registerServices.kt: (40, 120): Unresolved reference: kotlin_1_3

However I think that even Using unboxed here is not 100% clear for some one who is using this feature for the 1st time.

I think you are right as unboxed does not include the assumption of the developer that it is a Success. The same goes for your suggestion The result is IMO. What do you think about the following two? Which one do you like more:

expect: Failure(java.lang.IllegalArgumentException)        (kotlin.Result <1651855867>)
◆ unboxed Success: !! not a Success

Or

expect: Failure(java.lang.IllegalArgumentException)        (kotlin.Result <1651855867>)
â—† value: !! cannot access `value` as it is no a Success

I would suggest we use this :

expect: Failure(java.lang.IllegalArgumentException)        (kotlin.Result <1651855867>)
â—† value: !! cannot access `value` as it is no a Success

Good, let me know when I shall re-review your WIP and keep on having fun coding 🙂

I have pushed the code and resolved the comments that were suggested earlier.
But I still have an issue with the building of the application. I have mentioned it in the WIP Pull Request.

@robstoll

I have added all the changes mentioned (except the test cases).

But now I have 3 Issues :

1) _I am getting a compilation error on the _isSuccess() implementation_

Required : ExtractedFeaturePostStep
Found : ExtractedFeaturePostStep

2) _I am unable to build the project (./gr build) :_

Task :atrium-api-fluent-en_GB-kotlin_1_3-jvm:compileKotlin FAILED
e: D:\SRH\shardulsonar-atrium\apis\fluent-en_GB\extensions\kotlin_1_3\atrium-api-fluent-en_GB-kotlin_1_3-common\src\main\kotlin\ch\tutteli\atrium\api\fluent\en_GB\kotlin_1_3\resultAssertions.kt: (14, 70): Symbol is declared in module 'ch.tutteli.atrium.domain.builders.kotlin_1_3' which does not export package 'ch.tutteli.atrium.domain.builders.kotlin_1_3'
e: D:\SRH\shardulsonar-atrium\apis\fluent-en_GB\extensions\kotlin_1_3\atrium-api-fluent-en_GB-kotlin_1_3-common\src\main\kotlin\ch\tutteli\atrium\api\fluent\en_GB\kotlin_1_3\resultAssertions.kt: (24, 16): Symbol is declared in module 'ch.tutteli.atrium.domain.builders.kotlin_1_3' which does not export package 'ch.tutteli.atrium.domain.builders.kotlin_1_3'
When I run generateJsRegisterNewServices (./gr generateJsRegisterServices) :
I get an error as

3) _Another problem was found with the configuration of task ':atrium-domain-robstoll-kotlin_1_3-js:generateJsRegisterServices'._

File 'D:\SRH\shardulsonar-atrium\domain\robstoll\extensions\kotlin_1_3\atrium-domain-robstoll-kotlin_1_3-js\src\main\kotlin\ch\tutteli\atrium\domain\kotlin_1_3\registerServices.kt' specified for property '$2' does not exist.
Here the $2 means the

createRegisterJsServicesTask('domain-robstoll-kotlin_1_3-js', 'ch.tutteli.atrium.domain.kotlin_1_3') { true }

on the build.gradle file

I am unable to figure out how to fix this build issue .
Whenever you have time, could you please have a look at my branch and let me know what is going wrong ?
Thanks for your help

Implemented with 6ef99c01

Was this page helpful?
0 / 5 - 0 ratings

Related issues

robstoll picture robstoll  Â·  6Comments

robstoll picture robstoll  Â·  5Comments

robstoll picture robstoll  Â·  4Comments

robstoll picture robstoll  Â·  4Comments

robstoll picture robstoll  Â·  4Comments