Skip to content

Commit

Permalink
Fix sonar code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
lkleisa committed Jun 6, 2024
1 parent 77fdbc8 commit b5e474c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ private void throwExceptionWhenAlignedObjectIsNull(Alignment model) {
throw new OkrResponseStatusException(HttpStatus.BAD_REQUEST, ErrorKey.ATTRIBUTE_NULL,
List.of("targetObjectiveId", objectiveAlignment.getAlignedObjective().getId()));
}
} else if (model instanceof KeyResultAlignment keyResultAlignment) {
if (keyResultAlignment.getAlignmentTarget() == null) {
throw new OkrResponseStatusException(HttpStatus.BAD_REQUEST, ErrorKey.ATTRIBUTE_NULL,
List.of("targetKeyResultId", keyResultAlignment.getAlignedObjective().getId()));
}
} else if (model instanceof KeyResultAlignment keyResultAlignment
&& (keyResultAlignment.getAlignmentTarget() == null)) {
throw new OkrResponseStatusException(HttpStatus.BAD_REQUEST, ErrorKey.ATTRIBUTE_NULL,
List.of("targetKeyResultId", keyResultAlignment.getAlignedObjective().getId()));

}
}

Expand All @@ -85,12 +85,12 @@ private void throwExceptionWhenAlignmentIsInSameTeam(Alignment model) {
}

private void throwExceptionWhenAlignedIdIsSameAsTargetId(Alignment model) {
if (model instanceof ObjectiveAlignment objectiveAlignment) {
if (Objects.equals(objectiveAlignment.getAlignedObjective().getId(),
objectiveAlignment.getAlignmentTarget().getId())) {
throw new OkrResponseStatusException(HttpStatus.BAD_REQUEST, ErrorKey.NOT_LINK_YOURSELF,
List.of("targetObjectiveId", objectiveAlignment.getAlignmentTarget().getId()));
}
if (model instanceof ObjectiveAlignment objectiveAlignment
&& (Objects.equals(objectiveAlignment.getAlignedObjective().getId(),
objectiveAlignment.getAlignmentTarget().getId()))) {
throw new OkrResponseStatusException(HttpStatus.BAD_REQUEST, ErrorKey.NOT_LINK_YOURSELF,
List.of("targetObjectiveId", objectiveAlignment.getAlignmentTarget().getId()));

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AlignmentPersistenceServiceIT {
@Autowired
private AlignmentPersistenceService alignmentPersistenceService;
private Alignment createdAlignment;
private final String ALIGNMENT = "alignment";

private static ObjectiveAlignment createObjectiveAlignment(Long id) {
return ObjectiveAlignment.Builder.builder().withId(id)
Expand Down Expand Up @@ -102,7 +103,7 @@ void updateAlignmentShouldThrowExceptionWhenAlreadyUpdated() {
OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class,
() -> alignmentPersistenceService.save(updateAlignment));

List<ErrorDto> expectedErrors = List.of(new ErrorDto("DATA_HAS_BEEN_UPDATED", List.of("Alignment")));
List<ErrorDto> expectedErrors = List.of(new ErrorDto("DATA_HAS_BEEN_UPDATED", List.of(ALIGNMENT)));

assertEquals(UNPROCESSABLE_ENTITY, exception.getStatusCode());
assertThat(expectedErrors).hasSameElementsAs(exception.getErrors());
Expand All @@ -114,7 +115,7 @@ void findByAlignedObjectiveIdShouldReturnAlignmentModel() {
Alignment alignment = alignmentPersistenceService.findByAlignedObjectiveId(4L);

assertNotNull(alignment);
assertEquals(alignment.getAlignedObjective().getId(), 4);
assertEquals(4, alignment.getAlignedObjective().getId());
}

@Test
Expand Down Expand Up @@ -162,7 +163,7 @@ void recreateEntityShouldUpdateAlignmentNoTypeChange() {
() -> alignmentPersistenceService.findById(alignmentId));

List<ErrorDto> expectedErrors = List
.of(ErrorDto.of("MODEL_WITH_ID_NOT_FOUND", List.of("Alignment", alignmentId)));
.of(ErrorDto.of("MODEL_WITH_ID_NOT_FOUND", List.of(ALIGNMENT, alignmentId)));

assertEquals(NOT_FOUND, exception.getStatusCode());
assertThat(expectedErrors).hasSameElementsAs(exception.getErrors());
Expand Down Expand Up @@ -202,7 +203,7 @@ void recreateEntityShouldUpdateAlignmentWithTypeChange() {
() -> alignmentPersistenceService.findById(alignmentId));

List<ErrorDto> expectedErrors = List
.of(ErrorDto.of("MODEL_WITH_ID_NOT_FOUND", List.of("Alignment", alignmentId)));
.of(ErrorDto.of("MODEL_WITH_ID_NOT_FOUND", List.of(ALIGNMENT, alignmentId)));

assertEquals(NOT_FOUND, exception.getStatusCode());
assertThat(expectedErrors).hasSameElementsAs(exception.getErrors());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export class ObjectiveFormComponent implements OnInit {
this.alignmentPossibilities$ = this.objectiveService.getAlignmentPossibilities(quarterId);
this.alignmentPossibilities$.subscribe((value: AlignmentPossibility[]) => {
if (teamId) {
value = value.filter((item: AlignmentPossibility) => !(item.teamId == teamId));
value = value.filter((item: AlignmentPossibility) => item.teamId != teamId);
}

if (objective) {
Expand Down

0 comments on commit b5e474c

Please sign in to comment.