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

ReflectionTestUtils: Testing exceptions in constructors #257

Closed
alpkaanaksu opened this issue Dec 2, 2022 · 0 comments
Closed

ReflectionTestUtils: Testing exceptions in constructors #257

alpkaanaksu opened this issue Dec 2, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@alpkaanaksu
Copy link

Is your feature request related to a problem? Please describe.
I wanted to test that a constructor throws an IllegalArgumentException, there is no method in ReflectionTestUtils to do that.

Describe the solution you'd like
A new method (e.g. newInstanceRethrowing), which rethrows the underlying exception (cause), if a problem occurs during instantiation. We would be able to use assertThrows with that method.

Describe alternatives you've considered
I created a method myself:

public static <T extends Throwable> void assertConstructorThrowsException(String message, Class<T> exception, Constructor<?> constructor, Object... arguments) {
        assertThrows(exception, () -> {
            try {
                constructor.newInstance(arguments);
            } catch (InvocationTargetException | InstantiationException | IllegalAccessException e) {
                throw e.getCause();
            }
        }, message);
    }

Ares-Version you are using
1.11.0

@MaisiKoleni MaisiKoleni added the enhancement New feature or request label Dec 11, 2022
@MaisiKoleni MaisiKoleni added this to the Version 1.11.1 milestone Dec 11, 2022
@MaisiKoleni MaisiKoleni self-assigned this Dec 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants