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

Maintenance/use more junit5 features #518

Merged

Conversation

jens-kaiser
Copy link
Contributor

Many Junit 5 features are not used in existing tests because the structures from JUnit 4 are still being implemented.
Mocks and other values e.g. can be injected directly into the tests without using the Mockito.mock method or class attributes.

@jens-kaiser jens-kaiser changed the title Maintenance/user more junit5 features Maintenance/use more junit5 features Nov 26, 2024
@jens-kaiser jens-kaiser requested a review from F43nd1r November 28, 2024 13:53
Copy link

codecov bot commented Nov 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.16%. Comparing base (7904764) to head (8b81231).
Report is 67 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #518      +/-   ##
============================================
+ Coverage     82.11%   82.16%   +0.04%     
+ Complexity      478      390      -88     
============================================
  Files            86       85       -1     
  Lines          1068      953     -115     
  Branches         70       68       -2     
============================================
- Hits            877      783      -94     
+ Misses          156      144      -12     
+ Partials         35       26       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@denniseffing denniseffing self-requested a review December 6, 2024 08:48
Copy link
Contributor

@WtfJoke WtfJoke left a comment

Choose a reason for hiding this comment

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

I finally found the time to check it out in more detail. I've left some comments.
The changes overall looks good, thanks for that 👍

There aren't really blocking points in my opinion, despite the @Disabled test and the comment/review from @denniseffing.

After that feel free to (squash :D) merge (or address some of the further comments) :)

@@ -48,6 +50,9 @@ public void setup() {
when(greetingServiceMock.greet()).thenReturn(responseService);
responseRepo = "Hello from repo!";
when(greetingServiceMock.greetFromRepo()).thenReturn(responseRepo);
when(greetingServiceMock.greetFromRepoPagingSorting()).thenReturn(responseRepo);
when(greetingServiceMock.greetFromRepoJpa()).thenReturn(responseRepo);
when(greetingServiceMock.greetFromRepoAnnotation()).thenReturn(responseRepo);
Copy link
Contributor

Choose a reason for hiding this comment

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

We could also move this to the parametrized test below, because its only used there. However no hard feelings in keeping it here :D

@SpringBootTest(properties = {"chaos.monkey.enabled=true", "chaos.monkey.watcher.rest-template=true", "chaos.monkey.assaults.latency-active=true",
"chaos.monkey.test.rest-template.time-out=20"}, classes = {ChaosDemoApplication.class})
@ActiveProfiles("chaos-monkey")
static class LatencyAssaultIntegrationTest {
@Nested
@Disabled
Copy link
Contributor

@WtfJoke WtfJoke Dec 6, 2024

Choose a reason for hiding this comment

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

I guess that was added by accident? However it seems that the Exception has changed from SSLException to io.netty.handler.timeout.ReadTimeoutException

EDIT: This seems to work:

assertThatThrownBy(() ->  demoRestTemplateService.callWithRestTemplate()).isInstanceOf(ReadTimeoutException.class);

@Mock
private Advice advice;
@Mock
private ChaosMonkeyBaseClassFilter baseClassFilter;
Copy link
Contributor

Choose a reason for hiding this comment

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

Good changes 👍


import static org.junit.jupiter.api.Assertions.*;

class HelloComponentTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Which value adds this test? 😅 if its only to get codecov happy I would simply drop it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But if codecov drops down, you have to merge it anyway

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah codecov cant stop us 👿 😄 we merge it!

never stop

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do-it1

Copy link
Contributor

@WtfJoke WtfJoke Dec 6, 2024

Choose a reason for hiding this comment

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

if you fix that, im happy to merge it (or you can on your own if you like) :D

@@ -35,7 +37,7 @@ public class HelloControllerTest {
@Autowired
private MockMvc mockMvc;

@MockBean
@MockitoBean
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please do this change for the remaining @MockBean as well if possible? 🙃🙏

final int latencyRangeStart = 1000;
final int latencyRangeEnd = 5000;
@Mock
ApplicationEventPublisher applicationEventPublisher;
Copy link
Contributor

Choose a reason for hiding this comment

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

Personal taste: I would add private to every member variable here


assertThat(settings.getChaosMonkeyProperties()).isNotNull();
Copy link
Contributor

@WtfJoke WtfJoke Dec 6, 2024

Choose a reason for hiding this comment

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

Not really sure, why this test existed before, however dont we need these notnull checks still in a test (allArgsTest?)?

BDDAssertions.then(watcherProperties.isRestTemplate()).isTrue();
BDDAssertions.then(watcherProperties.isWebClient()).isTrue();
BDDAssertions.then(watcherProperties.isActuatorHealth()).isTrue();
assertAll(() -> assertEquals(HttpStatus.OK, response.getStatusCode()), () -> assertTrue(watcherProperties.isController()),
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@jens-kaiser jens-kaiser self-assigned this Dec 6, 2024
@jens-kaiser jens-kaiser enabled auto-merge (squash) December 6, 2024 14:35
@jens-kaiser jens-kaiser removed their assignment Dec 6, 2024
@jens-kaiser jens-kaiser requested a review from F43nd1r December 6, 2024 14:36
Copy link
Contributor

@WtfJoke WtfJoke left a comment

Choose a reason for hiding this comment

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

LGTM 🐼

@jens-kaiser jens-kaiser merged commit d25b0e3 into codecentric:main Dec 6, 2024
9 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.

4 participants