Skip to content

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

Open
@iamdanfox

Description

@iamdanfox

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions