question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make the assertion lambdas Kotlin friendly

See original GitHub issue

Feature summary

Some assertions accept a functor:

public static <THROWABLE extends Throwable> THROWABLE catchThrowableOfType(ThrowingCallable shouldRaiseThrowable,
                                                                             Class<THROWABLE> type) {
    return AssertionsForClassTypes.catchThrowableOfType(shouldRaiseThrowable, type);
  }

Kotlin has a syntax for lambdas, so it could call:

catchThrowableOfType(NotFoundException::class.java) { 
    connectionService.findBy(hubId = "hub2", connId = "conn1") 
}

But as it is, it needs to stick with the less readable:

catchThrowableOfType( { 
    connectionService.findBy(hubId = "hub2", connId = "conn1") 
}, NotFoundException::class.java)

Could you please add some overrides, moving the functors to the last place? Like,

public static <THROWABLE extends Throwable> THROWABLE catchThrowableOfType(
         Class<THROWABLE> type, ThrowingCallable shouldRaiseThrowable) {
    return AssertionsForClassTypes.catchThrowableOfType(shouldRaiseThrowable, type);
  }

Thanks for considering.

AssertJ 3.23.11

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
scordiocommented, Oct 26, 2022

Team decision: let’s add catchThrowableOfType(Class<THROWABLE>, ThrowingCallable) and deprecate the existing catchThrowableOfType(ThrowingCallable, Class<THROWABLE>).

We believe that the readability of Java code can also benefit from this change.

@java-coding-prodigy would you like to take care of these changes?

0reactions
scordiocommented, Oct 26, 2022

I assume we will also replace existing calls of the method in our repo?

Yes, that would make sense.

Read more comments on GitHub >

github_iconTop Results From Across the Web

High-order functions and lambdas - Kotlin
Kotlin functions are first-class, which means they can be stored in variables and data structures, and can be passed as arguments to and ......
Read more >
Evolution from Java Method to Inline Lambda - YouTube
An overview discussion of lambdas in Kotlin. We start by looking at a Java method, and we convert it to a Kotlin function....
Read more >
Lambdas assigned to variables in Kotlin. Why? - Stack Overflow
When is it needed, recommended, advantageous to define a variable as a lambda rather than define a function to it?
Read more >
Using Kotlin in a Serverless Architecture with AWS Lambda ...
So far I have covered all the basics to set up, build and deploy your Serverless + Kotlin project using AWS Lambda as...
Read more >
Lambda Expressions in Kotlin - Baeldung
A quick and practical guide to Lambda Expressions in Kotlin. ... If we wanted to create a lambda that multiplies its single argument...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found