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

Replace try-fail-catch pattern with nicer assertThatThrownBy #64

Open
iamdanfox opened this issue Feb 10, 2020 · 0 comments
Open

Replace try-fail-catch pattern with nicer assertThatThrownBy #64

iamdanfox opened this issue Feb 10, 2020 · 0 comments

Comments

@iamdanfox
Copy link
Contributor

iamdanfox commented Feb 10, 2020

What happened?

People write:


        try {
            Main.processArgs("-offset", "10", "-length", "20", "-length", "50", "Foo.java");
            fail("fail");
        } catch (UsageException e) {
            // expected
        }

e.g. https://github.com/palantir/palantir-java-format/blob/78e4387d65b232a2fbff3cf9c39fffc7167460ec/palantir-java-format/src/test/java/com/palantir/javaformat/java/CommandLineFlagsTest.java

What did you want to happen?

assertThatThrownBy(() -> Main.processArgs("-offset", "10", "-length", "20", "-length", "50", "Foo.java"))
                .isInstanceOf(UsageException.class);

Stretch goals:

  • preserving the message if it's interesting, e.g. fail("hardDeleteObjects should have thrown an exception");
  • supporting other types of fail e.g. raw junit fail e.g. org.junit.Assert#fail
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

No branches or pull requests

1 participant