Skip to content

Conversation

@aliJavaTar
Copy link

@aliJavaTar aliJavaTar commented Jul 4, 2025

Refactored the verifyMeterNotFoundException method in MicrometerStatisticsTest to use assertThrows instead of a try-catch block.

This improves readability and aligns with modern JUnit testing best practices.

Before:

try {
    registry.get(name).meter();
    Assert.fail(name + " should not have been found");
}
catch (MeterNotFoundException mnfe) {
}

---

### ✅ Final Code: New `verifyMeterNotFoundException`

You already wrote it correctly! Here's the cleaned-up version for clarity:

```java
void verifyMeterNotFoundException(String name) {
    MeterNotFoundException exception = assertThrows(
        MeterNotFoundException.class,
        () -> registry.get(name).meter(),
        name + " should not have been found"
    );
    assertTrue(exception.getMessage().contains(name));
}

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


https://hibernate.atlassian.net/browse/HHH-19591

@beikov beikov merged commit aef67ae into hibernate:main Jul 8, 2025
22 of 24 checks passed
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