Skip to content

Commit

Permalink
Add displayname annotation to each test in the service.validation pac…
Browse files Browse the repository at this point in the history
…kage
  • Loading branch information
MasterEvarior committed Dec 18, 2024
1 parent 05b6d67 commit 04011c5
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ch.puzzle.okr.models.keyresult;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ void setUp() {
Mockito.lenient().when(actionPersistenceService.getModelName()).thenReturn("Action");
}

@DisplayName("should be successful on validateOnCreate() when action is valid")
@Test
void validateOnCreateShouldBeSuccessfulWhenActionIsValid() {
validator.validateOnCreate(action1);
Expand All @@ -116,6 +117,7 @@ void validateOnCreateShouldBeSuccessfulWhenActionIsValid() {
verify(validator, times(1)).validate(action1);
}

@DisplayName("should throw exception on validateOnCreate() when model is null")
@Test
void validateOnCreateShouldThrowExceptionWhenModelIsNull() {
// arrange
Expand All @@ -128,6 +130,7 @@ void validateOnCreateShouldThrowExceptionWhenModelIsNull() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("should be successful on validateOnCreate() when id is not null")
@Test
void validateOnCreateShouldThrowExceptionWhenIdIsNotNull() {
// arrange
Expand All @@ -140,7 +143,7 @@ void validateOnCreateShouldThrowExceptionWhenIdIsNotNull() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@ParameterizedTest
@ParameterizedTest(name = "should throw exception on validateOnCreate() when model has invalid text {0}")
@MethodSource("actionValidationArguments")
void validateOnCreateShouldThrowExceptionWhenActionIsInvalid(String actionText, List<ErrorDto> errors) {
// arrange
Expand All @@ -154,6 +157,7 @@ void validateOnCreateShouldThrowExceptionWhenActionIsInvalid(String actionText,
assertOkrResponseStatusException(exception, errors);
}

@DisplayName("should throw exception on validateOnCreate() when attributes are missing")
@Test
void validateOnCreateShouldThrowExceptionWhenAttrsAreMissing() {
// arrange
Expand All @@ -169,6 +173,7 @@ void validateOnCreateShouldThrowExceptionWhenAttrsAreMissing() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("should be successful on validateOnUpdate() when action is valid")
@Test
void validateOnUpdateShouldBeSuccessfulWhenActionIsValid() {
// arrange
Expand All @@ -186,6 +191,7 @@ void validateOnUpdateShouldBeSuccessfulWhenActionIsValid() {
verify(validator, times(1)).validate(action2);
}

@DisplayName("should throw exception on validateOnUpdate() when model is null")
@Test
void validateOnUpdateShouldThrowExceptionWhenModelIsNull() {
// arrange
Expand All @@ -198,6 +204,7 @@ void validateOnUpdateShouldThrowExceptionWhenModelIsNull() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("should throw exception on validateOnUpdate() when id is null")
@Test
void validateOnUpdateShouldThrowExceptionWhenIdIsNull() {
// act + assert
Expand All @@ -212,6 +219,7 @@ void validateOnUpdateShouldThrowExceptionWhenIdIsNull() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("should throw exception on validateOnUpdate() when id has changed")
@Test
void validateOnUpdateShouldThrowExceptionWhenIdHasChanged() {
// act + assert
Expand All @@ -227,6 +235,7 @@ void validateOnUpdateShouldThrowExceptionWhenIdHasChanged() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("should throw exception on validateOnUpdate() when no entity can be found")
@Test
void validateOnUpdateShouldThrowExceptionWhenEntityDoesNotExist() {
// arrange
Expand All @@ -246,7 +255,7 @@ void validateOnUpdateShouldThrowExceptionWhenEntityDoesNotExist() {
assertEquals("MODEL_WITH_ID_NOT_FOUND", exception.getReason());
}

@DisplayName("validateOnUpdate() should throw exception when KeyResult is not set")
@DisplayName("should throw exception on validateOnUpdate() when KeyResult is not set")
@ParameterizedTest
@MethodSource("actionPairArgument")
void validateOnUpdateShouldThrowExceptionWhenKeyResultNotSet(ActionPair actionPair) {
Expand All @@ -270,6 +279,7 @@ void validateOnUpdateShouldThrowExceptionWhenKeyResultNotSet(ActionPair actionPa
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("should throw exception on validateOnUpdate() when key result id has changed")
@Test
void validateOnUpdateShouldThrowExceptionWhenKeyResultIdHasChanged() {
// arrange
Expand All @@ -291,7 +301,7 @@ void validateOnUpdateShouldThrowExceptionWhenKeyResultIdHasChanged() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@ParameterizedTest
@ParameterizedTest(name = "should throw exception on validateOnUpdate() when model has invalid text {0}")
@MethodSource("actionValidationArguments")
void validateOnUpdateShouldThrowExceptionWhenTitleIsInvalid(String actionText, List<ErrorDto> errors) {
// arrange
Expand All @@ -305,6 +315,7 @@ void validateOnUpdateShouldThrowExceptionWhenTitleIsInvalid(String actionText, L
assertOkrResponseStatusException(exception, errors);
}

@DisplayName("should throw exception on validateOnUpdate() when key result is missing in model")
@Test
void validateOnUpdateShouldThrowExceptionWhenKeyResultIsMissing() {
// arrange
Expand All @@ -320,6 +331,7 @@ void validateOnUpdateShouldThrowExceptionWhenKeyResultIsMissing() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("should throw exception on validateOnUpdate() when attributes are missing")
@Test
void validateOnUpdateShouldThrowExceptionWhenAttrsAreMissing() {
// arrange
Expand All @@ -335,7 +347,7 @@ void validateOnUpdateShouldThrowExceptionWhenAttrsAreMissing() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("validateOnGetByKeyResultId() should be successful when id is not null")
@DisplayName("should be successful on validateOnGetByKeyResultId() when id is not null")
@Test
void validateOnGetByKeyResultIdShouldBeSuccessfulWhenIdIsNotNull() {
// arrange
Expand All @@ -347,7 +359,7 @@ void validateOnGetByKeyResultIdShouldBeSuccessfulWhenIdIsNotNull() {
verify(actionPersistenceService, never()).getModelName();
}

@DisplayName("validateOnGetByKeyResultId() should throw exception when id is null")
@DisplayName("should throw exception on validateOnGetByKeyResultId() when id is null")
@Test
void validateOnGetByKeyResultIdShouldThrowExceptionWhenIdIsNull() {
// arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ch.puzzle.okr.models.alignment.Alignment;
import ch.puzzle.okr.models.alignment.KeyResultAlignment;
import ch.puzzle.okr.service.persistence.AlignmentPersistenceService;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand Down Expand Up @@ -33,11 +34,13 @@ class AlignmentValidationServiceTest {
@InjectMocks
private AlignmentValidationService validator;

@DisplayName("should throw exception on validateOnCreate()")
@Test
void validateOnCreateShouldThrowException() {
assertThrows(UnsupportedOperationException.class, () -> validator.validateOnCreate(keyResultAlignment));
}

@DisplayName("should throw exception on validateOnUpdate() when id is null")
@Test
void validateOnUpdateShouldThrowExceptionWhenIdIsNull() {
when(alignmentPersistenceService.getModelName()).thenReturn("Alignment");
Expand All @@ -51,6 +54,7 @@ void validateOnUpdateShouldThrowExceptionWhenIdIsNull() {
verify(validator, times(1)).throwExceptionWhenIdIsNull(null);
}

@DisplayName("should throw exception on validateOnUpdate() when id of alignment is null")
@Test
void validateOnUpdateShouldThrowExceptionWhenIdOfAlignmentIsNull() {
when(alignmentPersistenceService.getModelName()).thenReturn("Alignment");
Expand All @@ -66,6 +70,7 @@ void validateOnUpdateShouldThrowExceptionWhenIdOfAlignmentIsNull() {

}

@DisplayName("should throw exception on validateOnUpdate() when id has changed")
@Test
void validateOnUpdateShouldThrowExceptionWhenIdHasChanged() {
Alignment alignment = KeyResultAlignment.Builder.builder().withId(3L).build();
Expand All @@ -79,6 +84,7 @@ void validateOnUpdateShouldThrowExceptionWhenIdHasChanged() {
verify(validator, times(1)).throwExceptionWhenIdHasChanged(1L, 3L);
}

@DisplayName("should throw exception on validateOnUpdate() when model is invalid")
@Test
void validateOnUpdateShouldValidateDto() {
when(alignmentPersistenceService.getModelName()).thenReturn("Alignment");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import ch.puzzle.okr.models.keyresult.KeyResultOrdinal;
import ch.puzzle.okr.service.persistence.CheckInPersistenceService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -78,12 +79,14 @@ void setUp() {
when(checkInPersistenceService.getModelName()).thenReturn("CheckIn");
}

@DisplayName("should be successful on validateOnGet() when id is valid")
@Test
void validateOnGetShouldBeSuccessfulWhenValidCheckInId() {
validator.validateOnGet(1L);
verify(validator, times(1)).throwExceptionWhenIdIsNull(1L);
}

@DisplayName("should throw exception on validateOnGet() when id is null")
@Test
void validateOnGetShouldThrowExceptionIfCheckInIdIsNull() {
// act + assert
Expand All @@ -96,6 +99,7 @@ void validateOnGetShouldThrowExceptionIfCheckInIdIsNull() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("should be successful on validateOnCreate() when check in is valid")
@Test
void validateOnCreateShouldBeSuccessfulWhenCheckInIsValid() {
when(checkInPersistenceService.findById(checkInMetric.getId())).thenReturn(checkInMetric);
Expand All @@ -107,6 +111,7 @@ void validateOnCreateShouldBeSuccessfulWhenCheckInIsValid() {
verify(validator, times(1)).validate(checkInMetric);
}

@DisplayName("should throw exception on validateOnCreate() when model is null")
@Test
void validateOnCreateShouldThrowExceptionWhenModelIsNull() {
// act + assert
Expand All @@ -117,6 +122,7 @@ void validateOnCreateShouldThrowExceptionWhenModelIsNull() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("should throw exception on validateOnCreate() when id is not null")
@Test
void validateOnCreateShouldThrowExceptionWhenIdIsNotNull() {
// act + assert
Expand All @@ -127,7 +133,7 @@ void validateOnCreateShouldThrowExceptionWhenIdIsNotNull() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@ParameterizedTest
@ParameterizedTest(name = "should throw exception on validateOnCreate() when confidence has invalid value {0}")
@MethodSource("confidenceValidationArguments")
void validateOnCreateShouldThrowExceptionWhenConfidenceIsInvalid(Integer confidence,
List<ErrorDto> expectedErrors) {
Expand All @@ -150,6 +156,7 @@ void validateOnCreateShouldThrowExceptionWhenConfidenceIsInvalid(Integer confide
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("should throw exception on validateOnCreate() when attributes are missing")
@Test
void validateOnCreateShouldThrowExceptionWhenAttrsAreMissing() {
// arrange
Expand All @@ -170,6 +177,7 @@ void validateOnCreateShouldThrowExceptionWhenAttrsAreMissing() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("should be successful on validateOnUpdate()")
@Test
void validateOnUpdateShouldBeSuccessfulWhenCheckInIsValid() {
when(checkInPersistenceService.findById(checkInOrdinal.getId())).thenReturn(checkInOrdinal);
Expand All @@ -182,6 +190,7 @@ void validateOnUpdateShouldBeSuccessfulWhenCheckInIsValid() {
verify(validator, times(1)).validate(checkInOrdinal);
}

@DisplayName("should throw exception on validateOnUpdate() when model is null")
@Test
void validateOnUpdateShouldThrowExceptionWhenModelIsNull() {
// act + assert
Expand All @@ -192,6 +201,7 @@ void validateOnUpdateShouldThrowExceptionWhenModelIsNull() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("should throw exception on validateOnUpdate() when id is null")
@Test
void validateOnUpdateShouldThrowExceptionWhenIdIsNull() {
// act + assert
Expand All @@ -205,6 +215,7 @@ void validateOnUpdateShouldThrowExceptionWhenIdIsNull() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("should throw exception on validateOnUpdate() when id has changed")
@Test
void validateOnUpdateShouldThrowExceptionWhenIdIsHasChanged() {
// act + assert
Expand All @@ -219,7 +230,7 @@ void validateOnUpdateShouldThrowExceptionWhenIdIsHasChanged() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@ParameterizedTest
@ParameterizedTest(name = "should throw exception on validateOnUpdate() when confidence has invalid value {0}")
@MethodSource("confidenceValidationArguments")
void validateOnUpdateShouldThrowExceptionWhenConfidenceIsInvalid(Integer confidence,
List<ErrorDto> expectedErrors) {
Expand All @@ -238,6 +249,7 @@ void validateOnUpdateShouldThrowExceptionWhenConfidenceIsInvalid(Integer confide
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("should throw exception on validateOnUpdate() when check ins are empty")
@Test
void validateOnUpdateShouldThrowExceptionWhenCheckInsOfKeyResultIsEmpty() {
// arrange
Expand All @@ -263,6 +275,7 @@ void validateOnUpdateShouldThrowExceptionWhenCheckInsOfKeyResultIsEmpty() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("should throw exception on validateOnUpdate() when attributes are missing")
@Test
void validateOnUpdateShouldThrowExceptionWhenAttrsAreMissing() {
// arrange
Expand All @@ -286,13 +299,15 @@ void validateOnUpdateShouldThrowExceptionWhenAttrsAreMissing() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("should be successful on validateOnDelete() when id is valid")
@Test
void validateOnDeleteShouldBeSuccessfulWhenValidKeyResultId() {
validator.validateOnDelete(1L);
verify(validator, times(1)).throwExceptionWhenIdIsNull(1L);
verify(validator, times(1)).doesEntityExist(1L);
}

@DisplayName("should throw exception on validateOnDelete() when id is null")
@Test
void validateOnDeleteShouldThrowExceptionIfKeyResultIdIsNull() {
// act + assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private static Stream<Arguments> nameValidationArguments() {
List.of(new ErrorDto("ATTRIBUTE_SIZE_BETWEEN", List.of("comment", "Completed", "0", "4096")))));
}

@DisplayName("should be successful on validateOnCreate() when model is valid")
@Test
void validateOnCreateShouldBeSuccessfulWhenCompletedIsValid() {
validator.validateOnCreate(this.validCompleted);
Expand All @@ -80,6 +81,7 @@ void validateOnCreateShouldBeSuccessfulWhenCompletedIsValid() {
verify(validator, times(1)).validate(this.validCompleted);
}

@DisplayName("should throw exception on validateOnCreate() when model is null")
@Test
void validateOnCreateShouldThrowExceptionWhenModelIsNull() {
// act + assert
Expand All @@ -90,6 +92,7 @@ void validateOnCreateShouldThrowExceptionWhenModelIsNull() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("should throw exception on validateOnCreate() when id is not null")
@Test
void validateOnCreateShouldThrowExceptionWhenIdIsNotNull() {
// arrange
Expand All @@ -107,7 +110,7 @@ void validateOnCreateShouldThrowExceptionWhenIdIsNotNull() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@ParameterizedTest
@ParameterizedTest(name = "should throw exception on validateOnCreate() when model has invalid comment {0}")
@MethodSource("nameValidationArguments")
void validateOnCreateShouldThrowExceptionWhenCommentIsInvalid(String comment, List<ErrorDto> expectedErrors) {
// arrange
Expand All @@ -123,6 +126,7 @@ void validateOnCreateShouldThrowExceptionWhenCommentIsInvalid(String comment, Li
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("should throw exception on validateOnCreate() when attributes are missing")
@Test
void validateOnCreateShouldThrowExceptionWhenAttrsAreMissing() {
// arrange
Expand All @@ -140,7 +144,7 @@ void validateOnCreateShouldThrowExceptionWhenAttrsAreMissing() {
assertOkrResponseStatusException(exception, expectedErrors);
}

@DisplayName("validateOnUpdate() should throw exception")
@DisplayName("should throw exception on validateOnUpdate()")
@Test
void validateOnUpdateShouldThrowException() {
// arrange
Expand Down
Loading

0 comments on commit 04011c5

Please sign in to comment.