Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use AssertJ for assertions #134

Merged
merged 1 commit into from Jul 18, 2020
Merged

Use AssertJ for assertions #134

merged 1 commit into from Jul 18, 2020

Conversation

stefanbirkner
Copy link
Contributor

Improve the readability of tests. E.g.

assertThat(actualPlugins)
    .containsExactlyInAnyOrder(
        new Plugin("workflow-scm-step", "2.4", null, null),
        new Plugin("workflow-step-api", "2.20", null, null));

is easier to read than

List<Plugin> expectedPlugins = Arrays.asList(
    new Plugin("workflow-scm-step", "2.4", null, null),
    new Plugin("workflow-step-api", "2.20", null, null));
assertEquals(expectedPlugins, actualPlugins);

and also more specific because it explicitly states that the order does
not matter.

Also the messages for failing tests is more helpful than the current
one. E.g. if the assertion from above fails it prints an error like

Expecting:
  <[workflow-scm-step 2.4]>
to contain exactly in any order:
  <[workflow-scm-step 2.4, workflow-step-api 2.20]>
but could not find the following elements:
  <[workflow-step-api 2.20]>

so that it is immediately clear that one plugin is missing.

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.16.1</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to manage this version in the parent in a dependencyManagement block

as it's shared between the cli and library

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I updated the commit.

@timja timja added the chore Project maintenance label Jul 16, 2020
Improve the readability of tests. E.g.

    assertThat(actualPlugins)
        .containsExactlyInAnyOrder(
            new Plugin("workflow-scm-step", "2.4", null, null),
            new Plugin("workflow-step-api", "2.20", null, null));

is easier to read than

    List<Plugin> expectedPlugins = Arrays.asList(
        new Plugin("workflow-scm-step", "2.4", null, null),
        new Plugin("workflow-step-api", "2.20", null, null));
    assertEquals(expectedPlugins, actualPlugins);

and also more specific because it explicitly states that the order does
not matter.

Also the messages for failing tests is more helpful than the current
one. E.g. if the assertion from above fails it prints an error like

    Expecting:
      <[workflow-scm-step 2.4]>
    to contain exactly in any order:
      <[workflow-scm-step 2.4, workflow-step-api 2.20]>
    but could not find the following elements:
      <[workflow-step-api 2.20]>

so that it is immediately clear that one plugin is missing.
@timja timja merged commit 3cb8315 into jenkinsci:master Jul 18, 2020
@stefanbirkner stefanbirkner deleted the assertj branch July 18, 2020 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Project maintenance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants