Skip to content

Commit

Permalink
SonarQube fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
edeandrea committed Jan 8, 2025
1 parent e3ffe5f commit 8146b6d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public Uni<Response> getFight(@Parameter(name = "id", required = true) @PathPara
Log.debugf("Found fight: %s", f);
return Response.ok(f).build();
})
.onItem().ifNull().continueWith(() -> {
.replaceIfNullWith(() -> {
Log.debugf("No fight found with id %s", id);
return Response.status(Status.NOT_FOUND).build();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public Uni<Response> getRandomHero() {
Log.debugf("Found random hero: %s", h);
return Response.ok(h).build();
})
.onItem().ifNull().continueWith(() -> {
.replaceIfNullWith(() -> {
Log.debug("No random villain found");
return Response.status(Status.NOT_FOUND).build();
});
Expand All @@ -100,7 +100,7 @@ public Uni<Response> getRandomHero() {
public Uni<List<Hero>> getAllHeroes(@Parameter(name = "name_filter", description = "An optional filter parameter to filter results by name") @QueryParam("name_filter") Optional<String> nameFilter) {
return nameFilter
.map(this.heroService::findAllHeroesHavingName)
.orElseGet(this.heroService::findAllHeroes)
.orElseGet(() -> this.heroService.findAllHeroes().replaceIfNullWith(List::of))
.invoke(heroes -> Log.debugf("Total number of heroes: %d", heroes.size()));
}

Expand All @@ -125,7 +125,7 @@ public Uni<Response> getHero(@Parameter(name = "id", required = true) @PathParam
Log.debugf("Found hero: %s", h);
return Response.ok(h).build();
})
.onItem().ifNull().continueWith(() -> {
.replaceIfNullWith(() -> {
Log.debugf("No hero found with id %d", id);
return Response.status(Status.NOT_FOUND).build();
});
Expand Down Expand Up @@ -200,7 +200,7 @@ public Uni<Response> fullyUpdateHero(
Log.debugf("Hero replaced with new values %s", h);
return Response.noContent().build();
})
.onItem().ifNull().continueWith(() -> {
.replaceIfNullWith(() -> {
Log.debugf("No hero found with id %d", hero.getId());
return Response.status(Status.NOT_FOUND).build();
});
Expand Down Expand Up @@ -279,7 +279,7 @@ public Uni<Response> partiallyUpdateHero(
Log.debugf("Hero updated with new values %s", h);
return Response.ok(h).build();
})
.onItem().ifNull().continueWith(() -> {
.replaceIfNullWith(() -> {
Log.debugf("No hero found with id %d", hero.getId());
return Response.status(Status.NOT_FOUND).build();
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,9 @@ void shouldGetEmptyItemsWithNameFilter() {
@Test
void shouldGetNullItems() {
when(this.heroService.findAllHeroes())
.thenReturn(Uni.createFrom().item(List.of()));
.thenReturn(Uni.createFrom().nullItem());

get("/api/heroes")
.then()
get("/api/heroes").then()
.statusCode(OK.getStatusCode())
.body("$.size()", is(0));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void narrateWithTimeout() {
.withHeader("openai-organization", "my-org-1234")
.withHeader("openai-version", "2020-10-01")
.withHeader("openai-processing-ms", "15000")
.withFixedDelay(Long.valueOf(this.timeout.multipliedBy(2).toMillis()).intValue())
.withFixedDelay((int) this.timeout.multipliedBy(2).toMillis())
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,20 +327,6 @@ void shouldGetEmptyItemsWithNameFilter() {
verifyNoMoreInteractions(this.villainService);
}

@Test
void shouldGetNullItems() {
when(this.villainService.findAllVillains())
.thenReturn(List.of());

get("/api/villains")
.then()
.statusCode(OK.getStatusCode())
.body("$.size()", is(0));

verify(this.villainService).findAllVillains();
verifyNoMoreInteractions(this.villainService);
}

@Test
void shouldAddAnItem() {
ArgumentMatcher<Villain> villainMatcher = v ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void findRandomVillainFound() {
@Test
void persistNullVillain() {
PanacheMock.mock(Villain.class);
var cve = catchThrowableOfType(() -> this.villainService.persistVillain(null), ConstraintViolationException.class);
var cve = catchThrowableOfType(ConstraintViolationException.class, () -> this.villainService.persistVillain(null));

assertThat(cve)
.isNotNull();
Expand Down Expand Up @@ -274,7 +274,7 @@ void persistInvalidVillain() {
var villain = createDefaultVillian();
villain.name = "a";

var cve = catchThrowableOfType(() -> this.villainService.persistVillain(villain), ConstraintViolationException.class);
var cve = catchThrowableOfType(ConstraintViolationException.class, () -> this.villainService.persistVillain(villain));

assertThat(cve)
.isNotNull();
Expand Down Expand Up @@ -334,7 +334,7 @@ void persistVillain() {
@Test
void fullyUpdateNullVillain() {
PanacheMock.mock(Villain.class);
var cve = catchThrowableOfType(() -> this.villainService.replaceVillain(null), ConstraintViolationException.class);
var cve = catchThrowableOfType(ConstraintViolationException.class, () -> this.villainService.replaceVillain(null));

assertThat(cve)
.isNotNull();
Expand Down Expand Up @@ -368,7 +368,7 @@ void fullyUpdateInvalidVillain() {
var villain = createDefaultVillian();
villain.name = null;

var cve = catchThrowableOfType(() -> this.villainService.replaceVillain(villain), ConstraintViolationException.class);
var cve = catchThrowableOfType(ConstraintViolationException.class, () -> this.villainService.replaceVillain(villain));

assertThat(cve)
.isNotNull();
Expand Down Expand Up @@ -445,7 +445,7 @@ void fullyUpdateVillain() {
@Test
void partiallyUpdateNullVillain() {
PanacheMock.mock(Villain.class);
var cve = catchThrowableOfType(() -> this.villainService.partialUpdateVillain(null), ConstraintViolationException.class);
var cve = catchThrowableOfType(ConstraintViolationException.class, () -> this.villainService.partialUpdateVillain(null));

assertThat(cve)
.isNotNull();
Expand Down Expand Up @@ -480,7 +480,7 @@ void partiallyUpdateInvalidVillain() {
var villain = createDefaultVillian();
villain.name = "a";

var cve = catchThrowableOfType(() -> this.villainService.partialUpdateVillain(villain), ConstraintViolationException.class);
var cve = catchThrowableOfType(ConstraintViolationException.class, () -> this.villainService.partialUpdateVillain(villain));

assertThat(cve)
.isNotNull();
Expand Down

0 comments on commit 8146b6d

Please sign in to comment.