Suggestion: suggest hasValue for optionals #11

Closed
opened 2023-03-14 07:57:51 +01:00 by erikpragt-connectid · 1 comment
erikpragt-connectid commented 2023-03-14 07:57:51 +01:00 (Migrated from github.com)

We have the following code:

assertThat(response.getBody().get()).isEqualTo("pong");

where response.getBody() returns an optional String.

what I think would be a good suggestion, is the following:

assertThat(response.getBody()).hasValue("pong");

Could that be a reasonable addition to this plugin?

We have the following code: ``` assertThat(response.getBody().get()).isEqualTo("pong"); ``` where `response.getBody()` returns an optional String. what I think would be a good suggestion, is the following: ``` assertThat(response.getBody()).hasValue("pong"); ``` Could that be a reasonable addition to this plugin?
chrisly42 commented 2023-03-14 10:29:08 +01:00 (Migrated from github.com)

Hmmm... I'm confused. This should be included in the AssertThatJava8Optional inspection. From the Readme:

  from: assertThat(opt.get()).isEqualTo("foo");
    to: assertThat(opt).contains("foo");

It uses contains() though to which hasValue() is an alias.

I just checked the plugin manually and it does suggest the change in my case.

Can you produce a code fragment that does not come up with the inspection as expected? Thanks.

Hmmm... I'm confused. This should be included in the `AssertThatJava8Optional` inspection. From the Readme: ``` from: assertThat(opt.get()).isEqualTo("foo"); to: assertThat(opt).contains("foo"); ``` It uses contains() though to which hasValue() is an alias. I just checked the plugin manually and it does suggest the change in my case. Can you produce a code fragment that does not come up with the inspection as expected? Thanks.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: chrisly42/cajon-plugin#11
No description provided.