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

chore(test): Replace try/fail/catch/assert with assertThat #199

Merged
merged 7 commits into from
Oct 3, 2023

Conversation

guicamest
Copy link
Contributor

Description of changes:
This PR replaces several occurrences of the idiom:

try {
  ... // do something that throws an Exception
  fail() // with some message to display because the exception should have been thrown
} catch ( someException ){
  ... // some assertion on the exception
}

with a couple of assertion methods provided by AssertJ (assertThatCode, assertThatThrownBy) and JUnit (assertThrows) which are already part of the dependencies of the project.

Before:

        try {
            provider.newFileSystem(URI.create(pathUri));
            fail("filesystem created twice!");
        } catch (FileSystemAlreadyExistsException x) {
            assertTrue(x.getMessage().contains("'foo'"));
        }

After:

assertThatCode(() -> provider.newFileSystem(URI.create(pathUri)))
                .as("filesystem created twice!")
                .isInstanceOf(FileSystemAlreadyExistsException.class)
                .hasMessageContaining("'foo'");

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link
Contributor

@markjschreiber markjschreiber left a comment

Choose a reason for hiding this comment

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

Nice refactoring to assertJ idioms. Thanks!

@markjschreiber markjschreiber merged commit 3f2db3e into awslabs:main Oct 3, 2023
1 check passed
@guicamest guicamest deleted the replaceTryCatchInTests branch October 3, 2023 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants